Skip to content

Commit 68b54e7

Browse files
committed
Introduce separate macros for property flag
Also don't set it for static properties -- this is only relevant for instance properties, as static properties have no __set().
1 parent 6bde436 commit 68b54e7

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

Zend/zend_API.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,15 +1263,13 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
12631263

12641264
if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
12651265
do {
1266-
ZVAL_COPY_OR_DUP(dst, src);
1267-
Z_EXTRA_P(dst) = Z_EXTRA_P(src);
1266+
ZVAL_COPY_OR_DUP_PROP(dst, src);
12681267
src++;
12691268
dst++;
12701269
} while (src != end);
12711270
} else {
12721271
do {
1273-
ZVAL_COPY(dst, src);
1274-
Z_EXTRA_P(dst) = Z_EXTRA_P(src);
1272+
ZVAL_COPY_PROP(dst, src);
12751273
src++;
12761274
dst++;
12771275
} while (src != end);
@@ -3685,7 +3683,6 @@ static zend_always_inline zend_bool is_persistent_class(zend_class_entry *ce) {
36853683
ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type) /* {{{ */
36863684
{
36873685
zend_property_info *property_info, *property_info_ptr;
3688-
zval *property_default_ptr;
36893686

36903687
if (ZEND_TYPE_IS_SET(type)) {
36913688
ce->ce_flags |= ZEND_ACC_HAS_TYPE_HINTS;
@@ -3717,7 +3714,7 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name
37173714
property_info->offset = ce->default_static_members_count++;
37183715
ce->default_static_members_table = perealloc(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count, ce->type == ZEND_INTERNAL_CLASS);
37193716
}
3720-
property_default_ptr = &ce->default_static_members_table[property_info->offset];
3717+
ZVAL_COPY_VALUE(&ce->default_static_members_table[property_info->offset], property);
37213718
if (!ZEND_MAP_PTR(ce->static_members_table)) {
37223719
ZEND_ASSERT(ce->type == ZEND_INTERNAL_CLASS);
37233720
if (!EG(current_execute_data)) {
@@ -3728,6 +3725,7 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name
37283725
}
37293726
}
37303727
} else {
3728+
zval *property_default_ptr;
37313729
if ((property_info_ptr = zend_hash_find_ptr(&ce->properties_info, name)) != NULL &&
37323730
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
37333731
property_info->offset = property_info_ptr->offset;
@@ -3749,6 +3747,8 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name
37493747
}
37503748
}
37513749
property_default_ptr = &ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)];
3750+
ZVAL_COPY_VALUE(property_default_ptr, property);
3751+
Z_PROP_FLAG_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;
37523752
}
37533753
if (ce->type & ZEND_INTERNAL_CLASS) {
37543754
switch(Z_TYPE_P(property)) {
@@ -3765,9 +3765,6 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name
37653765
name = zend_new_interned_string(zend_string_copy(name));
37663766
}
37673767

3768-
ZVAL_COPY_VALUE(property_default_ptr, property);
3769-
Z_EXTRA_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;
3770-
37713768
if (access_type & ZEND_ACC_PUBLIC) {
37723769
property_info->name = zend_string_copy(name);
37733770
} else if (access_type & ZEND_ACC_PRIVATE) {

Zend/zend_inheritance.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
11671167
do {
11681168
dst--;
11691169
src--;
1170-
*dst = *src; /* Copy Z_EXTRA as well */
1170+
ZVAL_COPY_VALUE_PROP(dst, src);
11711171
} while (dst != end);
11721172
pefree(src, ce->type == ZEND_INTERNAL_CLASS);
11731173
end = ce->default_properties_table;
@@ -1182,9 +1182,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
11821182
do {
11831183
dst--;
11841184
src--;
1185-
*dst = *src; /* Copy Z_EXTRA as well */
1186-
ZVAL_COPY_OR_DUP(dst, src);
1187-
Z_EXTRA_P(dst) = Z_EXTRA_P(src);
1185+
ZVAL_COPY_OR_DUP_PROP(dst, src);
11881186
if (Z_OPT_TYPE_P(dst) == IS_CONSTANT_AST) {
11891187
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
11901188
}
@@ -1194,8 +1192,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
11941192
do {
11951193
dst--;
11961194
src--;
1197-
ZVAL_COPY(dst, src);
1198-
Z_EXTRA_P(dst) = Z_EXTRA_P(src);
1195+
ZVAL_COPY_PROP(dst, src);
11991196
if (Z_OPT_TYPE_P(dst) == IS_CONSTANT_AST) {
12001197
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
12011198
}

Zend/zend_object_handlers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
836836
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
837837
goto exit;
838838
}
839-
if (Z_EXTRA_P(variable_ptr) == IS_PROP_UNINIT) {
839+
if (Z_PROP_FLAG_P(variable_ptr) == IS_PROP_UNINIT) {
840840
/* Writes to uninitializde typed properties bypass __set(). */
841-
Z_EXTRA_P(variable_ptr) = 0;
841+
Z_PROP_FLAG_P(variable_ptr) = 0;
842842
goto write_std_property;
843843
}
844844
} else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
@@ -1119,7 +1119,7 @@ ZEND_API void zend_std_unset_property(zval *object, zval *member, void **cache_s
11191119
goto exit;
11201120
}
11211121
/* Reset the IS_PROP_UNINIT flag, if it exists. */
1122-
Z_EXTRA_P(slot) = 0;
1122+
Z_PROP_FLAG_P(slot) = 0;
11231123
} else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))
11241124
&& EXPECTED(zobj->properties != NULL)) {
11251125
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {

Zend/zend_objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object,
209209

210210
do {
211211
i_zval_ptr_dtor(dst);
212-
*dst = *src; /* Copy Z_EXTRA as well */
212+
ZVAL_COPY_VALUE_PROP(dst, src);
213213
zval_add_ref(dst);
214214
if (UNEXPECTED(Z_ISREF_P(dst)) &&
215215
(ZEND_DEBUG || ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(dst)))) {

Zend/zend_types.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
593593

594594
#define OBJ_FLAGS(obj) GC_FLAGS(obj)
595595

596-
/* Property flag stores in Z_EXTRA */
597-
#define IS_PROP_UNINIT 1
598-
599596
/* Recursion protection macros must be used only for arrays and objects */
600597
#define GC_IS_RECURSIVE(p) \
601598
(GC_FLAGS(p) & GC_PROTECTED)
@@ -1265,4 +1262,18 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
12651262
} \
12661263
} while (0)
12671264

1265+
/* Properties store a flag distinguishing unset and unintialized properties
1266+
* (both use IS_UNDEF type) in the Z_EXTRA space. As such we also need to copy
1267+
* the Z_EXTRA space when copying property default values etc. We define separate
1268+
* macros for this purpose, so this workaround is easier to remove in the future. */
1269+
#define IS_PROP_UNINIT 1
1270+
#define Z_PROP_FLAG_P(z) Z_EXTRA_P(z)
1271+
#define ZVAL_COPY_VALUE_PROP(z, v) \
1272+
do { *(z) = *(v); } while (0)
1273+
#define ZVAL_COPY_PROP(z, v) \
1274+
do { ZVAL_COPY(z, v); Z_PROP_FLAG_P(z) = Z_PROP_FLAG_P(v); } while (0)
1275+
#define ZVAL_COPY_OR_DUP_PROP(z, v) \
1276+
do { ZVAL_COPY_OR_DUP(z, v); Z_PROP_FLAG_P(z) = Z_PROP_FLAG_P(v); } while (0)
1277+
1278+
12681279
#endif /* ZEND_TYPES_H */

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static void zend_class_copy_ctor(zend_class_entry **pce)
270270
end = src + ce->default_properties_count;
271271
ce->default_properties_table = dst;
272272
for (; src != end; src++, dst++) {
273-
*dst = *src;
273+
ZVAL_COPY_VALUE_PROP(dst, src);
274274
}
275275
}
276276

0 commit comments

Comments
 (0)