Open Norbytus opened 4 years ago
I have a sneaking suspicion that this is caused by the conflict between different allocators. When writing Rust code to interface with PHP, you've got four allocation systems to juggle, but Solder currently assumes that everything will happily free everything else's memory.
To solve this, you need to pass everything back to the place from whence it came; never drop any Rust stuff inside PHP, or PHP stuff inside Rust. A later version of solder might expose the three allocators to the wider world, but for now this will have to do.
Specifically, the issue is (as far as I can tell) in the section beginning:
impl From<&str> for Zval {
It shouldn't pass the pointer into the ZendString
; it should allocate new memory using the PHP allocator and copy the bytes into it. (Also – that should really be a &mut
if you're not planning to set the GC_IMMUTABLE
flag!) Alternatively, the GC_COLLECTABLE
, GC_PROTECTED
and / or GC_PERSISTENT
(_LOCAL
) (intended for malloc
, which is not the Rust allocator! Be careful, because I don't know what assumptions PHP makes about that) might be possible to combine to solve the problem.
If take example and
hello_world
function like this:It will crash with segmentation fault (core dumped) looks like problem in add_zend_value_zval