Skip to content

Commit

Permalink
Merge pull request #555 from Tieske/fix/luajit
Browse files Browse the repository at this point in the history
fix LuaJIT segfault due to ffi reloading
  • Loading branch information
DorianGray authored Jul 17, 2017
2 parents 9abdb19 + db6d8b4 commit 997514a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion busted/modules/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ return function()
return nil, '.busted file does not return a table.'
end

local defaults = defaults or {}
defaults = defaults or {}
local run = config.run or defaults.run

if run and run ~= '' then
Expand Down
19 changes: 19 additions & 0 deletions busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ return function(options)
arguments = cliArgs.Xoutput,
})

-- Pre-load the LuaJIT 'ffi' module if applicable
local isJit = (tostring(assert):match('builtin') ~= nil)
if isJit then
-- pre-load the ffi module, such that it becomes part of the environment
-- and Busted will not try to GC and reload it. The ffi is not suited
-- for that and will occasionally segfault if done so.
local ffi = require "ffi"

-- Now patch ffi.cdef to only be called once with each definition, as it
-- will error on re-registering.
local old_cdef = ffi.cdef
local exists = {}
ffi.cdef = function(def)
if exists[def] then return end
exists[def] = true
return old_cdef(def)
end
end

-- Set up helper script
if cliArgs.helper and cliArgs.helper ~= '' then
helperLoader(busted, cliArgs.helper, {
Expand Down

0 comments on commit 997514a

Please sign in to comment.