@@ -2823,8 +2823,6 @@ static void scavenge_sl_vm_internals(lua_State *L, bool forUnpersist) {
28232823 eris_ifassert (const int top = lua_gettop (L));
28242824 int perms_idx = lua_gettop (L);
28252825
2826- auto *runtime_state = (lua_SLRuntimeState*)lua_getthreaddata (L);
2827-
28282826 const std::vector<std::pair<const char *, int >> lsl_vm_refs {
28292827 // none for now
28302828 };
@@ -3004,6 +3002,10 @@ void eris_register_perms(lua_State *L, bool for_unpersist) {
30043002
30053003static void
30063004unchecked_persist (lua_State *L, std::ostream *writer) {
3005+ // pause GC for the duration of serialization - some objects we're creating aren't rooted
3006+ // Also prevents beforeallocate callbacks from being invoked during setup
3007+ ScopedDisableGC _disable_gc (L);
3008+
30073009 eris_ifassert (int old_top=lua_gettop (L));
30083010 Info info; /* perms buff rootobj */
30093011 info.L = L;
@@ -3064,11 +3066,7 @@ unchecked_persist(lua_State *L, std::ostream *writer) {
30643066#endif
30653067
30663068 p_header (&info);
3067- {
3068- ScopedDisableGC _disable_gc (L);
3069-
3070- persist (&info); /* perms reftbl buff path? rootobj */
3071- }
3069+ persist (&info); /* perms reftbl buff path? rootobj */
30723070
30733071#if HARDSTACKTESTS
30743072 lua_pop (L, LUA_MINSTACK - pre_pad_top);
@@ -3084,6 +3082,10 @@ unchecked_persist(lua_State *L, std::ostream *writer) {
30843082
30853083static void
30863084unchecked_unpersist (lua_State *L, std::istream *reader) {/* perms str? */
3085+ // pause GC for the duration of deserialization - some objects we're creating aren't rooted
3086+ // Also prevents beforeallocate callbacks from being invoked during setup
3087+ ScopedDisableGC _disable_gc (L);
3088+
30873089 eris_ifassert (int old_top = lua_gettop (L));
30883090 Info info;
30893091 info.L = L;
@@ -3128,32 +3130,27 @@ unchecked_unpersist(lua_State *L, std::istream *reader) {/* perms str? */
31283130 eris_populate_perms (L, true );
31293131 lua_pop (L, 1 ); /* perms reftbl nil? path? str? */
31303132
3131- // pause GC for the duration of deserialization - some objects we're creating aren't rooted
3132- {
3133- ScopedDisableGC _disable_gc (L);
3134-
31353133#if HARDSTACKTESTS
3136- // Arrange the stack to make it more likely that we hit any lua_checkstack() misuse
3137- int pre_pad_top = lua_gettop (L);
3138- lua_checkstack (L, LUA_MINSTACK );
3139- while (lua_gettop (L) != LUA_MINSTACK - 1 ) {
3140- lua_pushnil (L);
3141- }
3142- // A reference to the root obj needs to end back up on top
3143- lua_pushvalue (L, pre_pad_top);
3144- eris_assert (lua_gettop (L) == LUA_MINSTACK );
3134+ // Arrange the stack to make it more likely that we hit any lua_checkstack() misuse
3135+ int pre_pad_top = lua_gettop (L);
3136+ lua_checkstack (L, LUA_MINSTACK );
3137+ while (lua_gettop (L) != LUA_MINSTACK - 1 ) {
3138+ lua_pushnil (L);
3139+ }
3140+ // A reference to the root obj needs to end back up on top
3141+ lua_pushvalue (L, pre_pad_top);
3142+ eris_assert (lua_gettop (L) == LUA_MINSTACK );
31453143#endif
31463144
3147- u_header (&info);
3148- unpersist (&info); /* perms reftbl nil? path? str? rootobj */
3145+ u_header (&info);
3146+ unpersist (&info); /* perms reftbl nil? path? str? rootobj */
31493147
31503148#if HARDSTACKTESTS
3151- // Slot the top of the stack back in where it should be
3152- lua_replace (L, pre_pad_top + 1 );
3153- lua_pop (L, LUA_MINSTACK - pre_pad_top - 1 );
3154- eris_assert (lua_gettop (L) == pre_pad_top + 1 );
3149+ // Slot the top of the stack back in where it should be
3150+ lua_replace (L, pre_pad_top + 1 );
3151+ lua_pop (L, LUA_MINSTACK - pre_pad_top - 1 );
3152+ eris_assert (lua_gettop (L) == pre_pad_top + 1 );
31553153#endif
3156- }
31573154
31583155 if (info.generatePath ) { /* perms reftbl nil path str? rootobj */
31593156 lua_remove (L, PATHIDX ); /* perms reftbl nil str? rootobj */
@@ -3514,18 +3511,10 @@ eris_fork_thread(lua_State *Lforker, uint8_t default_state, uint8_t memcat) {
35143511 // Make sure any objects we create during deserialization are created with the desired memcat
35153512 lua_setmemcat (Lforker, memcat);
35163513
3517- // We need to relax the bytes limit so that we don't fail due to garbage generated during deserialization.
3518- int old_bytes_limit = Lforker->global ->memcatbyteslimit ;
3519- lua_setmemcatbyteslimit (Lforker, 0 );
35203514 int status = eris_unpersist (Lforker, -1 , -2 ); /* Lforker: state serialized uperms new_th */
35213515
3522- // Get rid of any garbage created during deserialization if we're using memcat-based memory limits
3523- if (old_bytes_limit)
3524- lua_gc (Lforker, LUA_GCCOLLECT , 0 );
3525-
35263516 // Done, set the memcat back to the main one.
35273517 lua_setmemcat (Lforker, 0 );
3528- lua_setmemcatbyteslimit (Lforker, old_bytes_limit);
35293518
35303519 if (status == LUA_OK ) {
35313520 eris_assert (lua_isthread (Lforker, -1 ));
0 commit comments