From baf3a9133bf0bc7069e5191b780c221485b2dda6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 10 Dec 2019 11:55:14 +0100 Subject: Add support for class_alias to preloading Related to bug #78918. --- ext/opcache/tests/preload_class_alias.inc | 3 +++ ext/opcache/tests/preload_class_alias.phpt | 17 +++++++++++++++++ ext/opcache/zend_persist.c | 6 ++++++ ext/opcache/zend_persist_calc.c | 6 ++++++ 4 files changed, 32 insertions(+) create mode 100644 ext/opcache/tests/preload_class_alias.inc create mode 100644 ext/opcache/tests/preload_class_alias.phpt diff --git a/ext/opcache/tests/preload_class_alias.inc b/ext/opcache/tests/preload_class_alias.inc new file mode 100644 index 0000000000..2aaa5adafc --- /dev/null +++ b/ext/opcache/tests/preload_class_alias.inc @@ -0,0 +1,3 @@ + +--FILE-- + +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 1571093419..bcbd2f270f 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -700,6 +700,12 @@ static void zend_persist_class_entry(zval *zv) zend_class_entry *ce = Z_PTR_P(zv); if (ce->type == ZEND_USER_CLASS) { + /* The same zend_class_entry may be reused by class_alias */ + zend_class_entry *new_ce = zend_shared_alloc_get_xlat_entry(ce); + if (new_ce) { + Z_PTR_P(zv) = new_ce; + return; + } if ((ce->ce_flags & ZEND_ACC_LINKED) && (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED) && (ce->ce_flags & ZEND_ACC_PROPERTY_TYPES_RESOLVED) diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index cc798b27de..dacc2376e8 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -352,6 +352,12 @@ static void zend_persist_class_entry_calc(zval *zv) Bucket *p; if (ce->type == ZEND_USER_CLASS) { + /* The same zend_class_entry may be reused by class_alias */ + if (zend_shared_alloc_get_xlat_entry(ce)) { + return; + } + zend_shared_alloc_register_xlat_entry(ce, ce); + check_property_type_resolution(ce); ZCG(is_immutable_class) = -- cgit v1.2.1