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

Function prepbuffsize

3rd/lua-5.4.3/src/lauxlib.c:546–569  ·  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

544** buffer's box or its placeholder.
545*/
546static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) {
547 checkbufferlevel(B, boxidx);
548 if (B->size - B->n >= sz) /* enough space? */
549 return B->b + B->n;
550 else {
551 lua_State *L = B->L;
552 char *newbuff;
553 size_t newsize = newbuffsize(B, sz);
554 /* create larger buffer */
555 if (buffonstack(B)) /* buffer already has a box? */
556 newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */
557 else { /* no box yet */
558 lua_remove(L, boxidx); /* remove placeholder */
559 newbox(L); /* create a new box */
560 lua_insert(L, boxidx); /* move box to its intended position */
561 lua_toclose(L, boxidx);
562 newbuff = (char *)resizebox(L, boxidx, newsize);
563 memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
564 }
565 B->b = newbuff;
566 B->size = newsize;
567 return newbuff + B->n;
568 }
569}
570
571/*
572** returns a pointer to a free area with at least 'sz' bytes

Callers 4

luaL_prepbuffsizeFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_addvalueFunction · 0.85
luaL_buffinitsizeFunction · 0.85

Calls 4

newbuffsizeFunction · 0.85
resizeboxFunction · 0.85
newboxFunction · 0.85
lua_tocloseFunction · 0.85

Tested by

no test coverage detected