MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaM_realloc_

Function luaM_realloc_

freebsd/contrib/openzfs/module/lua/lmem.c:74–97  ·  view source on GitHub ↗

** generic allocation routine. */

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

luaC_fullgcFunction · 0.70
luaD_throwFunction · 0.70

Tested by

no test coverage detected