]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Remove internal __mode = "K" and replace with safe check.
authorMike Pall <mike>
Wed, 8 Mar 2017 21:03:17 +0000 (22:03 +0100)
committerMike Pall <mike>
Wed, 8 Mar 2017 21:03:17 +0000 (22:03 +0100)
src/lib_ffi.c
src/lj_gc.c

index 6a93ce9713c2a532cf6a846734b7f9fdddea47fb..f2f2ede45bebe0db11227b2828339a31599287d1 100644 (file)
@@ -811,7 +811,7 @@ static GCtab *ffi_finalizer(lua_State *L)
   settabV(L, L->top++, t);
   setgcref(t->metatable, obj2gco(t));
   setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
-         lj_str_newlit(L, "K"));
+         lj_str_newlit(L, "k"));
   t->nomm = (uint8_t)(~(1u<<MM_mode));
   return t;
 }
index aa243d13ed0a9cd12f1fe0cae4f078b8ffc04e37..a5d32ea359d1ebd85c0327e918c84922d4abd912 100644 (file)
@@ -168,12 +168,19 @@ static int gc_traverse_tab(global_State *g, GCtab *t)
     while ((c = *modestr++)) {
       if (c == 'k') weak |= LJ_GC_WEAKKEY;
       else if (c == 'v') weak |= LJ_GC_WEAKVAL;
-      else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL);
     }
-    if (weak > 0) {  /* Weak tables are cleared in the atomic phase. */
-      t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
-      setgcrefr(t->gclist, g->gc.weak);
-      setgcref(g->gc.weak, obj2gco(t));
+    if (weak) {  /* Weak tables are cleared in the atomic phase. */
+#if LJ_HASFFI
+      CTState *cts = ctype_ctsG(g);
+      if (cts && cts->finalizer == t) {
+       weak = (int)(~0u & ~LJ_GC_WEAKVAL);
+      } else
+#endif
+      {
+       t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
+       setgcrefr(t->gclist, g->gc.weak);
+       setgcref(g->gc.weak, obj2gco(t));
+      }
     }
   }
   if (weak == LJ_GC_WEAK)  /* Nothing to mark if both keys/values are weak. */