diff options
| author | Mike Pall <mike> | 2021-06-01 01:01:15 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2021-06-01 01:01:15 +0200 |
| commit | 50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9 (patch) | |
| tree | 651d9197f277d8c13142e503a066688bfa3c2045 /src | |
| parent | 61990cef05a4ee4abb7cd130c7e46160cd914d95 (diff) | |
| download | luajit-50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9.tar.gz luajit-50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9.tar.bz2 luajit-50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9.zip | |
Abstract out on-demand loading of FFI library.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_jit.c | 6 | ||||
| -rw-r--r-- | src/lj_bcread.c | 6 | ||||
| -rw-r--r-- | src/lj_ctype.h | 10 | ||||
| -rw-r--r-- | src/lj_lex.c | 6 |
4 files changed, 13 insertions, 15 deletions
diff --git a/src/lib_jit.c b/src/lib_jit.c index 12f51d75..817c2967 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c | |||
| @@ -346,11 +346,7 @@ LJLIB_CF(jit_util_tracek) | |||
| 346 | ir = &T->ir[ir->op1]; | 346 | ir = &T->ir[ir->op1]; |
| 347 | } | 347 | } |
| 348 | #if LJ_HASFFI | 348 | #if LJ_HASFFI |
| 349 | if (ir->o == IR_KINT64 && !ctype_ctsG(G(L))) { | 349 | if (ir->o == IR_KINT64) ctype_loadffi(L); |
| 350 | ptrdiff_t oldtop = savestack(L, L->top); | ||
| 351 | luaopen_ffi(L); /* Load FFI library on-demand. */ | ||
| 352 | L->top = restorestack(L, oldtop); | ||
| 353 | } | ||
| 354 | #endif | 350 | #endif |
| 355 | lj_ir_kvalue(L, L->top-2, ir); | 351 | lj_ir_kvalue(L, L->top-2, ir); |
| 356 | setintV(L->top-1, (int32_t)irt_type(ir->t)); | 352 | setintV(L->top-1, (int32_t)irt_type(ir->t)); |
diff --git a/src/lj_bcread.c b/src/lj_bcread.c index 28795e3c..298e6c45 100644 --- a/src/lj_bcread.c +++ b/src/lj_bcread.c | |||
| @@ -399,11 +399,7 @@ static int bcread_header(LexState *ls) | |||
| 399 | if ((flags & BCDUMP_F_FFI)) { | 399 | if ((flags & BCDUMP_F_FFI)) { |
| 400 | #if LJ_HASFFI | 400 | #if LJ_HASFFI |
| 401 | lua_State *L = ls->L; | 401 | lua_State *L = ls->L; |
| 402 | if (!ctype_ctsG(G(L))) { | 402 | ctype_loadffi(L); |
| 403 | ptrdiff_t oldtop = savestack(L, L->top); | ||
| 404 | luaopen_ffi(L); /* Load FFI library on-demand. */ | ||
| 405 | L->top = restorestack(L, oldtop); | ||
| 406 | } | ||
| 407 | #else | 403 | #else |
| 408 | return 0; | 404 | return 0; |
| 409 | #endif | 405 | #endif |
diff --git a/src/lj_ctype.h b/src/lj_ctype.h index 49ec71da..9589ef2a 100644 --- a/src/lj_ctype.h +++ b/src/lj_ctype.h | |||
| @@ -389,6 +389,16 @@ static LJ_AINLINE CTState *ctype_cts(lua_State *L) | |||
| 389 | return cts; | 389 | return cts; |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | /* Load FFI library on-demand. */ | ||
| 393 | #define ctype_loadffi(L) \ | ||
| 394 | do { \ | ||
| 395 | if (!ctype_ctsG(G(L))) { \ | ||
| 396 | ptrdiff_t oldtop = (char *)L->top - mref(L->stack, char); \ | ||
| 397 | luaopen_ffi(L); \ | ||
| 398 | L->top = (TValue *)(mref(L->stack, char) + oldtop); \ | ||
| 399 | } \ | ||
| 400 | } while (0) | ||
| 401 | |||
| 392 | /* Save and restore state of C type table. */ | 402 | /* Save and restore state of C type table. */ |
| 393 | #define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts) | 403 | #define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts) |
| 394 | #define LJ_CTYPE_RESTORE(cts) \ | 404 | #define LJ_CTYPE_RESTORE(cts) \ |
diff --git a/src/lj_lex.c b/src/lj_lex.c index f954b428..cc6fa533 100644 --- a/src/lj_lex.c +++ b/src/lj_lex.c | |||
| @@ -118,11 +118,7 @@ static void lex_number(LexState *ls, TValue *tv) | |||
| 118 | GCcdata *cd; | 118 | GCcdata *cd; |
| 119 | lj_assertLS(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG, | 119 | lj_assertLS(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG, |
| 120 | "unexpected number format %d", fmt); | 120 | "unexpected number format %d", fmt); |
| 121 | if (!ctype_ctsG(G(L))) { | 121 | ctype_loadffi(L); |
| 122 | ptrdiff_t oldtop = savestack(L, L->top); | ||
| 123 | luaopen_ffi(L); /* Load FFI library on-demand. */ | ||
| 124 | L->top = restorestack(L, oldtop); | ||
| 125 | } | ||
| 126 | if (fmt == STRSCAN_IMAG) { | 122 | if (fmt == STRSCAN_IMAG) { |
| 127 | cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); | 123 | cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); |
| 128 | ((double *)cdataptr(cd))[0] = 0; | 124 | ((double *)cdataptr(cd))[0] = 0; |
