diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-06-18 15:56:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-06-18 15:56:45 -0300 |
commit | f5eb809d3f1da13683cd02184042e67228206205 (patch) | |
tree | 68177f3b093bce54c4293ae68bb2d9a9fc5ea496 /lundump.c | |
parent | d71a548685eb3ac5ea598d6a9e7481389c558808 (diff) | |
download | lua-f5eb809d3f1da13683cd02184042e67228206205.tar.gz lua-f5eb809d3f1da13683cd02184042e67228206205.tar.bz2 lua-f5eb809d3f1da13683cd02184042e67228206205.zip |
Fixed missing GC barriers in compiler and undump
While building a new prototype, the GC needs barriers for every object
(strings and nested prototypes) that is attached to the new prototype.
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -85,8 +85,9 @@ static lua_Integer LoadInteger (LoadState *S) { | |||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static TString *LoadString (LoadState *S) { | 88 | static TString *LoadString (LoadState *S, Proto *p) { |
89 | size_t size = LoadByte(S); | 89 | size_t size = LoadByte(S); |
90 | TString *ts; | ||
90 | if (size == 0xFF) | 91 | if (size == 0xFF) |
91 | LoadVar(S, size); | 92 | LoadVar(S, size); |
92 | if (size == 0) | 93 | if (size == 0) |
@@ -94,13 +95,14 @@ static TString *LoadString (LoadState *S) { | |||
94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ | 95 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ |
95 | char buff[LUAI_MAXSHORTLEN]; | 96 | char buff[LUAI_MAXSHORTLEN]; |
96 | LoadVector(S, buff, size); | 97 | LoadVector(S, buff, size); |
97 | return luaS_newlstr(S->L, buff, size); | 98 | ts = luaS_newlstr(S->L, buff, size); |
98 | } | 99 | } |
99 | else { /* long string */ | 100 | else { /* long string */ |
100 | TString *ts = luaS_createlngstrobj(S->L, size); | 101 | ts = luaS_createlngstrobj(S->L, size); |
101 | LoadVector(S, getstr(ts), size); /* load directly in final place */ | 102 | LoadVector(S, getstr(ts), size); /* load directly in final place */ |
102 | return ts; | ||
103 | } | 103 | } |
104 | luaC_objbarrier(S->L, p, ts); | ||
105 | return ts; | ||
104 | } | 106 | } |
105 | 107 | ||
106 | 108 | ||
@@ -140,7 +142,7 @@ static void LoadConstants (LoadState *S, Proto *f) { | |||
140 | break; | 142 | break; |
141 | case LUA_TSHRSTR: | 143 | case LUA_TSHRSTR: |
142 | case LUA_TLNGSTR: | 144 | case LUA_TLNGSTR: |
143 | setsvalue2n(S->L, o, LoadString(S)); | 145 | setsvalue2n(S->L, o, LoadString(S, f)); |
144 | break; | 146 | break; |
145 | default: | 147 | default: |
146 | lua_assert(0); | 148 | lua_assert(0); |
@@ -158,6 +160,7 @@ static void LoadProtos (LoadState *S, Proto *f) { | |||
158 | f->p[i] = NULL; | 160 | f->p[i] = NULL; |
159 | for (i = 0; i < n; i++) { | 161 | for (i = 0; i < n; i++) { |
160 | f->p[i] = luaF_newproto(S->L); | 162 | f->p[i] = luaF_newproto(S->L); |
163 | luaC_objbarrier(S->L, f, f->p[i]); | ||
161 | LoadFunction(S, f->p[i], f->source); | 164 | LoadFunction(S, f->p[i], f->source); |
162 | } | 165 | } |
163 | } | 166 | } |
@@ -189,18 +192,18 @@ static void LoadDebug (LoadState *S, Proto *f) { | |||
189 | for (i = 0; i < n; i++) | 192 | for (i = 0; i < n; i++) |
190 | f->locvars[i].varname = NULL; | 193 | f->locvars[i].varname = NULL; |
191 | for (i = 0; i < n; i++) { | 194 | for (i = 0; i < n; i++) { |
192 | f->locvars[i].varname = LoadString(S); | 195 | f->locvars[i].varname = LoadString(S, f); |
193 | f->locvars[i].startpc = LoadInt(S); | 196 | f->locvars[i].startpc = LoadInt(S); |
194 | f->locvars[i].endpc = LoadInt(S); | 197 | f->locvars[i].endpc = LoadInt(S); |
195 | } | 198 | } |
196 | n = LoadInt(S); | 199 | n = LoadInt(S); |
197 | for (i = 0; i < n; i++) | 200 | for (i = 0; i < n; i++) |
198 | f->upvalues[i].name = LoadString(S); | 201 | f->upvalues[i].name = LoadString(S, f); |
199 | } | 202 | } |
200 | 203 | ||
201 | 204 | ||
202 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { | 205 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { |
203 | f->source = LoadString(S); | 206 | f->source = LoadString(S, f); |
204 | if (f->source == NULL) /* no source in dump? */ | 207 | if (f->source == NULL) /* no source in dump? */ |
205 | f->source = psource; /* reuse parent's source */ | 208 | f->source = psource; /* reuse parent's source */ |
206 | f->linedefined = LoadInt(S); | 209 | f->linedefined = LoadInt(S); |
@@ -271,6 +274,7 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { | |||
271 | setclLvalue(L, L->top, cl); | 274 | setclLvalue(L, L->top, cl); |
272 | luaD_inctop(L); | 275 | luaD_inctop(L); |
273 | cl->p = luaF_newproto(L); | 276 | cl->p = luaF_newproto(L); |
277 | luaC_objbarrier(L, cl, cl->p); | ||
274 | LoadFunction(&S, cl->p, NULL); | 278 | LoadFunction(&S, cl->p, NULL); |
275 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); | 279 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); |
276 | luai_verifycode(L, buff, cl->p); | 280 | luai_verifycode(L, buff, cl->p); |