MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaM_realloc_

Function luaM_realloc_

depends/lua/src/lmem.c:77–99  ·  view source on GitHub ↗

** generic allocation routine. */

Source from the content-addressed store, hash-verified

75** generic allocation routine.
76*/
77void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
78 void *newblock;
79 global_State *g = G(L);
80 size_t realosize = (block) ? osize : 0;
81 lua_assert((realosize == 0) == (block == NULL));
82#if defined(HARDMEMTESTS)
83 if (nsize > realosize && g->gcrunning)
84 luaC_fullgc(L, 1); /* force a GC whenever possible */
85#endif
86 newblock = (*g->frealloc)(g->ud, block, osize, nsize);
87 if (newblock == NULL && nsize > 0) {
88 lua_assert(nsize > realosize); /* cannot fail when shrinking a block */
89 if (g->version) { /* is state fully built? */
90 luaC_fullgc(L, 1); /* try to free some memory... */
91 newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
92 }
93 if (newblock == NULL)
94 luaD_throw(L, LUA_ERRMEM);
95 }
96 lua_assert((nsize == 0) == (newblock == NULL));
97 g->GCdebt = (g->GCdebt + nsize) - realosize;
98 return newblock;
99}
100

Callers

nothing calls this directly

Calls 2

luaC_fullgcFunction · 0.85
luaD_throwFunction · 0.85

Tested by

no test coverage detected