Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Busted and LuaJIT are not playing well together. #369

Closed
jszakmeister opened this issue Mar 1, 2015 · 7 comments
Closed

Busted and LuaJIT are not playing well together. #369

jszakmeister opened this issue Mar 1, 2015 · 7 comments

Comments

@jszakmeister
Copy link
Contributor

I just wanted to give you guys a heads up that some of Busted's more recent changes have caused some issues for Neovim's test suite using LuaJIT.

This fixes one issue, but I don't think it's the right fix--I think LuaJIT is broken here:

diff --git a/busted/compatibility.lua b/busted/compatibility.lua
index 7837656..3ae58e5 100644
--- a/busted/compatibility.lua
+++ b/busted/compatibility.lua
@@ -55,6 +55,6 @@ return {
         end
       end
     end
-    os.exit(code, close)
+    os.exit(code)
   end,
 }

Some other newer behavior in Busted is now helping to trigger an assertion error about ctypes in LuaJIT too--again, I don't think it's technically Busted's problem, but it may affect anyone who is using LuaJIT and the ffi module.

More than anything, I wanted to let you know that there are some issues with Busted and LuaJIT. I've brought this to the attention of Mike Pall as well. Hopefully, he can help track some of this down too: http://www.freelists.org/post/luajit/Assertion-error

@o-lim
Copy link
Contributor

o-lim commented Mar 1, 2015

According to the change log, os.exit(status[, close]) should be supported since LuaJIT 2.0.0-beta6. Sounds like your suspicions may be right on, at least regarding os.exit.

LuaJIT 2.0.0-beta6 — 2011-02-11

  • New features:
  • PowerPC/e500v2 port of the LuaJIT interpreter is complete.
  • Various minor features from Lua 5.2: Hex escapes in literals, '*' escape, reversible string.format("%q",s), "%g" pattern, table.sort checks callbacks, os.exit(status|true|false[,close]).
  • Lua 5.2 __pairs and __ipairs metamethods (disabled by default).
  • Initial release of the FFI library.

@o-lim
Copy link
Contributor

o-lim commented Mar 1, 2015

@jszakmeister: I looked at one of your test cases here (https://www.freelists.org/post/luajit/Assertion-error,2). You are doing a require 'ffi in your spec files, which seems to be related to your error.

If I comment either one of the require('ffi') lines out, it runs
fine. Perhaps busted is clearing something, and ffi is actually
getting loaded twice, even though it shouldn't?

I should add that this happens with busted 2.0-rc7. If I use
busted 2.0-rc4, it doesn't fail. In fact, it seems like the
issue started happening between 2.0rc6 and 2.0rc7. I'll try and
bisect it down to the commit that introduced the problem, and
hopefully that will provide a better clue.

The reason for this is that busted will reload any requred modules for each spec file. So ffi is being loaded twice. This was done to address issue #62, and has been present since rc5. As a workaround, to prevent this from happening you can put the require in a helper script that is loaded by busted before running any tests.
helper.lua:

local ffi = require 'ffi'
$ busted --helper=helper.lua

or, alternatively, you can do

$ luajit -e 'require "ffi"' /path/to/busted

This should prevent the ffi module from being reloaded by busted.

Maybe LuaJIT doesn't like loading the ffi module multiple times.

The os.exit change, I believe, is new to rc7.

@jszakmeister
Copy link
Contributor Author

The reason for this is that busted will reload any requred modules for each spec file. So ffi is being loaded twice. This was done to address issue #62, and has been present since rc5. As a workaround, to prevent this from happening you can put the require in a helper script that is loaded by busted before running any tests.

Thanks @o-lim! That does indeed help! Though, I think it might still be worthwhile for LuaJIT to fix though.

@o-lim
Copy link
Contributor

o-lim commented Mar 1, 2015

Agreed, it looks like this has revealed some issues in LuaJIT that should be fixed.

@jszakmeister does the workaround fix both the GC and ctype assertion issues or just the ctype assertion issue? Just wondering if the multiple loading of the ffi module causes the GC issue as well, or if they are two separate problems.

@jszakmeister
Copy link
Contributor Author

@o-lim Yes, both are fixed with the workaround. Thank you so much for helping me out on this!

@DorianGray
Copy link
Contributor

👍

mikz added a commit to 3scale/APIcast that referenced this issue Oct 24, 2016
to prevent: `Assertion failed: (id > 0 && id < cts->top), function ctype_check, file ./lj_ctype.h`
> http://www.freelists.org/post/luajit/Assertion-error,4

lunarmodules/busted#369 (comment)
mikz added a commit to 3scale/APIcast that referenced this issue Oct 24, 2016
to prevent: `Assertion failed: (id > 0 && id < cts->top), function ctype_check, file ./lj_ctype.h`
> http://www.freelists.org/post/luajit/Assertion-error,4

lunarmodules/busted#369 (comment)
@Tieske
Copy link
Member

Tieske commented Jun 17, 2017

for reference, a possible fix: lunarmodules/luassert#150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants