FFI: Don't keep CType * across call. Callback may reallocate table.

This commit is contained in:
Mike Pall 2012-08-12 01:16:49 +02:00
parent ece23a4788
commit 1a3e5e1521

View File

@ -810,6 +810,7 @@ int lj_ccall_func(lua_State *L, GCcdata *cd)
int gcsteps, ret; int gcsteps, ret;
cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz); cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz);
gcsteps = ccall_set_args(L, cts, ct, &cc); gcsteps = ccall_set_args(L, cts, ct, &cc);
ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab);
cts->cb.slot = ~0u; cts->cb.slot = ~0u;
lj_vm_ffi_call(&cc); lj_vm_ffi_call(&cc);
if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */ if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */
@ -817,6 +818,7 @@ int lj_ccall_func(lua_State *L, GCcdata *cd)
setlightudV(&tv, (void *)cc.func); setlightudV(&tv, (void *)cc.func);
setboolV(lj_tab_set(L, cts->miscmap, &tv), 1); setboolV(lj_tab_set(L, cts->miscmap, &tv), 1);
} }
ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab); /* May be reallocated. */
gcsteps += ccall_get_results(L, cts, ct, &cc, &ret); gcsteps += ccall_get_results(L, cts, ct, &cc, &ret);
#if LJ_TARGET_X86 && LJ_ABI_WIN #if LJ_TARGET_X86 && LJ_ABI_WIN
/* Automatically detect __stdcall and fix up C function declaration. */ /* Automatically detect __stdcall and fix up C function declaration. */