rpm  4.5
lmem.h
Go to the documentation of this file.
1 /*
2 ** $Id: lmem.h,v 1.1 2004/03/16 21:58:30 niemeyer Exp $
3 ** Interface to Memory Manager
4 ** See Copyright Notice in lua.h
5 */
6 
7 #ifndef lmem_h
8 #define lmem_h
9 
10 
11 #include <stddef.h>
12 
13 #include "llimits.h"
14 #include "lua.h"
15 
16 #define MEMERRMSG "not enough memory"
17 
18 
19 /*@null@*/
20 void *luaM_realloc (/*@null@*/ lua_State *L, /*@null@*/ void *oldblock, lu_mem oldsize, lu_mem size)
21  /*@modifies L, oldblock @*/;
22 
23 /*@null@*/
24 void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
25  int limit, const char *errormsg)
26  /*@modifies L, block, *size @*/;
27 
28 #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
29 #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0)
30 #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
31  cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
32 
33 #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
34 #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
35 #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
36  cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
37 
38 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
39  if (((nelems)+1) > (size)) \
40  ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
41 
42 #define luaM_reallocvector(L, v,oldn,n,t) \
43  ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
44  cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
45 
46 
47 #endif
48