|
1 | 1 | /* |
2 | | -** $Id: lmem.h,v 1.44 2017/12/06 18:36:31 roberto Exp roberto $ |
| 2 | +** $Id: lmem.h,v 1.45 2017/12/07 18:59:52 roberto Exp roberto $ |
3 | 3 | ** Interface to Memory Manager |
4 | 4 | ** See Copyright Notice in lua.h |
5 | 5 | */ |
|
14 | 14 | #include "lua.h" |
15 | 15 |
|
16 | 16 |
|
| 17 | +#define luaM_error(L) luaD_throw(L, LUA_ERRMEM) |
| 18 | + |
| 19 | + |
17 | 20 | /* |
18 | 21 | ** This macro tests whether it is safe to multiply 'n' by the size of |
19 | 22 | ** type 't' without overflows. Because 'e' is always constant, it avoids |
|
45 | 48 | ** Arrays of chars do not need any test |
46 | 49 | */ |
47 | 50 | #define luaM_reallocvchar(L,b,on,n) \ |
48 | | - cast(char *, luaM_realloc(L, (b), (on)*sizeof(char), (n)*sizeof(char))) |
| 51 | + cast(char *, luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) |
49 | 52 |
|
50 | 53 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) |
51 | 54 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) |
52 | 55 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b))) |
53 | 56 |
|
54 | | -#define luaM_new(L,t) cast(t*, luaM_malloc(L, sizeof(t), 0)) |
55 | | -#define luaM_newvector(L,n,t) cast(t*, luaM_malloc(L, (n)*sizeof(t), 0)) |
| 57 | +#define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0)) |
| 58 | +#define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0)) |
56 | 59 | #define luaM_newvectorchecked(L,n,t) \ |
57 | 60 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t)) |
58 | 61 |
|
59 | | -#define luaM_newobject(L,tag,s) luaM_malloc(L, (s), tag) |
| 62 | +#define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag) |
60 | 63 |
|
61 | 64 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ |
62 | 65 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \ |
63 | 66 | luaM_limitN(limit,t),e))) |
64 | 67 |
|
65 | 68 | #define luaM_reallocvector(L, v,oldn,n,t) \ |
66 | | - ((v)=cast(t *, luaM_realloc(L, v, cast(size_t, oldn) * sizeof(t), \ |
67 | | - cast(size_t, n) * sizeof(t)))) |
| 69 | + (cast(t *, luaM_realloc_(L, v, cast(size_t, oldn) * sizeof(t), \ |
| 70 | + cast(size_t, n) * sizeof(t)))) |
68 | 71 |
|
69 | 72 | #define luaM_shrinkvector(L,v,size,fs,t) \ |
70 | 73 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) |
71 | 74 |
|
72 | 75 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); |
73 | 76 |
|
74 | 77 | /* not to be called directly */ |
75 | | -LUAI_FUNC void *luaM_realloc (lua_State *L, void *block, size_t oldsize, |
| 78 | +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, |
76 | 79 | size_t size); |
| 80 | +LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, |
| 81 | + size_t size); |
77 | 82 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); |
78 | 83 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, |
79 | 84 | int *size, int size_elem, int limit, |
80 | 85 | const char *what); |
81 | 86 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, |
82 | 87 | int final_n, int size_elem); |
83 | | -LUAI_FUNC void *luaM_malloc (lua_State *L, size_t size, int tag); |
| 88 | +LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag); |
84 | 89 |
|
85 | 90 | #endif |
86 | 91 |
|
0 commit comments