kphp
kphp copied to clipboard
[compiler, runtime] add FFI callbacks support
- Improved PHP FFI nullptr handling (+ added tests #456)
- Added FFI callbacks support (#450 #425)
- Added unmanaged FFI memory allocation
- Fixed double-vs-float token issue in FFI (#584)
- Added
@kphp-ffi-signalsafeannotation for C headers (cdef #586) - Fixed imprecise C parser error locations (#446)
- Added
ffi_cast_addr2ptrandffi_cast_ptr2addrfunctions
Unmanaged memory is handles like this:
- When unmanaged chunk is allocated, a refcnt is 2 instead of 1
- So, this memory is never deallocated via that object
- When free is used on such object, refcnt is decreased
- If that was the last reference, the memory will be deallocated
- Otherwise it will be deallocated when the last reference dies
- It's UB to call free on the same memory chunk more than once
The memory can be deallocated via the non-owning pointer
like CDataPtr; it's UB to call free on the owning object
after that. There should be exactly 1 free call per every
allocated memory chunk. The FFI documentation describes that
and shares a few common patterns.
FFI callback functions have restrictions placed on them:
- Can't throw from it
- Can't have captured state (no instance methods, no closures)
- Can't be resumable
Can use stateless lambdas, freestanding functions, and static methods as FFI callbacks.
Fixes #450 Fixes #425 Fixes #456 Fixes #585 Fixes #584 Fixes #586 Fixes #451 Fixes #446