Skip to content

Test memleak when FFI::new() or FFI::type() is called as instance methods #11720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/ffi/tests/017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ ffi
ffi.enable=1
--FILE--
<?php
$ffi = FFI::cdef();

try {
var_dump(FFI::new("struct X {void x();}"));
var_dump($ffi->new("struct X {void x();}"));
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
var_dump(FFI::new("struct X {struct X x;}"));
var_dump($ffi->new("struct X {struct X x;}"));
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
try {
var_dump(FFI::new("struct X {struct X *ptr;}"));
var_dump($ffi->new("struct X {struct X *ptr;}"));
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/tests/021.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ffi.enable=1
--FILE--
<?php
function test($size, $type) {
if (FFI::sizeof(FFI::new($type)) !== $size) {
if (FFI::sizeof(FFI::cdef()->new($type)) !== $size) {
echo "FAIL: sizeof($type) != $size\n";
}
}
Expand Down
16 changes: 9 additions & 7 deletions ext/ffi/tests/046.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ ffi
ffi.enable=1
--FILE--
<?php
$x = FFI::type("uint8_t");
$ffi = FFI::cdef();

$x = $ffi->type("uint8_t");
var_dump($x->getKind() === $x::TYPE_UINT8);
var_dump($x->getSize());
var_dump($x->getAlignment());

$x = FFI::type("enum __attribute__((packed)) {a2, b2}");
$x = $ffi->type("enum __attribute__((packed)) {a2, b2}");
var_dump($x->getKind() === $x::TYPE_ENUM);
var_dump($x->getEnumKind() === $x::TYPE_UINT8);

$x = FFI::type("char[5]");
$x = $ffi->type("char[5]");
var_dump($x->getKind() === $x::TYPE_ARRAY);
var_dump($x->getSize());
var_dump($x->getArrayElementType()->getKind() === $x::TYPE_CHAR);
var_dump($x->getArrayLength());

$x = FFI::type("void*");
$x = $ffi->type("void*");
var_dump($x->getKind() === $x::TYPE_POINTER);
var_dump($x->getPointerType()->getKind() === $x::TYPE_VOID);

$x = FFI::type("struct {double x; double y;}");
$x = $ffi->type("struct {double x; double y;}");
var_dump($x->getKind() === $x::TYPE_STRUCT);
var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0);
var_dump($x->getStructFieldNames());
Expand All @@ -34,7 +36,7 @@ var_dump($x->getStructFieldOffset("y"));
var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE);
var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE);

$x = FFI::type("union {double x; double y;}");
$x = $ffi->type("union {double x; double y;}");
var_dump($x->getKind() === $x::TYPE_STRUCT);
var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0);
var_dump($x->getStructFieldNames());
Expand All @@ -43,7 +45,7 @@ var_dump($x->getStructFieldOffset("y"));
var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE);
var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE);

$x = FFI::type("void (*)(double,int32_t)");
$x = $ffi->type("void (*)(double,int32_t)");
var_dump($x->getKind() === $x::TYPE_POINTER);
var_dump($x->getPointerType()->getKind() === $x::TYPE_FUNC);
var_dump($x->getPointerType()->getFuncReturnType()->getKind() === $x::TYPE_VOID);
Expand Down