2015-07-20 10:02:16 +02:00
|
|
|
#include "cjson_mem.h"
|
|
|
|
#include "../lua/lauxlib.h"
|
|
|
|
#include <c_stdlib.h>
|
|
|
|
|
|
|
|
static const char errfmt[] = "cjson %salloc: out of mem (%d bytes)";
|
|
|
|
|
|
|
|
void *cjson_mem_malloc (uint32_t sz)
|
|
|
|
{
|
|
|
|
void *p = (void*)c_malloc (sz);
|
2016-08-02 22:33:05 +02:00
|
|
|
lua_State *L = lua_getstate();
|
|
|
|
if (!p)
|
|
|
|
luaL_error (L, errfmt, "m", sz);
|
2015-07-20 10:02:16 +02:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *cjson_mem_realloc (void *o, uint32_t sz)
|
|
|
|
{
|
|
|
|
void *p = (void*)c_realloc (o, sz);
|
2016-08-02 22:33:05 +02:00
|
|
|
lua_State *L = lua_getstate();
|
|
|
|
if (!p)
|
|
|
|
luaL_error (L, errfmt, "re", sz);
|
2015-07-20 10:02:16 +02:00
|
|
|
return p;
|
|
|
|
}
|