MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaM_growaux_

Function luaM_growaux_

lib/lua/src/lmem.c:97–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96
97void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,
98 int size_elems, int limit, const char *what) {
99 void *newblock;
100 int size = *psize;
101 if (nelems + 1 <= size) /* does one extra element still fit? */
102 return block; /* nothing to be done */
103 if (size >= limit / 2) { /* cannot double it? */
104 if (l_unlikely(size >= limit)) /* cannot grow even a little? */
105 luaG_runerror(L, "too many %s (limit is %d)", what, limit);
106 size = limit; /* still have at least one free place */
107 }
108 else {
109 size *= 2;
110 if (size < MINSIZEARRAY)
111 size = MINSIZEARRAY; /* minimum size */
112 }
113 lua_assert(nelems + 1 <= size && size <= limit);
114 /* 'limit' ensures that multiplication will not overflow */
115 newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems,
116 cast_sizet(size) * size_elems);
117 *psize = size; /* update only when everything else is OK */
118 return newblock;
119}
120
121
122/*

Callers

nothing calls this directly

Calls 2

luaG_runerrorFunction · 0.85
luaM_saferealloc_Function · 0.85

Tested by

no test coverage detected