The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lmem.h
Go to the documentation of this file.
1 /*
2 ** Interface to Memory Manager
3 ** See Copyright Notice in lua.h
4 */
5 
6 #ifndef lmem_h
7 #define lmem_h
8 
9 
10 #include <stddef.h>
11 
12 #include "llimits.h"
13 #include "lua.h"
14 
15 
16 /*
17 ** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is
18 ** always constant.
19 ** The macro is somewhat complex to avoid warnings:
20 ** +1 avoids warnings of "comparison has constant result";
21 ** cast to 'void' avoids warnings of "value unused".
22 */
23 #define luaM_reallocv(L,b,on,n,e) \
24  (cast(void, \
25  (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
26  luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
27 
28 #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
29 #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
30 #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
31 
32 #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s))
33 #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
34 #define luaM_newvector(L,n,t) \
35  cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
36 
37 #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
38 
39 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
40  if ((nelems)+1 > (size)) \
41  ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
42 
43 #define luaM_reallocvector(L, v,oldn,n,t) \
44  ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
45 
47 
48 /* not to be called directly */
49 LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
50  size_t size);
51 LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
52  size_t size_elem, int limit,
53  const char *what);
54 
55 #endif
56 
#define LUAI_FUNC
Definition: luaconf.h:187
#define l_noret
Definition: llimits.h:108
const char * what() const
GLint limit
Definition: glew.h:10112
LUAI_FUNC void * luaM_realloc_(lua_State *L, void *block, size_t oldsize, size_t size)
Definition: lmem.cpp:74
static void block(LexState *ls)
Definition: lparser.cpp:1081
GLsizeiptr size
Definition: glew.h:1649
LUAI_FUNC void * luaM_growaux_(lua_State *L, void *block, int *size, size_t size_elem, int limit, const char *what)
Definition: lmem.cpp:45
LUAI_FUNC l_noret luaM_toobig(lua_State *L)
Definition: lmem.cpp:65