Skip to content

Commit a122c8b

Browse files
committed
Implement ZEND_ACC_HAS_RC_PROPS
1 parent 7d551a8 commit a122c8b

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Zend/zend_API.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,15 +1609,17 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
16091609
zval *dst = object->properties_table;
16101610
zval *end = src + class_type->default_properties_count;
16111611

1612-
if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
1612+
if (EXPECTED(class_type->ce_flags & ZEND_ACC_HAS_RC_PROPS)) {
1613+
zval *end = src + class_type->default_properties_count;
16131614
do {
1614-
ZVAL_COPY_OR_DUP_PROP(dst, src);
1615+
ZVAL_COPY_PROP(dst, src);
16151616
src++;
16161617
dst++;
16171618
} while (src != end);
16181619
} else {
1620+
/* zend_declare_typed_property() disallows refcounted default property values in internal classes */
16191621
do {
1620-
ZVAL_COPY_PROP(dst, src);
1622+
ZVAL_COPY_VALUE_PROP(dst, src);
16211623
src++;
16221624
dst++;
16231625
} while (src != end);
@@ -4303,6 +4305,7 @@ static zend_always_inline bool is_persistent_class(zend_class_entry *ce) {
43034305
ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type) /* {{{ */
43044306
{
43054307
zend_property_info *property_info, *property_info_ptr;
4308+
// printf("decl prop %s\n", name->val);
43064309

43074310
if (ZEND_TYPE_IS_SET(type)) {
43084311
ce->ce_flags |= ZEND_ACC_HAS_TYPE_HINTS;
@@ -4378,6 +4381,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43784381
ce->properties_info_table[ce->default_properties_count - 1] = property_info;
43794382
}
43804383
}
4384+
if (Z_REFCOUNTED_P(property)) {
4385+
ce->ce_flags |= ZEND_ACC_HAS_RC_PROPS;
4386+
}
43814387
property_default_ptr = &ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)];
43824388
ZVAL_COPY_VALUE(property_default_ptr, property);
43834389
Z_PROP_FLAG_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;

Zend/zend_compile.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ typedef struct _zend_oparray_context {
239239
/* or IS_CONSTANT_VISITED_MARK | | | */
240240
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
241241
/* | | | */
242-
/* Class Flags (unused: 30,31) | | | */
242+
/* Class Flags (unused: 31) | | | */
243243
/* =========== | | | */
244244
/* | | | */
245245
/* Special class types | | | */
@@ -304,6 +304,8 @@ typedef struct _zend_oparray_context {
304304
/* | | | */
305305
/* Class cannot be serialized or unserialized | | | */
306306
#define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
307+
/* Class has refcounted props | | | */
308+
#define ZEND_ACC_HAS_RC_PROPS (1 << 30) /* X | | | */
307309
/* | | | */
308310
/* Function Flags (unused: 29-30) | | | */
309311
/* ============== | | | */

Zend/zend_inheritance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
16721672
ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
16731673
}
16741674
}
1675-
ce->ce_flags |= parent_ce->ce_flags & (ZEND_HAS_STATIC_IN_METHODS | ZEND_ACC_HAS_TYPE_HINTS | ZEND_ACC_HAS_READONLY_PROPS | ZEND_ACC_USE_GUARDS | ZEND_ACC_NOT_SERIALIZABLE | ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES);
1675+
ce->ce_flags |= parent_ce->ce_flags & (ZEND_HAS_STATIC_IN_METHODS | ZEND_ACC_HAS_TYPE_HINTS | ZEND_ACC_HAS_READONLY_PROPS | ZEND_ACC_USE_GUARDS | ZEND_ACC_NOT_SERIALIZABLE | ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES | ZEND_ACC_HAS_RC_PROPS);
16761676
}
16771677
/* }}} */
16781678

@@ -2537,6 +2537,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
25372537
}
25382538
}
25392539
} ZEND_HASH_FOREACH_END();
2540+
ce->ce_flags |= traits[i]->ce_flags & ZEND_ACC_HAS_RC_PROPS;
25402541
}
25412542
}
25422543
/* }}} */

ext/standard/array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6470,14 +6470,14 @@ PHP_FUNCTION(array_map)
64706470
array_init_size(return_value, maxlen);
64716471
zend_hash_real_init(Z_ARRVAL_P(return_value), HT_IS_PACKED(Z_ARRVAL(arrays[0])));
64726472

6473-
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) {
6474-
fci.retval = &result;
6475-
fci.param_count = 1;
6476-
fci.params = &arg;
6473+
fci.retval = &result;
6474+
fci.param_count = 1;
6475+
fci.params = &arg;
64776476

6477+
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) {
64786478
ZVAL_COPY(&arg, zv);
64796479
ret = zend_call_function(&fci, &fci_cache);
6480-
i_zval_ptr_dtor(&arg);
6480+
Z_TRY_DELREF(arg); /* hash table still holds a reference, no dtor check is necessary */
64816481
if (ret != SUCCESS || Z_TYPE(result) == IS_UNDEF) {
64826482
zend_array_destroy(Z_ARR_P(return_value));
64836483
RETURN_NULL();

0 commit comments

Comments
 (0)