]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Load FFI library on-demand for bytecode with cdata literals.
authorMike Pall <mike>
Tue, 15 Jan 2013 00:16:37 +0000 (01:16 +0100)
committerMike Pall <mike>
Tue, 15 Jan 2013 00:16:37 +0000 (01:16 +0100)
src/Makefile.dep
src/lj_bcread.c

index 6433bea7963157ad16493e70b9726ad8da873f65..5d91723a76da605256c53990c82d1b8c5df9abc9 100644 (file)
@@ -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 \
  lj_bcdef.h
 lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \
- lj_cdata.h lj_lex.h lj_bcdump.h lj_state.h
+ lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h
 lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \
  lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h
index dfef3947caffd9153478b10d29efce37345e17b6..de3c997ad898d33b9df2d9097e87fb4e7affe240 100644 (file)
@@ -15,6 +15,7 @@
 #if LJ_HASFFI
 #include "lj_ctype.h"
 #include "lj_cdata.h"
+#include "lualib.h"
 #endif
 #include "lj_lex.h"
 #include "lj_bcdump.h"
@@ -428,9 +429,18 @@ static int bcread_header(LexState *ls)
       bcread_byte(ls) != BCDUMP_VERSION) return 0;
   bcread_flags(ls) = flags = bcread_uleb128(ls);
   if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0;
-#if !LJ_HASFFI
-  if ((flags & BCDUMP_F_FFI)) return 0;
+  if ((flags & BCDUMP_F_FFI)) {
+#if LJ_HASFFI
+    lua_State *L = ls->L;
+    if (!ctype_ctsG(G(L))) {
+      ptrdiff_t oldtop = savestack(L, L->top);
+      luaopen_ffi(L);  /* Load FFI library on-demand. */
+      L->top = restorestack(L, oldtop);
+    }
+#else
+    return 0;
 #endif
+  }
   if ((flags & BCDUMP_F_STRIP)) {
     ls->chunkname = lj_str_newz(ls->L, ls->chunkarg);
   } else {