| 459 | |
| 460 | |
| 461 | static void *resizebox (lua_State *L, int idx, size_t newsize) { |
| 462 | void *ud; |
| 463 | lua_Alloc allocf = lua_getallocf(L, &ud); |
| 464 | UBox *box = (UBox *)lua_touserdata(L, idx); |
| 465 | void *temp = allocf(ud, box->box, box->bsize, newsize); |
| 466 | if (temp == NULL && newsize > 0) { /* allocation error? */ |
| 467 | resizebox(L, idx, 0); /* free buffer */ |
| 468 | luaL_error(L, "not enough memory for buffer allocation"); |
| 469 | } |
| 470 | box->box = temp; |
| 471 | box->bsize = newsize; |
| 472 | return temp; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | static int boxgc (lua_State *L) { |
no test coverage detected