cjson_mem.c 495 B

123456789101112131415161718192021222324
  1. #include "cjson_mem.h"
  2. #include "../lua/lauxlib.h"
  3. #include <c_stdlib.h>
  4. static const char errfmt[] = "cjson %salloc: out of mem (%d bytes)";
  5. void *cjson_mem_malloc (uint32_t sz)
  6. {
  7. void *p = (void*)c_malloc (sz);
  8. lua_State *L = lua_getstate();
  9. if (!p)
  10. luaL_error (L, errfmt, "m", sz);
  11. return p;
  12. }
  13. void *cjson_mem_realloc (void *o, uint32_t sz)
  14. {
  15. void *p = (void*)c_realloc (o, sz);
  16. lua_State *L = lua_getstate();
  17. if (!p)
  18. luaL_error (L, errfmt, "re", sz);
  19. return p;
  20. }