Fix static property indirections in file cache

If the class is already linked, we need to serialize and
unserialize INDIRECTed static properties. Normally these would
be set up when copying from cache.
This commit is contained in:
Nikita Popov 2020-05-20 10:55:36 +02:00
parent 8819d247c6
commit db0cdcbb0a

View File

@ -368,6 +368,10 @@ static void zend_file_cache_serialize_zval(zval *zv,
zend_file_cache_serialize_ast(GC_AST(ast), script, info, buf); zend_file_cache_serialize_ast(GC_AST(ast), script, info, buf);
} }
break; break;
case IS_INDIRECT:
/* Used by static properties. */
SERIALIZE_PTR(Z_INDIRECT_P(zv));
break;
} }
} }
@ -626,7 +630,6 @@ static void zend_file_cache_serialize_class(zval *zv,
void *buf) void *buf)
{ {
zend_class_entry *ce; zend_class_entry *ce;
zend_class_entry *parent = NULL;
SERIALIZE_PTR(Z_PTR_P(zv)); SERIALIZE_PTR(Z_PTR_P(zv));
ce = Z_PTR_P(zv); ce = Z_PTR_P(zv);
@ -637,7 +640,6 @@ static void zend_file_cache_serialize_class(zval *zv,
if (!(ce->ce_flags & ZEND_ACC_LINKED)) { if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
SERIALIZE_STR(ce->parent_name); SERIALIZE_STR(ce->parent_name);
} else { } else {
parent = ce->parent;
SERIALIZE_PTR(ce->parent); SERIALIZE_PTR(ce->parent);
} }
} }
@ -655,16 +657,13 @@ static void zend_file_cache_serialize_class(zval *zv,
} }
} }
if (ce->default_static_members_table) { if (ce->default_static_members_table) {
zval *table, *p, *end; zval *p, *end;
SERIALIZE_PTR(ce->default_static_members_table); SERIALIZE_PTR(ce->default_static_members_table);
table = ce->default_static_members_table; p = ce->default_static_members_table;
UNSERIALIZE_PTR(table); UNSERIALIZE_PTR(p);
/* Serialize only static properties in this class. end = p + ce->default_static_members_count;
* Static properties from parent classes will be handled in class_copy_ctor */
p = table + (parent ? parent->default_static_members_count : 0);
end = table + ce->default_static_members_count;
while (p < end) { while (p < end) {
zend_file_cache_serialize_zval(p, script, info, buf); zend_file_cache_serialize_zval(p, script, info, buf);
p++; p++;
@ -1081,6 +1080,10 @@ static void zend_file_cache_unserialize_zval(zval *zv,
zend_file_cache_unserialize_ast(Z_ASTVAL_P(zv), script, buf); zend_file_cache_unserialize_ast(Z_ASTVAL_P(zv), script, buf);
} }
break; break;
case IS_INDIRECT:
/* Used by static properties. */
UNSERIALIZE_PTR(Z_INDIRECT_P(zv));
break;
} }
} }
@ -1325,7 +1328,6 @@ static void zend_file_cache_unserialize_class(zval *zv,
void *buf) void *buf)
{ {
zend_class_entry *ce; zend_class_entry *ce;
zend_class_entry *parent = NULL;
UNSERIALIZE_PTR(Z_PTR_P(zv)); UNSERIALIZE_PTR(Z_PTR_P(zv));
ce = Z_PTR_P(zv); ce = Z_PTR_P(zv);
@ -1336,7 +1338,6 @@ static void zend_file_cache_unserialize_class(zval *zv,
UNSERIALIZE_STR(ce->parent_name); UNSERIALIZE_STR(ce->parent_name);
} else { } else {
UNSERIALIZE_PTR(ce->parent); UNSERIALIZE_PTR(ce->parent);
parent = ce->parent;
} }
} }
zend_file_cache_unserialize_hash(&ce->function_table, zend_file_cache_unserialize_hash(&ce->function_table,
@ -1353,14 +1354,10 @@ static void zend_file_cache_unserialize_class(zval *zv,
} }
} }
if (ce->default_static_members_table) { if (ce->default_static_members_table) {
zval *table, *p, *end; zval *p, *end;
/* Unserialize only static properties in this class.
* Static properties from parent classes will be handled in class_copy_ctor */
UNSERIALIZE_PTR(ce->default_static_members_table); UNSERIALIZE_PTR(ce->default_static_members_table);
table = ce->default_static_members_table; p = ce->default_static_members_table;
p = table + (parent ? parent->default_static_members_count : 0); end = p + ce->default_static_members_count;
end = table + ce->default_static_members_count;
while (p < end) { while (p < end) {
zend_file_cache_unserialize_zval(p, script, buf); zend_file_cache_unserialize_zval(p, script, buf);
p++; p++;