diff options
Diffstat (limited to 'lmem.h')
-rw-r--r-- | lmem.h | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.h,v 1.25 2001/11/28 20:13:13 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.26 2002/05/01 20:40:42 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -16,28 +16,34 @@ | |||
16 | #define MEMERRMSG "not enough memory" | 16 | #define MEMERRMSG "not enough memory" |
17 | 17 | ||
18 | 18 | ||
19 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); | 19 | void *luaM_realloc (lua_State *L, void *block, size_t oldsize, size_t size); |
20 | 20 | ||
21 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | 21 | void *luaM_toobig (lua_State *L); |
22 | |||
23 | #define luaM_reallocv(L,b,on,n,e) \ | ||
24 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 only to avoid warnings */ \ | ||
25 | luaM_realloc(L, (b), (on)*(e), (n)*(e)) : \ | ||
26 | luaM_toobig(L)) | ||
27 | |||
28 | |||
29 | void *luaM_growaux (lua_State *L, void *block, int *size, size_t size_elem, | ||
22 | int limit, const char *errormsg); | 30 | int limit, const char *errormsg); |
23 | 31 | ||
24 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) | 32 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) |
25 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) | 33 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) |
26 | #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ | 34 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) |
27 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0) | ||
28 | 35 | ||
29 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) | 36 | #define luaM_malloc(L,t) luaM_realloc(L, NULL, 0, (t)) |
30 | #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) | 37 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) |
31 | #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ | 38 | #define luaM_newvector(L,n,t) \ |
32 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)))) | 39 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) |
33 | 40 | ||
34 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ | 41 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ |
35 | if (((nelems)+1) > (size)) \ | 42 | if (((nelems)+1) > (size)) \ |
36 | ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) | 43 | ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) |
37 | 44 | ||
38 | #define luaM_reallocvector(L, v,oldn,n,t) \ | 45 | #define luaM_reallocvector(L, v,oldn,n,t) \ |
39 | ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ | 46 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) |
40 | cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) | ||
41 | 47 | ||
42 | 48 | ||
43 | #endif | 49 | #endif |