lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


YangFan wrote:
> I have written a piece of cpp code, it works under Windows XP Pro SP3,
> should be compiled by VC2008 with luabind 0.8.1 which depends on boost
> library. Also a lua test function which will be called from cpp source code.
> See the attachment.
> 
> Build this project, then run the executable with either LuaJIT dll or official
> Lua dll. You can see after printing 3, official Lua will push an error message, 
> but LuaJIT just crashes.

Thank you for the test case! I can reproduce the problem now
(it's not in lua_pcall). Patch attached.

--Mike
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -486,8 +486,12 @@ LUA_API size_t lua_objlen(lua_State *L, int idx)
 LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
 {
   cTValue *o = index2adr(L, idx);
-  ASMFunction gate = funcV(o)->c.gate;
-  return (gate == lj_gate_c || gate == lj_gate_cwrap) ? funcV(o)->c.f : NULL;
+  if (tvisfunc(o)) {
+    ASMFunction gate = funcV(o)->c.gate;
+    if (gate == lj_gate_c || gate == lj_gate_cwrap)
+      return funcV(o)->c.f;
+  }
+  return NULL;
 }
 
 LUA_API void *lua_touserdata(lua_State *L, int idx)