Segmentation fault when calling inside __callStatic with arguments
oraoto opened this issue · 1 comments
oraoto commented
Environment:
- lib-ffi: 3.2.1
- php-ffi: latest master
- php version: latest PHP-7.4 (php/php-src@76f8a90)
<?php
class Test
{
private static $ffi;
private static function createFFI()
{
$cdef="
int abs(int n);
";
static::$ffi = FFI::cdef($cdef, "libc.so.6");
}
private static function getFFI()
{
if (!static::$ffi) {
static::createFFI();
}
return static::$ffi;
}
public static function __callStatic($method, $args)
{
$ffi = static::getFFI();
return $ffi->abs(-1);
}
public static function absDirect()
{
// same as __callStatic
$ffi = static::getFFI();
return $ffi->abs(-1);
}
}
When calling absDirect
or __callStatic
without arguments, it works correctly:
// call absDirect
echo Test::absDirect(); // 1
echo Test::absDirect(); // 1
// __callStatic with no argument
echo Test::abs(); // 1
echo Test::abs(); // 1
However, __callStatic
with arguments will segfault on the second call, event we don't use the arguments at all:
echo Test::abs(-1); // 1
echo Test::abs(-1); // segfault
dstogov commented
Thanks far catching.
ext/ffi is already merged into PHP-7.4 and master.
I've just fixed the problem in the php repository.