luajit 2.1 table.sort segmentation fault on OSX and Linux

  • From: ivan starkov <istarkov@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 20 Mar 2014 12:40:45 +0400

This code cause segmentation fault inside table.sort on OSX and Linux
(Ubuntu)
luajit 2.1
---------------------------------------------------------------------------------
local ffi = require ("ffi")

local cdef = [[
typedef struct {
  double value;
} some_struct;
]]

ffi.cdef(cdef)

local fn = function()
  local sorted = {}
  local any_struct_ffi = ffi.new("some_struct[?]", 10)

  for i=0, 10 do
    sorted[i] = 10-i
    any_struct_ffi[i].value = i
  end

  return function()
    table.sort(sorted)
  end
end


local ss = fn()

for i=0,3000000 do
  ss()
end

---------------------------------------------------------------------------------

Other related posts: