Skip to content

Commit a29ae17

Browse files
committed
Try to fix initialization problems
1 parent 7f1aa87 commit a29ae17

File tree

7 files changed

+37
-41
lines changed

7 files changed

+37
-41
lines changed

Zend/zend_API.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
20622062
}
20632063
if (ZEND_TYPE_IS_SET(info->type)) {
20642064
if (ZEND_TYPE_IS_CLASS(info->type)) {
2065-
const char *type_name = info->type.literal_name;
2065+
const char *type_name = ZEND_TYPE_LITERAL_NAME(info->type);
20662066
if (!scope && (!strcasecmp(type_name, "self") || !strcasecmp(type_name, "parent"))) {
20672067
zend_error_noreturn(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", type_name);
20682068
}
@@ -2143,9 +2143,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
21432143
reg_function->common.arg_info = new_arg_info + 1;
21442144
for (i = 0; i < num_args; i++) {
21452145
if (ZEND_TYPE_IS_CLASS(new_arg_info[i].type)) {
2146-
const char *class_name = new_arg_info[i].type.literal_name;
2147-
ZEND_TYPE_NAME(new_arg_info[i].type) =
2148-
zend_string_init_interned(class_name, strlen(class_name), 1);
2146+
const char *class_name = ZEND_TYPE_LITERAL_NAME(new_arg_info[i].type);
2147+
ZEND_TYPE_SET_PTR(new_arg_info[i].type,
2148+
zend_string_init_interned(class_name, strlen(class_name), 1));
21492149
}
21502150
}
21512151
}

Zend/zend_types.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,13 @@ typedef void (*copy_ctor_func_t)(zval *pElement);
120120
* ZEND_TYPE_ENCODE_*() should be used for construction.
121121
*/
122122

123-
/* We could use the extra 32-bit of padding on 64-bit systems. */
124123
typedef struct {
125-
union {
126-
zend_class_entry *ce;
127-
zend_string *name;
128-
const char *literal_name;
129-
};
124+
/* Not using a union here, because there's no good way to initialize them
125+
* in a way that is supported in both C and C++ (designated initializers
126+
* are only supported since C++20). */
127+
void *ptr;
130128
uint32_t type_mask;
129+
/* TODO: We could use the extra 32-bit of padding on 64-bit systems. */
131130
} zend_type;
132131

133132
#define _ZEND_TYPE_MASK ((1u<<(IS_VOID+1))-1)
@@ -152,13 +151,19 @@ typedef struct {
152151
(((t.type_mask) & _ZEND_TYPE_NAME_BIT) != 0)
153152

154153
#define ZEND_TYPE_IS_ONLY_MASK(t) \
155-
((t).type_mask != 0 && (t).ce == NULL)
154+
((t).type_mask != 0 && (t).ptr == NULL)
156155

157156
#define ZEND_TYPE_NAME(t) \
158-
((t).name)
157+
((zend_string *) (t).ptr)
158+
159+
#define ZEND_TYPE_LITERAL_NAME(t) \
160+
((const char *) (t).ptr)
159161

160162
#define ZEND_TYPE_CE(t) \
161-
((t).ce)
163+
((zend_class_entry *) (t).ptr)
164+
165+
#define ZEND_TYPE_SET_PTR(t, _ptr) \
166+
((t).ptr = (_ptr))
162167

163168
#define ZEND_TYPE_MASK(t) \
164169
((t).type_mask)
@@ -173,32 +178,23 @@ typedef struct {
173178
(((t).type_mask & _ZEND_TYPE_NULLABLE_BIT) != 0)
174179

175180
#define ZEND_TYPE_INIT_NONE() \
176-
{ .type_mask = 0 }
181+
{ NULL, 0 }
177182

178183
#define ZEND_TYPE_INIT_MASK(_type_mask) \
179-
{ .type_mask = (_type_mask) }
184+
{ NULL, (_type_mask) }
180185

181186
#define ZEND_TYPE_INIT_CODE(code, allow_null) \
182187
ZEND_TYPE_INIT_MASK(((code) == _IS_BOOL ? (MAY_BE_FALSE|MAY_BE_TRUE) : (1 << (code))) \
183188
| ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0))
184189

185190
#define ZEND_TYPE_INIT_CE(_ce, allow_null) \
186-
{ \
187-
.ce = (_ce), \
188-
.type_mask = _ZEND_TYPE_CE_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) \
189-
}
191+
{ (void *) (_ce), _ZEND_TYPE_CE_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) }
190192

191193
#define ZEND_TYPE_INIT_CLASS(class_name, allow_null) \
192-
{ \
193-
.name = (class_name), \
194-
.type_mask = _ZEND_TYPE_NAME_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) \
195-
}
194+
{ (void *) (class_name), _ZEND_TYPE_NAME_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) }
196195

197196
#define ZEND_TYPE_INIT_CLASS_CONST(class_name, allow_null) \
198-
{ \
199-
.literal_name = (class_name), \
200-
.type_mask = _ZEND_TYPE_NAME_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) \
201-
}
197+
{ (void *) (class_name), _ZEND_TYPE_NAME_BIT | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) }
202198

