rlm@1: /* rlm@1: ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ rlm@1: ** Interface to Memory Manager rlm@1: ** See Copyright Notice in lua.h rlm@1: */ rlm@1: rlm@1: #ifndef lmem_h rlm@1: #define lmem_h rlm@1: rlm@1: rlm@1: #include rlm@1: rlm@1: #include "llimits.h" rlm@1: #include "lua.h" rlm@1: rlm@1: #define MEMERRMSG "not enough memory" rlm@1: rlm@1: rlm@1: #define luaM_reallocv(L,b,on,n,e) \ rlm@1: ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ rlm@1: luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ rlm@1: luaM_toobig(L)) rlm@1: rlm@1: #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) rlm@1: #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) rlm@1: #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) rlm@1: rlm@1: #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) rlm@1: #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) rlm@1: #define luaM_newvector(L,n,t) \ rlm@1: cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) rlm@1: rlm@1: #define luaM_growvector(L,v,nelems,size,t,limit,e) \ rlm@1: if ((nelems)+1 > (size)) \ rlm@1: ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) rlm@1: rlm@1: #define luaM_reallocvector(L, v,oldn,n,t) \ rlm@1: ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) rlm@1: rlm@1: rlm@1: LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, rlm@1: size_t size); rlm@1: LUAI_FUNC void *luaM_toobig (lua_State *L); rlm@1: LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, rlm@1: size_t size_elem, int limit, rlm@1: const char *errormsg); rlm@1: rlm@1: #endif rlm@1: