By the way, I think you can fix this problem by using s7_define_unsafe_typed_function or s7_define_function. There's a discussion of function safety in s7-ffi.html in the section on optimizations.