From: Nikita Popov Date: Wed, 17 Mar 2021 10:51:23 +0000 (+0100) Subject: Simplify attribute persistence X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cff8c10a9b41a48363c71e0297710cfbddcecad;p=php Simplify attribute persistence For an inherited op_array, directly fetch the xlat entry, as we do for everything else. --- diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 216b6a1eb0..1e41097901 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -259,40 +259,35 @@ static void zend_persist_zval(zval *z) static HashTable *zend_persist_attributes(HashTable *attributes) { - HashTable *ptr = zend_shared_alloc_get_xlat_entry(attributes); - - if (!ptr) { - uint32_t i; - zval *v; + uint32_t i; + zval *v; - if (!ZCG(current_persistent_script)->corrupted - && zend_accel_in_shm(attributes)) { - return attributes; - } + if (!ZCG(current_persistent_script)->corrupted && zend_accel_in_shm(attributes)) { + return attributes; + } - zend_hash_persist(attributes); + zend_hash_persist(attributes); - ZEND_HASH_FOREACH_VAL(attributes, v) { - zend_attribute *attr = Z_PTR_P(v); - zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc)); + ZEND_HASH_FOREACH_VAL(attributes, v) { + zend_attribute *attr = Z_PTR_P(v); + zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc)); - zend_accel_store_interned_string(copy->name); - zend_accel_store_interned_string(copy->lcname); + zend_accel_store_interned_string(copy->name); + zend_accel_store_interned_string(copy->lcname); - for (i = 0; i < copy->argc; i++) { - if (copy->args[i].name) { - zend_accel_store_interned_string(copy->args[i].name); - } - zend_persist_zval(©->args[i].value); + for (i = 0; i < copy->argc; i++) { + if (copy->args[i].name) { + zend_accel_store_interned_string(copy->args[i].name); } + zend_persist_zval(©->args[i].value); + } - ZVAL_PTR(v, copy); - } ZEND_HASH_FOREACH_END(); + ZVAL_PTR(v, copy); + } ZEND_HASH_FOREACH_END(); - ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable)); - GC_SET_REFCOUNT(ptr, 2); - GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT); - } + HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable)); + GC_SET_REFCOUNT(ptr, 2); + GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT); return ptr; } @@ -450,7 +445,8 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc } } if (op_array->attributes) { - op_array->attributes = zend_persist_attributes(op_array->attributes); + op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes); + ZEND_ASSERT(op_array->attributes != NULL); } if (op_array->try_catch_array) {