summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorIlija Tovilo <ilija.tovilo@me.com>2020-06-10 23:10:18 +0200
committerIlija Tovilo <ilija.tovilo@me.com>2021-03-17 19:08:03 +0100
commit269c8dac1d56ee85d71ae94d9b28dd7d8e8de7b7 (patch)
tree810ac41b2157ff4e8063f9696f97e1a9d77837c4 /ext/opcache
parenta6fc427b8c51015c16541c112a26dd06bd75e99e (diff)
downloadphp-git-269c8dac1d56ee85d71ae94d9b28dd7d8e8de7b7.tar.gz
Implement enums
RFC: https://wiki.php.net/rfc/enumerations Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Closes GH-6489.
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/zend_file_cache.c32
-rw-r--r--ext/opcache/zend_persist.c24
-rw-r--r--ext/opcache/zend_persist_calc.c12
3 files changed, 59 insertions, 9 deletions
diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c
index 4c7611d36d..884ee796e0 100644
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@ -637,12 +637,12 @@ static void zend_file_cache_serialize_func(zval *zv,
zend_file_cache_metainfo *info,
void *buf)
{
- zend_op_array *op_array;
-
+ zend_function *func;
SERIALIZE_PTR(Z_PTR_P(zv));
- op_array = Z_PTR_P(zv);
- UNSERIALIZE_PTR(op_array);
- zend_file_cache_serialize_op_array(op_array, script, info, buf);
+ func = Z_PTR_P(zv);
+ UNSERIALIZE_PTR(func);
+ ZEND_ASSERT(func->type == ZEND_USER_FUNCTION);
+ zend_file_cache_serialize_op_array(&func->op_array, script, info, buf);
}
static void zend_file_cache_serialize_prop_info(zval *zv,
@@ -844,6 +844,14 @@ static void zend_file_cache_serialize_class(zval *zv,
}
}
+ if (ce->backed_enum_table) {
+ HashTable *ht;
+ SERIALIZE_PTR(ce->backed_enum_table);
+ ht = ce->backed_enum_table;
+ UNSERIALIZE_PTR(ht);
+ zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
+ }
+
SERIALIZE_PTR(ce->constructor);
SERIALIZE_PTR(ce->destructor);
SERIALIZE_PTR(ce->clone);
@@ -1432,11 +1440,11 @@ static void zend_file_cache_unserialize_func(zval *zv,
zend_persistent_script *script,
void *buf)
{
- zend_op_array *op_array;
-
+ zend_function *func;
UNSERIALIZE_PTR(Z_PTR_P(zv));
- op_array = Z_PTR_P(zv);
- zend_file_cache_unserialize_op_array(op_array, script, buf);
+ func = Z_PTR_P(zv);
+ ZEND_ASSERT(func->type == ZEND_USER_FUNCTION);
+ zend_file_cache_unserialize_op_array(&func->op_array, script, buf);
}
static void zend_file_cache_unserialize_prop_info(zval *zv,
@@ -1615,6 +1623,12 @@ static void zend_file_cache_unserialize_class(zval *zv,
}
}
+ if (ce->backed_enum_table) {
+ UNSERIALIZE_PTR(ce->backed_enum_table);
+ zend_file_cache_unserialize_hash(
+ ce->backed_enum_table, script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
+ }
+
UNSERIALIZE_PTR(ce->constructor);
UNSERIALIZE_PTR(ce->destructor);
UNSERIALIZE_PTR(ce->clone);
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 7ede974618..52d961c428 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -326,6 +326,26 @@ uint32_t zend_accel_get_type_map_ptr(zend_string *type_name, zend_class_entry *s
return ret;
}
+static HashTable *zend_persist_backed_enum_table(HashTable *backed_enum_table)
+{
+ HashTable *ptr;
+ Bucket *p;
+ zend_hash_persist(backed_enum_table);
+
+ ZEND_HASH_FOREACH_BUCKET(backed_enum_table, p) {
+ if (p->key != NULL) {
+ zend_accel_store_interned_string(p->key);
+ }
+ zend_persist_zval(&p->val);
+ } ZEND_HASH_FOREACH_END();
+
+ ptr = zend_shared_memdup_free(backed_enum_table, sizeof(HashTable));
+ GC_SET_REFCOUNT(ptr, 2);
+ GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
+
+ return ptr;
+}
+
static void zend_persist_type(zend_type *type, zend_class_entry *scope) {
if (ZEND_TYPE_HAS_LIST(*type)) {
zend_type_list *list = ZEND_TYPE_LIST(*type);
@@ -1050,6 +1070,10 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
}
}
+
+ if (ce->backed_enum_table) {
+ ce->backed_enum_table = zend_persist_backed_enum_table(ce->backed_enum_table);
+ }
}
return ce;
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index ebd1c61358..c3292ec2a1 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -534,6 +534,18 @@ void zend_persist_class_entry_calc(zend_class_entry *ce)
ADD_SIZE(sizeof(zend_trait_precedence*) * (i + 1));
}
}
+
+ if (ce->backed_enum_table) {
+ Bucket *p;
+ ADD_SIZE(sizeof(HashTable));
+ zend_hash_persist_calc(ce->backed_enum_table);
+ ZEND_HASH_FOREACH_BUCKET(ce->backed_enum_table, p) {
+ if (p->key != NULL) {
+ ADD_INTERNED_STRING(p->key);
+ }
+ zend_persist_zval_calc(&p->val);
+ } ZEND_HASH_FOREACH_END();
+ }
}
}