2626
2727
2828#if !defined(luai_verifycode )
29- #define luai_verifycode (L ,b , f ) /* empty */
29+ #define luai_verifycode (L ,f ) /* empty */
3030#endif
3131
3232
@@ -105,30 +105,33 @@ static lua_Integer loadInteger (LoadState *S) {
105105
106106
107107/*
108- ** Load a nullable string.
108+ ** Load a nullable string into prototype 'p' .
109109*/
110- static TString * loadStringN (LoadState * S ) {
110+ static TString * loadStringN (LoadState * S , Proto * p ) {
111+ lua_State * L = S -> L ;
112+ TString * ts ;
111113 size_t size = loadSize (S );
112- if (size == 0 )
114+ if (size == 0 ) /* no string? */
113115 return NULL ;
114116 else if (-- size <= LUAI_MAXSHORTLEN ) { /* short string? */
115117 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 */
118120 }
119121 else { /* long string */
120- TString * ts = luaS_createlngstrobj (S -> L , size );
122+ ts = luaS_createlngstrobj (L , size ); /* create string */
121123 loadVector (S , getstr (ts ), size ); /* load directly in final place */
122- return ts ;
123124 }
125+ luaC_objbarrier (L , p , ts );
126+ return ts ;
124127}
125128
126129
127130/*
128- ** Load a non-nullable string.
131+ ** Load a non-nullable string into prototype 'p' .
129132*/
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 );
132135 if (st == NULL )
133136 error (S , "bad format for constant string" );
134137 return st ;
@@ -174,7 +177,7 @@ static void loadConstants (LoadState *S, Proto *f) {
174177 break ;
175178 case LUA_VSHRSTR :
176179 case LUA_VLNGSTR :
177- setsvalue2n (S -> L , o , loadString (S ));
180+ setsvalue2n (S -> L , o , loadString (S , f ));
178181 break ;
179182 default : lua_assert (0 );
180183 }
@@ -191,6 +194,7 @@ static void loadProtos (LoadState *S, Proto *f) {
191194 f -> p [i ] = NULL ;
192195 for (i = 0 ; i < n ; i ++ ) {
193196 f -> p [i ] = luaF_newproto (S -> L );
197+ luaC_objbarrier (S -> L , f , f -> p [i ]);
194198 loadFunction (S , f -> p [i ], f -> source );
195199 }
196200}
@@ -229,18 +233,18 @@ static void loadDebug (LoadState *S, Proto *f) {
229233 for (i = 0 ; i < n ; i ++ )
230234 f -> locvars [i ].varname = NULL ;
231235 for (i = 0 ; i < n ; i ++ ) {
232- f -> locvars [i ].varname = loadStringN (S );
236+ f -> locvars [i ].varname = loadStringN (S , f );
233237 f -> locvars [i ].startpc = loadInt (S );
234238 f -> locvars [i ].endpc = loadInt (S );
235239 }
236240 n = loadInt (S );
237241 for (i = 0 ; i < n ; i ++ )
238- f -> upvalues [i ].name = loadStringN (S );
242+ f -> upvalues [i ].name = loadStringN (S , f );
239243}
240244
241245
242246static void loadFunction (LoadState * S , Proto * f , TString * psource ) {
243- f -> source = loadStringN (S );
247+ f -> source = loadStringN (S , f );
244248 if (f -> source == NULL ) /* no source in dump? */
245249 f -> source = psource ; /* reuse parent's source */
246250 f -> linedefined = loadInt (S );
@@ -310,9 +314,10 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
310314 setclLvalue2s (L , L -> top , cl );
311315 luaD_inctop (L );
312316 cl -> p = luaF_newproto (L );
317+ luaC_objbarrier (L , cl , cl -> p );
313318 loadFunction (& S , cl -> p , NULL );
314319 lua_assert (cl -> nupvalues == cl -> p -> sizeupvalues );
315- luai_verifycode (L , buff , cl -> p );
320+ luai_verifycode (L , cl -> p );
316321 return cl ;
317322}
318323
0 commit comments