Adjust director_finalizer_runme.php

Without inventing a SWIG/PHP-specific mechanism, we can't really
finalise objects in the way the testcase expects, so adjust the
testcase minimally so we avoid triggering C++ undefined behaviour
(use-after-free).
This commit is contained in:
Olly Betts 2021-05-03 16:07:50 +12:00
commit 81d1618777

View file

@ -12,7 +12,12 @@ check::globals(array());
class MyFoo extends Foo {
function __destruct() {
$this->orStatus(2);
# It's not safe to call methods on the C++ object from the PHP destructor
# if the object has been disowned, since the C++ object will already have
# been destroyed by the time the PHP destructor runs.
if ($this->thisown) {
$this->orStatus(2);
}
if (method_exists(get_parent_class(), "__destruct")) {
parent::__destruct();
}
@ -41,19 +46,23 @@ resetStatus();
$a = new MyFoo();
$a->thisown = 0;
check::equal(getStatus(), 0, "shadow release does not fire destructor of disowned object");
deleteFoo($a);
unset($a);
check::equal(getStatus(), 3, "getStatus() failed #4");
# getStatus() would ideally return 3 here.
check::equal(getStatus(), 1, "getStatus() failed #4");
resetStatus();
$a = new MyFoo();
$a->thisown = 0;
deleteFoo(launder($a));
$g = launder($a);
unset($a);
check::equal(getStatus(), 3, "getStatus() failed #5");
deleteFoo($g);
# getStatus() would ideally return 3 here.
check::equal(getStatus(), 1, "getStatus() failed #5");
resetStatus();