diff options
| author | Mike Pall <mike> | 2017-03-08 22:03:17 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2017-03-08 22:03:17 +0100 |
| commit | 3ab9f5a18da06b06ebf1e4487997c25e32210dfe (patch) | |
| tree | 730950bc84c1d336b3b844434c1f24cf9d6eafcb | |
| parent | eef77a6d775147a1b581b06c296e9f2b3ebc9d2b (diff) | |
| download | luajit-3ab9f5a18da06b06ebf1e4487997c25e32210dfe.tar.gz luajit-3ab9f5a18da06b06ebf1e4487997c25e32210dfe.tar.bz2 luajit-3ab9f5a18da06b06ebf1e4487997c25e32210dfe.zip | |
Remove internal __mode = "K" and replace with safe check.
| -rw-r--r-- | src/lib_ffi.c | 2 | ||||
| -rw-r--r-- | src/lj_gc.c | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 6a93ce97..f2f2ede4 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -811,7 +811,7 @@ static GCtab *ffi_finalizer(lua_State *L) | |||
| 811 | settabV(L, L->top++, t); | 811 | settabV(L, L->top++, t); |
| 812 | setgcref(t->metatable, obj2gco(t)); | 812 | setgcref(t->metatable, obj2gco(t)); |
| 813 | setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), | 813 | setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), |
| 814 | lj_str_newlit(L, "K")); | 814 | lj_str_newlit(L, "k")); |
| 815 | t->nomm = (uint8_t)(~(1u<<MM_mode)); | 815 | t->nomm = (uint8_t)(~(1u<<MM_mode)); |
| 816 | return t; | 816 | return t; |
| 817 | } | 817 | } |
diff --git a/src/lj_gc.c b/src/lj_gc.c index aa243d13..a5d32ea3 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c | |||
| @@ -168,12 +168,19 @@ static int gc_traverse_tab(global_State *g, GCtab *t) | |||
| 168 | while ((c = *modestr++)) { | 168 | while ((c = *modestr++)) { |
| 169 | if (c == 'k') weak |= LJ_GC_WEAKKEY; | 169 | if (c == 'k') weak |= LJ_GC_WEAKKEY; |
| 170 | else if (c == 'v') weak |= LJ_GC_WEAKVAL; | 170 | else if (c == 'v') weak |= LJ_GC_WEAKVAL; |
| 171 | else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL); | ||
| 172 | } | 171 | } |
| 173 | if (weak > 0) { /* Weak tables are cleared in the atomic phase. */ | 172 | if (weak) { /* Weak tables are cleared in the atomic phase. */ |
| 174 | t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); | 173 | #if LJ_HASFFI |
| 175 | setgcrefr(t->gclist, g->gc.weak); | 174 | CTState *cts = ctype_ctsG(g); |
| 176 | setgcref(g->gc.weak, obj2gco(t)); | 175 | if (cts && cts->finalizer == t) { |
| 176 | weak = (int)(~0u & ~LJ_GC_WEAKVAL); | ||
| 177 | } else | ||
| 178 | #endif | ||
| 179 | { | ||
| 180 | t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); | ||
| 181 | setgcrefr(t->gclist, g->gc.weak); | ||
| 182 | setgcref(g->gc.weak, obj2gco(t)); | ||
| 183 | } | ||
| 177 | } | 184 | } |
| 178 | } | 185 | } |
| 179 | if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */ | 186 | if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */ |
