Do you mean the callback itself can get garbage collected after C uses it exactly once?
Here is the offending function
# The following functions call on each other in sequence
# This reformats the callback to only need to take one argument
function peripheral_notify(handle, service, characteristic, callback)
function c_callback(handle, service, characteristic, data, data_length, userdata)
jdata = unsafe_wrap(Vector{UInt8}, data, data_length)
callback(jdata)
simpleble_free(data)
end
peripheral_notify(handle, service, characteristic, c_callback, C_NULL)
end
# This converts the callback into a c function
function peripheral_notify(handle, service, characteristic, callback, userdata)
c_callback = @cfunction($callback, Cvoid, (SBLEPeripheral, SBLEUUID, SBLEUUID, Ptr{UInt8},Csize_t, Ptr{Cvoid}))
_peripheral_notify(handle, service, characteristic, c_callback, userdata)
end
# This calls ccall
_peripheral_notify(handle, service, characteristic, callback, userdata) =
@ccall simpleblepath.simpleble_peripheral_notify(
handle::SBLEPeripheral,
service::SBLEUUID,
characteristic::SBLEUUID,
callback::Ptr{Cvoid},
userdata::Ptr{Cvoid})::SimpleBLE_Error
Adding a GC.@preserve for the callbacks does not seem to fix it.