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")
struct slice{
   char *data;
   int len;

local sk ="struct slice")
local sv ="struct slice") = ""> = "">

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

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

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.