This source file includes following definitions.
- luaM_growaux_
- luaM_toobig
- luaM_realloc_
1
2
3
4
5
6
7
8 #include <stddef.h>
9
10 #define lmem_c
11 #define LUA_CORE
12
13 #include "lua.h"
14
15 #include "ldebug.h"
16 #include "ldo.h"
17 #include "lmem.h"
18 #include "lobject.h"
19 #include "lstate.h"
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 #define MINSIZEARRAY 4
44
45
46 LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
47 int limit, const char *errormsg) {
48 void *newblock;
49 int newsize;
50 if (*size >= limit/2) {
51 if (*size >= limit)
52 luaG_runerror(L, errormsg);
53 newsize = limit;
54 }
55 else {
56 newsize = (*size)*2;
57 if (newsize < MINSIZEARRAY)
58 newsize = MINSIZEARRAY;
59 }
60 newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
61 *size = newsize;
62 return newblock;
63 }
64
65
66 LUAI_FUNC void *luaM_toobig (lua_State *L) {
67 luaG_runerror(L, "memory allocation error: block too big");
68 return NULL;
69 }
70
71
72
73
74
75
76 LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
77 global_State *g = G(L);
78 lua_assert((osize == 0) == (block == NULL));
79 block = (*g->frealloc)(g->ud, block, osize, nsize);
80 if (block == NULL && nsize > 0)
81 luaD_throw(L, LUA_ERRMEM);
82 lua_assert((nsize == 0) == (block == NULL));
83 g->totalbytes = (g->totalbytes - osize) + nsize;
84 return block;
85 }
86