Added suport for Fixed Buffers

A fixed buffer keeps a binary chunk "forever", so that the program
does not need to copy some of its parts when loading it.
This commit is contained in:
Roberto Ierusalimschy
2023-09-05 15:30:45 -03:00
parent f33cda8d6e
commit 14e416355f
12 changed files with 160 additions and 34 deletions

13
ldo.c
View File

@@ -977,7 +977,7 @@ struct SParser { /* data to 'f_parser' */
static void checkmode (lua_State *L, const char *mode, const char *x) {
if (mode && strchr(mode, x[0]) == NULL) {
if (strchr(mode, x[0]) == NULL) {
luaO_pushfstring(L,
"attempt to load a %s chunk (mode is '%s')", x, mode);
luaD_throw(L, LUA_ERRSYNTAX);
@@ -988,13 +988,18 @@ static void checkmode (lua_State *L, const char *mode, const char *x) {
static void f_parser (lua_State *L, void *ud) {
LClosure *cl;
struct SParser *p = cast(struct SParser *, ud);
const char *mode = p->mode ? p->mode : "bt";
int c = zgetc(p->z); /* read first character */
if (c == LUA_SIGNATURE[0]) {
checkmode(L, p->mode, "binary");
cl = luaU_undump(L, p->z, p->name);
int fixed = 0;
if (strchr(mode, 'B') != NULL)
fixed = 1;
else
checkmode(L, mode, "binary");
cl = luaU_undump(L, p->z, p->name, fixed);
}
else {
checkmode(L, p->mode, "text");
checkmode(L, mode, "text");
cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
}
lua_assert(cl->nupvalues == cl->p->sizeupvalues);