Skip to content

Avoid refcount copy of props #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,15 +1609,16 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
zval *dst = object->properties_table;
zval *end = src + class_type->default_properties_count;

if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
if (EXPECTED(class_type->ce_flags & ZEND_ACC_HAS_RC_PROPS)) {
do {
ZVAL_COPY_OR_DUP_PROP(dst, src);
ZVAL_COPY_PROP(dst, src);
src++;
dst++;
} while (src != end);
} else {
/* zend_declare_typed_property() disallows refcounted default property values in internal classes */
do {
ZVAL_COPY_PROP(dst, src);
ZVAL_COPY_VALUE_PROP(dst, src);
src++;
dst++;
} while (src != end);
Expand Down Expand Up @@ -4378,6 +4379,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
ce->properties_info_table[ce->default_properties_count - 1] = property_info;
}
}
if (Z_REFCOUNTED_P(property)) {
ce->ce_flags |= ZEND_ACC_HAS_RC_PROPS;
}
property_default_ptr = &ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)];
ZVAL_COPY_VALUE(property_default_ptr, property);
Z_PROP_FLAG_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ typedef struct _zend_oparray_context {
/* or IS_CONSTANT_VISITED_MARK | | | */
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
/* | | | */
/* Class Flags (unused: 30,31) | | | */
/* Class Flags (unused: 31) | | | */
/* =========== | | | */
/* | | | */
/* Special class types | | | */
Expand Down Expand Up @@ -304,6 +304,8 @@ typedef struct _zend_oparray_context {
/* | | | */
/* Class cannot be serialized or unserialized | | | */
#define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
/* Class has refcounted props | | | */
#define ZEND_ACC_HAS_RC_PROPS (1 << 30) /* X | | | */
/* | | | */
/* Function Flags (unused: 29-30) | | | */
/* ============== | | | */
Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
}
}
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);
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);
}
/* }}} */

Expand Down Expand Up @@ -2537,6 +2537,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
}
}
} ZEND_HASH_FOREACH_END();
ce->ce_flags |= traits[i]->ce_flags & ZEND_ACC_HAS_RC_PROPS;
}
}
/* }}} */
Expand Down