Resize the buffer used by a box. Optimize for the common case of ** resizing to the old size. (For instance, __gc will resize the box ** to 0 even after it was closed. 'pushresult' may also resize it to a ** final size that is equal to the one set when the buffer was created.) */
| 482 | ** final size that is equal to the one set when the buffer was created.) |
| 483 | */ |
| 484 | static void *resizebox (lua_State *L, int idx, size_t newsize) { |
| 485 | UBox *box = (UBox *)lua_touserdata(L, idx); |
| 486 | if (box->bsize == newsize) /* not changing size? */ |
| 487 | return box->box; /* keep the buffer */ |
| 488 | else { |
| 489 | void *ud; |
| 490 | lua_Alloc allocf = lua_getallocf(L, &ud); |
| 491 | void *temp = allocf(ud, box->box, box->bsize, newsize); |
| 492 | if (l_unlikely(temp == NULL && newsize > 0)) { /* allocation error? */ |
| 493 | lua_pushliteral(L, "not enough memory"); |
| 494 | lua_error(L); /* raise a memory error */ |
| 495 | } |
| 496 | box->box = temp; |
| 497 | box->bsize = newsize; |
| 498 | return temp; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | |
| 503 | static int boxgc (lua_State *L) { |
no test coverage detected