Permalink
Browse files

LuaJIT crashes with Spring's 32bit FPU setting

FPU _must_ run in 80bit mode for LuaJIT, duno how to finally solve that, for now use wrappers in LuaParser to make it not crash at start
  • Loading branch information...
1 parent c3d4c45 commit 42ad09a91ca1eb337bcb355908974c55f0f1b930 jK committed Apr 20, 2012
Showing with 49 additions and 3 deletions.
  1. +12 −0 rts/Lua/LuaParser.cpp
  2. +3 −3 rts/Lua/LuaRules.cpp
  3. +34 −0 rts/lib/lua/include/LuaInclude.h
View
@@ -48,11 +48,13 @@ LuaParser::LuaParser(const string& _fileName,
lowerKeys(true),
lowerCppKeys(true)
{
+ PUSH_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
L = lua_open();
if (L != NULL) {
SetupEnv();
}
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
}
@@ -69,11 +71,13 @@ LuaParser::LuaParser(const string& _textChunk,
lowerKeys(true),
lowerCppKeys(true)
{
+ PUSH_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
L = lua_open();
if (L != NULL) {
SetupEnv();
}
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
}
@@ -144,8 +148,10 @@ void LuaParser::SetupEnv()
bool LuaParser::Execute()
{
+ PUSH_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
if (!IsValid()) {
errorLog = "could not initialize LUA library";
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
@@ -167,13 +173,15 @@ bool LuaParser::Execute()
errorLog = "could not open file: " + fileName;
lua_close(L);
L = NULL;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
}
else {
errorLog = "invalid format or empty file";
lua_close(L);
L = NULL;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
@@ -185,6 +193,7 @@ bool LuaParser::Execute()
error, codeLabel.c_str(), errorLog.c_str());
lua_close(L);
L = NULL;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
@@ -211,6 +220,7 @@ bool LuaParser::Execute()
error, fileName.c_str(), errorLog.c_str());
lua_close(L);
L = NULL;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
@@ -219,6 +229,7 @@ bool LuaParser::Execute()
LOG_L(L_ERROR, "missing return table from %s", fileName.c_str());
lua_close(L);
L = NULL;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return false;
}
@@ -232,6 +243,7 @@ bool LuaParser::Execute()
valid = true;
+ POP_LUAJIT(); //FIXME just for testing, LuaParser should never use LuaJIT in final
return true;
}
View
@@ -1037,16 +1037,16 @@ void CLuaRules::Cob2Lua(const LuaHashString& name, const CUnit* unit,
}
LUA_CALL_IN_CHECK(L);
+ lua_checkstack(L, 1 + 3 + argsCount);
const int top = lua_gettop(L);
-
- if (!lua_checkstack(L, 1 + 3 + argsCount)) {
+ /*if (!lua_checkstack(L, 1 + 3 + argsCount)) {
LOG_L(L_WARNING, "CLuaRules::Cob2Lua() lua_checkstack() error: %s",
name.GetString().c_str());
args[0] = 0; // failure
lua_settop(L, top);
return;
- }
+ }*/
if (!name.GetGlobalFunc(L)) {
LOG_L(L_WARNING, "CLuaRules::Cob2Lua() missing function: %s",
@@ -7,6 +7,40 @@
//#include <boost/thread/recursive_mutex.hpp>
+inline void PUSH_LUAJIT()
+{
+#if defined(STREFLOP_X87) || defined(STREFLOP_SSE) || defined(STREFLOP_SOFT)
+ streflop::fpenv_t fenv;
+ streflop::fegetenv(&fenv);
+ fenv.x87_mode |= 0x0300; // 80 bits internal operations
+ streflop::fesetenv(&fenv);
+#endif
+}
+
+
+inline void POP_LUAJIT()
+{
+#if defined(STREFLOP_X87) || defined(STREFLOP_SSE) || defined(STREFLOP_SOFT)
+ streflop::fpenv_t fenv;
+ streflop::fegetenv(&fenv);
+ fenv.x87_mode &= 0xFCFF; // 32 bits internal operations
+ streflop::fesetenv(&fenv);
+#endif
+}
+
+class LuaJIT_FPU {
+ LuaJIT_FPU() { PUSH_LUAJIT(); }
+ ~LuaJIT_FPU() { POP_LUAJIT(); }
+};
+
+
+//FIXME this is just for testing/dev'ing!!!
+#define lua_checkstack(L, i) \
+ LuaJIT_FPU luaJitFPUSettings(); \
+ lua_checkstack(L, i);
+
+
+
inline void lua_pushsstring(lua_State* L, const std::string& str)
{
lua_pushlstring(L, str.data(), str.size());

0 comments on commit 42ad09a

Please sign in to comment.