lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


First, i am learning LuaJIT FFI so i am probably the source of the bug ;-)

This is the reduced program for this bug:
***
local ffi = require("ffi")
ffi.cdef[[
struct slice{
   char *data;
   int len;
};
]]

local sk = ffi.new("struct slice")
local sv = ffi.new("struct slice")
sk.data = "">
sv.data = "">

local function db_add(key, value)
sk.len = string.len(key)
ffi.copy(sk.data, key)
sv.len = string.len(value)
ffi.copy(sv.data, value)
print("add : " .. ffi.string(sk.data) .. " / " .. ffi.string(sv.data))
end

for n = 1,1000 do
db_add("key" .. n, "value" .. n)
end
***

This program print the key / value from 1 to 141 without problem but not the 142 key and do a segmentation fault at key 170.
Theses values are for my Ubuntu Box and may change on other box.

I am doing something wrong or there's a bug in LuaJIT FFI ?

Thanks in advance, Olivier.