26
26
27
27
28
28
#if !defined(luai_verifycode )
29
- #define luai_verifycode (L ,b , f ) /* empty */
29
+ #define luai_verifycode (L ,f ) /* empty */
30
30
#endif
31
31
32
32
@@ -105,30 +105,33 @@ static lua_Integer loadInteger (LoadState *S) {
105
105
106
106
107
107
/*
108
- ** Load a nullable string.
108
+ ** Load a nullable string into prototype 'p' .
109
109
*/
110
- static TString * loadStringN (LoadState * S ) {
110
+ static TString * loadStringN (LoadState * S , Proto * p ) {
111
+ lua_State * L = S -> L ;
112
+ TString * ts ;
111
113
size_t size = loadSize (S );
112
- if (size == 0 )
114
+ if (size == 0 ) /* no string? */
113
115
return NULL ;
114
116
else if (-- size <= LUAI_MAXSHORTLEN ) { /* short string? */
115
117
char buff [LUAI_MAXSHORTLEN ];
116
- loadVector (S , buff , size );
117
- return luaS_newlstr (S -> L , buff , size );
118
+ loadVector (S , buff , size ); /* load string into buffer */
119
+ ts = luaS_newlstr (L , buff , size ); /* create string */
118
120
}
119
121
else { /* long string */
120
- TString * ts = luaS_createlngstrobj (S -> L , size );
122
+ ts = luaS_createlngstrobj (L , size ); /* create string */
121
123
loadVector (S , getstr (ts ), size ); /* load directly in final place */
122
- return ts ;
123
124
}
125
+ luaC_objbarrier (L , p , ts );
126
+ return ts ;
124
127
}
125
128
126
129
127
130
/*
128
- ** Load a non-nullable string.
131
+ ** Load a non-nullable string into prototype 'p' .
129
132
*/
130
- static TString * loadString (LoadState * S ) {
131
- TString * st = loadStringN (S );
133
+ static TString * loadString (LoadState * S , Proto * p ) {
134
+ TString * st = loadStringN (S , p );
132
135
if (st == NULL )
133
136
error (S , "bad format for constant string" );
134
137
return st ;
@@ -174,7 +177,7 @@ static void loadConstants (LoadState *S, Proto *f) {
174
177
break ;
175
178
case LUA_VSHRSTR :
176
179
case LUA_VLNGSTR :
177
- setsvalue2n (S -> L , o , loadString (S ));
180
+ setsvalue2n (S -> L , o , loadString (S , f ));
178
181
break ;
179
182
default : lua_assert (0 );
180
183
}
@@ -191,6 +194,7 @@ static void loadProtos (LoadState *S, Proto *f) {
191
194
f -> p [i ] = NULL ;
192
195
for (i = 0 ; i < n ; i ++ ) {
193
196
f -> p [i ] = luaF_newproto (S -> L );
197
+ luaC_objbarrier (S -> L , f , f -> p [i ]);
194
198
loadFunction (S , f -> p [i ], f -> source );
195
199
}
196
200
}
@@ -229,18 +233,18 @@ static void loadDebug (LoadState *S, Proto *f) {
229
233
for (i = 0 ; i < n ; i ++ )
230
234
f -> locvars [i ].varname = NULL ;
231
235
for (i = 0 ; i < n ; i ++ ) {
232
- f -> locvars [i ].varname = loadStringN (S );
236
+ f -> locvars [i ].varname = loadStringN (S , f );
233
237
f -> locvars [i ].startpc = loadInt (S );
234
238
f -> locvars [i ].endpc = loadInt (S );
235
239
}
236
240
n = loadInt (S );
237
241
for (i = 0 ; i < n ; i ++ )
238
- f -> upvalues [i ].name = loadStringN (S );
242
+ f -> upvalues [i ].name = loadStringN (S , f );
239
243
}
240
244
241
245
242
246
static void loadFunction (LoadState * S , Proto * f , TString * psource ) {
243
- f -> source = loadStringN (S );
247
+ f -> source = loadStringN (S , f );
244
248
if (f -> source == NULL ) /* no source in dump? */
245
249
f -> source = psource ; /* reuse parent's source */
246
250
f -> linedefined = loadInt (S );
@@ -310,9 +314,10 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
310
314
setclLvalue2s (L , L -> top , cl );
311
315
luaD_inctop (L );
312
316
cl -> p = luaF_newproto (L );
317
+ luaC_objbarrier (L , cl , cl -> p );
313
318
loadFunction (& S , cl -> p , NULL );
314
319
lua_assert (cl -> nupvalues == cl -> p -> sizeupvalues );
315
- luai_verifycode (L , buff , cl -> p );
320
+ luai_verifycode (L , cl -> p );
316
321
return cl ;
317
322
}
318
323
0 commit comments