diff options
| author | Mike Pall <mike> | 2013-01-15 01:16:37 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2013-01-15 01:16:37 +0100 |
| commit | 2c293a96deb33a9a24f7b9dacd301ab70edbd559 (patch) | |
| tree | c25e5feb24c7c9c133e75e903857eb5bb849b439 /src | |
| parent | 2e8e5876388ccd907ab978fea393540d86972b57 (diff) | |
| download | luajit-2c293a96deb33a9a24f7b9dacd301ab70edbd559.tar.gz luajit-2c293a96deb33a9a24f7b9dacd301ab70edbd559.tar.bz2 luajit-2c293a96deb33a9a24f7b9dacd301ab70edbd559.zip | |
FFI: Load FFI library on-demand for bytecode with cdata literals.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.dep | 2 | ||||
| -rw-r--r-- | src/lj_bcread.c | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 6433bea7..5d91723a 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -51,7 +51,7 @@ lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \ | |||
| 51 | lj_bcdef.h | 51 | lj_bcdef.h |
| 52 | lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 52 | lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 53 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \ | 53 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \ |
| 54 | lj_cdata.h lj_lex.h lj_bcdump.h lj_state.h | 54 | lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h |
| 55 | lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 55 | lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 56 | lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \ | 56 | lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \ |
| 57 | lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h | 57 | lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h |
diff --git a/src/lj_bcread.c b/src/lj_bcread.c index dfef3947..de3c997a 100644 --- a/src/lj_bcread.c +++ b/src/lj_bcread.c | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #if LJ_HASFFI | 15 | #if LJ_HASFFI |
| 16 | #include "lj_ctype.h" | 16 | #include "lj_ctype.h" |
| 17 | #include "lj_cdata.h" | 17 | #include "lj_cdata.h" |
| 18 | #include "lualib.h" | ||
| 18 | #endif | 19 | #endif |
| 19 | #include "lj_lex.h" | 20 | #include "lj_lex.h" |
| 20 | #include "lj_bcdump.h" | 21 | #include "lj_bcdump.h" |
| @@ -428,9 +429,18 @@ static int bcread_header(LexState *ls) | |||
| 428 | bcread_byte(ls) != BCDUMP_VERSION) return 0; | 429 | bcread_byte(ls) != BCDUMP_VERSION) return 0; |
| 429 | bcread_flags(ls) = flags = bcread_uleb128(ls); | 430 | bcread_flags(ls) = flags = bcread_uleb128(ls); |
| 430 | if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0; | 431 | if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0; |
| 431 | #if !LJ_HASFFI | 432 | if ((flags & BCDUMP_F_FFI)) { |
| 432 | if ((flags & BCDUMP_F_FFI)) return 0; | 433 | #if LJ_HASFFI |
| 434 | lua_State *L = ls->L; | ||
| 435 | if (!ctype_ctsG(G(L))) { | ||
| 436 | ptrdiff_t oldtop = savestack(L, L->top); | ||
| 437 | luaopen_ffi(L); /* Load FFI library on-demand. */ | ||
| 438 | L->top = restorestack(L, oldtop); | ||
| 439 | } | ||
| 440 | #else | ||
| 441 | return 0; | ||
| 433 | #endif | 442 | #endif |
| 443 | } | ||
| 434 | if ((flags & BCDUMP_F_STRIP)) { | 444 | if ((flags & BCDUMP_F_STRIP)) { |
| 435 | ls->chunkname = lj_str_newz(ls->L, ls->chunkarg); | 445 | ls->chunkname = lj_str_newz(ls->L, ls->chunkarg); |
| 436 | } else { | 446 | } else { |
