cffi-lua
cffi-lua copied to clipboard
LuaJIT FFI versus CFFI: CFFI permits setting a new function to a callback on which free() has been called, causing a crash upon execution of the callback or free()
cffi = require("cffi")
callback = cffi.cast("void (*)()", function() end)
callback:free()
callback:set(function() end)
callback:free() -- this line crashes
Title is kind of misleading. LuaJIT does not support this either:
ffi = require 'ffi'
callback = ffi.cast("void (*)()", function() end)
callback:free()
callback:set(function() end) -- error: bad callback
Probably should replicate this behavior, and throw a Lua error instead of outright crashing.
Good point. To make it in line with LuaJIT, it should fail on using set on a freed callback. Although the code is wrong per the documentation, being able to set a free'd callback is confusing.