Skip to content

Commit 97ed444

Browse files
Fixes
1 parent 85307db commit 97ed444

File tree

10 files changed

+70
-10
lines changed

10 files changed

+70
-10
lines changed

Zend/Optimizer/zend_optimizer.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,13 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
784784
return false;
785785
}
786786
}
787+
// Ignore deprecated aliases so that they are fetched at runtime
788+
if (Z_TYPE_P(ce_zv) == IS_ALIAS_PTR) {
789+
zend_class_alias *alias = Z_CLASS_ALIAS_P(ce_zv);
790+
if (alias->alias_flags & ZEND_ACC_DEPRECATED) {
791+
return true;
792+
}
793+
}
787794
return ce->type == ZEND_USER_CLASS
788795
&& (!ce->info.user.filename || ce->info.user.filename != filename);
789796
}
@@ -817,6 +824,12 @@ zend_class_entry *zend_optimizer_get_class_entry(
817824
return Z_PTR_P(ce_or_alias);
818825
}
819826
ZEND_ASSERT(Z_TYPE_P(ce_or_alias) == IS_ALIAS_PTR);
827+
zend_class_alias *alias = Z_CLASS_ALIAS_P(ce_or_alias);
828+
if (alias->alias_flags & ZEND_ACC_DEPRECATED) {
829+
// Pretend that the class cannot be found so that it gets looked
830+
// up at runtime
831+
return NULL;
832+
}
820833
return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
821834
}
822835

Zend/zend_API.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,8 @@ ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_
36173617
}
36183618
return SUCCESS;
36193619
}
3620+
3621+
zend_string_release(original_name);
36203622
return FAILURE;
36213623
}
36223624
/* }}} */

Zend/zend_execute_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
328328
}
329329
} ZEND_HASH_FOREACH_END();
330330
ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) {
331+
if (Z_TYPE_P(zv) == IS_ALIAS_PTR) {
332+
continue;
333+
}
331334
zend_class_entry *ce;
332335
Z_CE_FROM_ZVAL_P(ce, zv);
333336

Zend/zend_opcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ ZEND_API void destroy_zend_class(zval *zv)
301301

302302
if (class_alias->attributes) {
303303
zend_hash_release(class_alias->attributes);
304-
class_alias->attributes = NULL;
304+
// class_alias->attributes = NULL;
305305
}
306306
if (class_alias->name) {
307307
zend_string_release(class_alias->name);
308-
class_alias->name = NULL;
308+
// class_alias->name = NULL;
309309
}
310310
return;
311311
}

ext/opcache/ZendAccelerator.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,14 @@ static void preload_link(void)
41464146
continue;
41474147
}
41484148

