Skip to content

Fix destruction of dl'ed module classes #17961

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 2 commits 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
23 changes: 10 additions & 13 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "zend.h"
#include "zend_execute.h"
#include "zend_API.h"
#include "zend_hash.h"
#include "zend_modules.h"
#include "zend_extensions.h"
#include "zend_constants.h"
Expand Down Expand Up @@ -3111,21 +3112,17 @@ ZEND_API zend_result zend_get_module_started(const char *module_name) /* {{{ */
}
/* }}} */

static int clean_module_class(zval *el, void *arg) /* {{{ */
{
zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
int module_number = *(int *)arg;
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
return ZEND_HASH_APPLY_REMOVE;
} else {
return ZEND_HASH_APPLY_KEEP;
}
}
/* }}} */

static void clean_module_classes(int module_number) /* {{{ */
{
zend_hash_apply_with_argument(EG(class_table), clean_module_class, (void *) &module_number);
/* Child classes may reuse structures from parent classes, so destroy in reverse order. */
Bucket *bucket;
ZEND_HASH_REVERSE_FOREACH_BUCKET(EG(class_table), bucket) {
zend_class_entry *ce = Z_CE(bucket->val);
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
zend_hash_del_bucket(EG(class_table), bucket);
}
} ZEND_HASH_FOREACH_END();

}
/* }}} */

Expand Down
12 changes: 12 additions & 0 deletions ext/dl_test/dl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,22 @@ PHP_METHOD(DlTest, test)
RETURN_STR(retval);
}

PHP_METHOD(DlTestSuperClass, test)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_NULL();
}

/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(dl_test)
{
zend_class_entry *ce;

register_class_DlTest();
ce = register_class_DlTestSuperClass();
register_class_DlTestSubClass(ce);
register_class_DlTestAliasedClass();

/* Test backwards compatibility */
if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
Expand Down
12 changes: 12 additions & 0 deletions ext/dl_test/dl_test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ function dl_test_test2(string $str = ""): string {}
class DlTest {
public function test(string $str = ""): string {}
}

class DlTestSuperClass {
public int $a;
public function test(string $str = ""): string {}
}

class DlTestSubClass extends DlTestSuperClass {
}

/** @alias DlTestClassAlias */
class DlTestAliasedClass {
}
58 changes: 57 additions & 1 deletion ext/dl_test/dl_test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading