MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaM_growaux_

Function luaM_growaux_

3rd/lua-5.4.3/src/lmem.c:79–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,
80 int size_elems, int limit, const char *what) {
81 void *newblock;
82 int size = *psize;
83 if (nelems + 1 <= size) /* does one extra element still fit? */
84 return block; /* nothing to be done */
85 if (size >= limit / 2) { /* cannot double it? */
86 if (l_unlikely(size >= limit)) /* cannot grow even a little? */
87 luaG_runerror(L, "too many %s (limit is %d)", what, limit);
88 size = limit; /* still have at least one free place */
89 }
90 else {
91 size *= 2;
92 if (size < MINSIZEARRAY)
93 size = MINSIZEARRAY; /* minimum size */
94 }
95 lua_assert(nelems + 1 <= size && size <= limit);
96 /* 'limit' ensures that multiplication will not overflow */
97 newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems,
98 cast_sizet(size) * size_elems);
99 *psize = size; /* update only when everything else is OK */
100 return newblock;
101}
102
103
104/*

Callers

nothing calls this directly

Calls 2

luaG_runerrorFunction · 0.85
luaM_saferealloc_Function · 0.85

Tested by

no test coverage detected