Răsfoiți Sursa

Force error if lua_newstate() is used in 64 bit mode.

Mike Pall 16 ani în urmă
părinte
comite
055396a69d
3 a modificat fișierele cu 21 adăugiri și 0 ștergeri
  1. 14 0
      src/lib_aux.c
  2. 4 0
      src/lj_state.c
  3. 3 0
      src/lj_state.h

+ 14 - 0
src/lib_aux.c

@@ -18,6 +18,7 @@
 
 
 #include "lj_obj.h"
 #include "lj_obj.h"
 #include "lj_err.h"
 #include "lj_err.h"
+#include "lj_state.h"
 #include "lj_lib.h"
 #include "lj_lib.h"
 
 
 /* -- Module registration ------------------------------------------------- */
 /* -- Module registration ------------------------------------------------- */
@@ -349,8 +350,21 @@ static int panic(lua_State *L)
 
 
 LUALIB_API lua_State *luaL_newstate(void)
 LUALIB_API lua_State *luaL_newstate(void)
 {
 {
+#if LJ_64
+  lua_State *L = lj_state_newstate(mem_alloc, mem_create());
+#else
   lua_State *L = lua_newstate(mem_alloc, mem_create());
   lua_State *L = lua_newstate(mem_alloc, mem_create());
+#endif
   if (L) G(L)->panic = panic;
   if (L) G(L)->panic = panic;
   return L;
   return L;
 }
 }
 
 
+#if LJ_64
+LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
+{
+  UNUSED(f); UNUSED(ud);
+  fprintf(stderr, "Must use luaL_newstate() for 64 bit target\n");
+  return NULL;
+}
+#endif
+

+ 4 - 0
src/lj_state.c

@@ -158,7 +158,11 @@ static void close_state(lua_State *L)
   }
   }
 }
 }
 
 
+#if LJ_64
+lua_State *lj_state_newstate(lua_Alloc f, void *ud)
+#else
 LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
 LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
+#endif
 {
 {
   GG_State *GG = cast(GG_State *, f(ud, NULL, 0, sizeof(GG_State)));
   GG_State *GG = cast(GG_State *, f(ud, NULL, 0, sizeof(GG_State)));
   lua_State *L = &GG->L;
   lua_State *L = &GG->L;

+ 3 - 0
src/lj_state.h

@@ -27,5 +27,8 @@ static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)
 
 
 LJ_FUNC lua_State *lj_state_new(lua_State *L);
 LJ_FUNC lua_State *lj_state_new(lua_State *L);
 LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);
 LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);
+#if LJ_64
+LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);
+#endif
 
 
 #endif
 #endif