00001
00002
00003
00004
00005
00006
00007 #ifndef lmem_h
00008 #define lmem_h
00009
00010
00011 #include <stddef.h>
00012
00013 #include "llimits.h"
00014 #include "lua.h"
00015
00016 #define MEMERRMSG "not enough memory"
00017
00018
00019 #define luaM_reallocv(L,b,on,n,e) \
00020 ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? \
00021 luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
00022 luaM_toobig(L))
00023
00024 #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
00025 #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
00026 #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
00027
00028 #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
00029 #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
00030 #define luaM_newvector(L,n,t) \
00031 cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
00032
00033 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
00034 if ((nelems)+1 > (size)) \
00035 ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
00036
00037 #define luaM_reallocvector(L, v,oldn,n,t) \
00038 ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
00039
00040
00041 LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
00042 size_t size);
00043 LUAI_FUNC void *luaM_toobig (lua_State *L);
00044 LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
00045 size_t size_elem, int limit,
00046 const char *errormsg);
00047
00048 #endif