aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-09-05 15:30:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-09-05 15:30:45 -0300
commit14e416355f83cf0a1b871eedec2c92b86dbe76d6 (patch)
tree620c7fa0b811d5f91d3d2f9b4879b289df6d137c /ldo.c
parentf33cda8d6eb1cac5b9042429e85f1096175c7ca5 (diff)
downloadlua-14e416355f83cf0a1b871eedec2c92b86dbe76d6.tar.gz
lua-14e416355f83cf0a1b871eedec2c92b86dbe76d6.tar.bz2
lua-14e416355f83cf0a1b871eedec2c92b86dbe76d6.zip
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.
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/ldo.c b/ldo.c
index a0e00229..e9f91384 100644
--- a/ldo.c
+++ b/ldo.c
@@ -977,7 +977,7 @@ struct SParser { /* data to 'f_parser' */
977 977
978 978
979static void checkmode (lua_State *L, const char *mode, const char *x) { 979static void checkmode (lua_State *L, const char *mode, const char *x) {
980 if (mode && strchr(mode, x[0]) == NULL) { 980 if (strchr(mode, x[0]) == NULL) {
981 luaO_pushfstring(L, 981 luaO_pushfstring(L,
982 "attempt to load a %s chunk (mode is '%s')", x, mode); 982 "attempt to load a %s chunk (mode is '%s')", x, mode);
983 luaD_throw(L, LUA_ERRSYNTAX); 983 luaD_throw(L, LUA_ERRSYNTAX);
@@ -988,13 +988,18 @@ static void checkmode (lua_State *L, const char *mode, const char *x) {
988static void f_parser (lua_State *L, void *ud) { 988static void f_parser (lua_State *L, void *ud) {
989 LClosure *cl; 989 LClosure *cl;
990 struct SParser *p = cast(struct SParser *, ud); 990 struct SParser *p = cast(struct SParser *, ud);
991 const char *mode = p->mode ? p->mode : "bt";
991 int c = zgetc(p->z); /* read first character */ 992 int c = zgetc(p->z); /* read first character */
992 if (c == LUA_SIGNATURE[0]) { 993 if (c == LUA_SIGNATURE[0]) {
993 checkmode(L, p->mode, "binary"); 994 int fixed = 0;
994 cl = luaU_undump(L, p->z, p->name); 995 if (strchr(mode, 'B') != NULL)
996 fixed = 1;
997 else
998 checkmode(L, mode, "binary");
999 cl = luaU_undump(L, p->z, p->name, fixed);
995 } 1000 }
996 else { 1001 else {
997 checkmode(L, p->mode, "text"); 1002 checkmode(L, mode, "text");
998 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); 1003 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
999 } 1004 }
1000 lua_assert(cl->nupvalues == cl->p->sizeupvalues); 1005 lua_assert(cl->nupvalues == cl->p->sizeupvalues);