203199
typedef union _zend_value {
204200
zend_long lval; /* long value */

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
602602
}
603603
for (i = 0 ; i < num_args; i++) {
604604
if (ZEND_TYPE_IS_CLASS(arg_info[i].type)) {
605-
ZEND_TYPE_NAME(arg_info[i].type) =
606-
new_interned_string(ZEND_TYPE_NAME(arg_info[i].type));
605+
ZEND_TYPE_SET_PTR(arg_info[i].type,
606+
new_interned_string(ZEND_TYPE_NAME(arg_info[i].type)));
607607
}
608608
}
609609
}

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static void zend_hash_clone_prop_info(HashTable *ht)
237237
zend_class_entry *ce = ZEND_TYPE_CE(prop_info->type);
238238
if (IN_ARENA(ce)) {
239239
ce = ARENA_REALLOC(ce);
240-
ZEND_TYPE_CE(prop_info->type) = ce;
240+
ZEND_TYPE_SET_PTR(prop_info->type, ce);
241241
}
242242
}
243243
}

ext/opcache/zend_file_cache.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
501501
if (ZEND_TYPE_IS_CLASS(p->type)) {
502502
zend_string *type_name = ZEND_TYPE_NAME(p->type);
503503
SERIALIZE_STR(type_name);
504-
ZEND_TYPE_NAME(p->type) = type_name;
504+
ZEND_TYPE_SET_PTR(p->type, type_name);
505505
}
506506
p++;
507507
}
@@ -575,11 +575,11 @@ static void zend_file_cache_serialize_prop_info(zval *zv,
575575
if (ZEND_TYPE_IS_NAME(prop->type)) {
576576
zend_string *name = ZEND_TYPE_NAME(prop->type);
577577
SERIALIZE_STR(name);
578-
ZEND_TYPE_NAME(prop->type) = name;
578+
ZEND_TYPE_SET_PTR(prop->type, name);
579579
} else if (ZEND_TYPE_IS_CE(prop->type)) {
580580
zend_class_entry *ce = ZEND_TYPE_CE(prop->type);
581581
SERIALIZE_PTR(ce);
582-
ZEND_TYPE_CE(prop->type) = ce;
582+
ZEND_TYPE_SET_PTR(prop->type, ce);
583583
}
584584
}
585585
}
@@ -1198,7 +1198,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
11981198
if (ZEND_TYPE_IS_CLASS(p->type)) {
11991199
zend_string *type_name = ZEND_TYPE_NAME(p->type);
12001200
UNSERIALIZE_STR(type_name);
1201-
ZEND_TYPE_NAME(p->type) = type_name;
1201+
ZEND_TYPE_SET_PTR(p->type, type_name);
12021202
}
12031203
p++;
12041204
}
@@ -1272,11 +1272,11 @@ static void zend_file_cache_unserialize_prop_info(zval *zv,
12721272
if (ZEND_TYPE_IS_NAME(prop->type)) {
12731273
zend_string *name = ZEND_TYPE_NAME(prop->type);
12741274
UNSERIALIZE_STR(name);
1275-
ZEND_TYPE_NAME(prop->type) = name;
1275+
ZEND_TYPE_SET_PTR(prop->type, name);
12761276
} else if (ZEND_TYPE_IS_CE(prop->type)) {
12771277
zend_class_entry *ce = ZEND_TYPE_CE(prop->type);
12781278
UNSERIALIZE_PTR(ce);
1279-
ZEND_TYPE_CE(prop->type) = ce;
1279+
ZEND_TYPE_SET_PTR(prop->type, ce);
12801280
}
12811281
}
12821282
}

ext/opcache/zend_persist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
502502
if (ZEND_TYPE_IS_CLASS(arg_info[i].type)) {
503503
zend_string *type_name = ZEND_TYPE_NAME(arg_info[i].type);
504504
zend_accel_store_interned_string(type_name);
505-
ZEND_TYPE_NAME(arg_info[i].type) = type_name;
505+
ZEND_TYPE_SET_PTR(arg_info[i].type, type_name);
506506
}
507507
}
508508
if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
@@ -662,7 +662,7 @@ static void zend_persist_property_info(zval *zv)
662662
if (ZEND_TYPE_IS_NAME(prop->type)) {
663663
zend_string *class_name = ZEND_TYPE_NAME(prop->type);
664664
zend_accel_store_interned_string(class_name);
665-
ZEND_TYPE_NAME(prop->type) = class_name;
665+
ZEND_TYPE_SET_PTR(prop->type, class_name);
666666
}
667667
}
668668

@@ -942,7 +942,7 @@ static void zend_update_parent_ce(zend_class_entry *ce)
942942
if (ce->type == ZEND_USER_CLASS) {
943943
ce = zend_shared_alloc_get_xlat_entry(ce);
944944
if (ce) {
945-
ZEND_TYPE_CE(prop->type) = ce;
945+
ZEND_TYPE_SET_PTR(prop->type, ce);
946946
}
947947
}
948948
}

ext/opcache/zend_persist_calc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
225225
if (ZEND_TYPE_IS_CLASS(arg_info[i].type)) {
226226
zend_string *type_name = ZEND_TYPE_NAME(arg_info[i].type);
227227
ADD_INTERNED_STRING(type_name);
228-
ZEND_TYPE_NAME(arg_info[i].type) = type_name;
228+
ZEND_TYPE_SET_PTR(arg_info[i].type, type_name);
229229
}
230230
}
231231
}
@@ -305,7 +305,7 @@ static void zend_persist_property_info_calc(zval *zv)
305305
if (ZEND_TYPE_IS_NAME(prop->type)) {
306306
zend_string *class_name = ZEND_TYPE_NAME(prop->type);
307307
ADD_INTERNED_STRING(class_name);
308-
ZEND_TYPE_NAME(prop->type) = class_name;
308+
ZEND_TYPE_SET_PTR(prop->type, class_name);
309309
}
310310
if (ZCG(accel_directives).save_comments && prop->doc_comment) {
311311
ADD_STRING(prop->doc_comment);

0 commit comments

Comments
 (0)