MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / prepbuffsize

Function prepbuffsize

third-party/lua-5.5.0/src/lauxlib.c:564–587  ·  view source on GitHub ↗

** Returns a pointer to a free area with at least 'sz' bytes in buffer ** 'B'. 'boxidx' is the relative position in the stack where is the ** buffer's box or its placeholder. */

Source from the content-addressed store, hash-verified

562** buffer's box or its placeholder.
563*/
564static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) {
565 checkbufferlevel(B, boxidx);
566 if (B->size - B->n >= sz) /* enough space? */
567 return B->b + B->n;
568 else {
569 lua_State *L = B->L;
570 char *newbuff;
571 size_t newsize = newbuffsize(B, sz);
572 /* create larger buffer */
573 if (buffonstack(B)) /* buffer already has a box? */
574 newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */
575 else { /* no box yet */
576 lua_remove(L, boxidx); /* remove placeholder */
577 newbox(L); /* create a new box */
578 lua_insert(L, boxidx); /* move box to its intended position */
579 lua_toclose(L, boxidx);
580 newbuff = (char *)resizebox(L, boxidx, newsize);
581 memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
582 }
583 B->b = newbuff;
584 B->size = newsize;
585 return newbuff + B->n;
586 }
587}
588
589/*
590** returns a pointer to a free area with at least 'sz' bytes

Callers 4

luaL_prepbuffsizeFunction · 0.70
luaL_addlstringFunction · 0.70
luaL_addvalueFunction · 0.70
luaL_buffinitsizeFunction · 0.70

Calls 6

newbuffsizeFunction · 0.70
resizeboxFunction · 0.70
newboxFunction · 0.70
lua_tocloseFunction · 0.70
lua_removeFunction · 0.50
lua_insertFunction · 0.50

Tested by

no test coverage detected