4149+
// Not preloading class constants for deprecated aliases
4150+
if (Z_TYPE_P(zv) == IS_ALIAS_PTR) {
4151+
zend_class_alias *class_alias = Z_CLASS_ALIAS_P(zv);
4152+
if (class_alias->alias_flags & ZEND_ACC_DEPRECATED) {
4153+
continue;
4154+
}
4155+
}
4156+
41494157
if ((ce->ce_flags & ZEND_ACC_LINKED) && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
41504158
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) { /* don't update traits */
41514159
CG(in_compilation) = true; /* prevent autoloading */

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ static zend_class_entry* zend_get_known_class(const zend_op_array *op_array, con
570570

571571
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
572572
class_name = Z_STR_P(zv);
573-
ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
573+
// ZEND_FETCH_CLASS_SILENT - ignore alias deprecation
574+
// TODO but we want to not cache the ce if i is a deprecated alias
575+
ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
574576
if (ce && (ce->type == ZEND_INTERNAL_CLASS || ce->info.user.filename != op_array->filename)) {
575577
ce = NULL;
576578
}

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,19 @@ static void zend_accel_do_delayed_early_binding(
365365
CG(in_compilation) = 1;
366366
for (uint32_t i = 0; i < persistent_script->num_early_bindings; i++) {
367367
zend_early_binding *early_binding = &persistent_script->early_bindings[i];
368-
zend_class_entry *ce = zend_hash_find_ex_ptr(EG(class_table), early_binding->lcname, 1);
369-
if (!ce) {
368+
zval *ce_or_alias = zend_hash_find_ex(EG(class_table), early_binding->lcname, 1);
369+
if (!ce_or_alias) {
370370
zval *zv = zend_hash_find_known_hash(EG(class_table), early_binding->rtd_key);
371+
zend_class_entry *ce = NULL;
371372
if (zv) {
372-
zend_class_entry *orig_ce = Z_CE_P(zv);
373-
zend_class_entry *parent_ce = !(orig_ce->ce_flags & ZEND_ACC_LINKED)
374-
? zend_hash_find_ex_ptr(EG(class_table), early_binding->lc_parent_name, 1)
373+
zend_class_entry *orig_ce;
374+
Z_CE_FROM_ZVAL_P(orig_ce, zv);
375+
zval *parent_ce_or_alias = !(orig_ce->ce_flags & ZEND_ACC_LINKED)
376+
? zend_hash_find_ex(EG(class_table), early_binding->lc_parent_name, 1)
375377
: NULL;
376-
if (parent_ce || (orig_ce->ce_flags & ZEND_ACC_LINKED)) {
378+
if (parent_ce_or_alias || (orig_ce->ce_flags & ZEND_ACC_LINKED)) {
379+
zend_class_entry *parent_ce;
380+
Z_CE_FROM_ZVAL_P(parent_ce, parent_ce_or_alias);
377381
ce = zend_try_early_bind(orig_ce, parent_ce, early_binding->lcname, zv);
378382
}
379383
}

ext/opcache/zend_file_cache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ static void zend_file_cache_serialize_class(zval *zv,
765765
zend_file_cache_metainfo *info,
766766
void *buf)
767767
{
768+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_PTR);
768769
zend_class_entry *ce;
769770

770771
SERIALIZE_PTR(Z_PTR_P(zv));
@@ -1619,6 +1620,7 @@ static void zend_file_cache_unserialize_class_constant(zval *
16191620
zend_persistent_script *script,
16201621
void *buf)
16211622
{
1623+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_PTR);
16221624
if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
16231625
zend_class_constant *c;
16241626

ext/opcache/zend_persist.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "zend_operators.h"
3030
#include "zend_interfaces.h"
3131
#include "zend_attributes.h"
32+
#include "zend_class_alias.h"
3233

3334
#ifdef HAVE_JIT
3435
# include "Optimizer/zend_func_info.h"
@@ -909,6 +910,21 @@ static void zend_persist_class_constant(zval *zv)
909910
zend_persist_type(&c->type);
910911
}
911912

913+
zend_class_alias *zend_persist_class_alias_entry(zend_class_alias *orig_alias)
914+
{
915+
Bucket *p;
916+
zend_class_alias *alias = orig_alias;
917+
918+
alias = zend_shared_memdup_put(alias, sizeof(zend_class_alias));
919+
alias->ce = zend_persist_class_entry(alias->ce);
920+
// zend_accel_store_string(alias->name);
921+
if (alias->attributes) {
922+
alias->attributes = zend_persist_attributes(alias->attributes);
923+
}
924+
925+
return alias;
926+
}
927+
912928
zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
913929
{
914930
Bucket *p;
@@ -1296,7 +1312,12 @@ static void zend_accel_persist_class_table(HashTable *class_table)
12961312
ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
12971313
ZEND_ASSERT(p->key != NULL);
12981314
zend_accel_store_interned_string(p->key);
1299-
Z_CE(p->val) = zend_persist_class_entry(Z_CE(p->val));
1315+
if (Z_TYPE(p->val) == IS_ALIAS_PTR) {
1316+
Z_CLASS_ALIAS(p->val) = zend_persist_class_alias_entry(Z_CLASS_ALIAS(p->val));
1317+
} else {
1318+
ZEND_ASSERT(Z_TYPE(p->val) == IS_PTR);
1319+
Z_CE(p->val) = zend_persist_class_entry(Z_CE(p->val));
1320+
}
13001321
} ZEND_HASH_FOREACH_END();
13011322
ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
13021323
if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {

ext/opcache/zend_persist_calc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,11 @@ static void zend_persist_class_alias_entry_calc(zend_class_alias *alias)
599599
// alias->ce is going to be a pointer to a class entry that will be
600600
// persisted on its own, here we just need to add size for the alias
601601
ADD_SIZE(sizeof(zend_class_alias));
602+
// And the things that the alias holds directly
603+
ADD_INTERNED_STRING(alias->name);
604+
if (alias->attributes) {
605+
zend_persist_attributes_calc(alias->attributes);
606+
}
602607
zend_persist_class_entry_calc(alias->ce);
603608
}
604609

0 commit comments

Comments
 (0)