Skip to content

Commit 303104e

Browse files
authored
zend: Define C23 enum zend_class_type (#21241)
Checked for “binary and” comparisons using Coccinelle: @@ struct _zend_class_entry *e; expression x; @@ * (e->type & x) @@ zend_class_entry *e; expression x; @@ * (e->type & x)
1 parent af69d3a commit 303104e

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

Zend/zend.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ struct _zend_inheritance_cache_entry {
144144
zend_class_entry *traits_and_interfaces[1];
145145
};
146146

147+
C23_ENUM(zend_class_type, uint8_t) {
148+
ZEND_INTERNAL_CLASS = 1,
149+
ZEND_USER_CLASS = 2,
150+
};
151+
147152
struct _zend_class_entry {
148-
char type;
153+
zend_class_type type;
149154
zend_string *name;
150155
/* class_entry or string depending on ZEND_ACC_LINKED */
151156
union {

Zend/zend_API.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,8 +4410,7 @@ ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
44104410
/* }}} */
44114411

44124412
static zend_always_inline bool is_persistent_class(const zend_class_entry *ce) {
4413-
return (ce->type & ZEND_INTERNAL_CLASS)
4414-
&& ce->info.internal.module->type == MODULE_PERSISTENT;
4413+
return ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->type == MODULE_PERSISTENT;
44154414
}
44164415

44174416
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) /* {{{ */
@@ -4534,7 +4533,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
45344533
Z_PROP_FLAG_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;
45354534
}
45364535
skip_property_storage:
4537-
if (ce->type & ZEND_INTERNAL_CLASS) {
4536+
if (ce->type == ZEND_INTERNAL_CLASS) {
45384537
/* Must be interned to avoid ZTS data races */
45394538
if (is_persistent_class(ce)) {
45404539
name = zend_new_interned_string(zend_string_copy(name));
@@ -4753,7 +4752,7 @@ ZEND_API void zend_declare_property_string(zend_class_entry *ce, const char *nam
47534752
{
47544753
zval property;
47554754

4756-
ZVAL_NEW_STR(&property, zend_string_init(value, strlen(value), ce->type & ZEND_INTERNAL_CLASS));
4755+
ZVAL_NEW_STR(&property, zend_string_init(value, strlen(value), ce->type == ZEND_INTERNAL_CLASS));
47574756
zend_declare_property(ce, name, name_length, &property, access_type);
47584757
}
47594758
/* }}} */
@@ -4762,7 +4761,7 @@ ZEND_API void zend_declare_property_stringl(zend_class_entry *ce, const char *na
47624761
{
47634762
zval property;
47644763

4765-
ZVAL_NEW_STR(&property, zend_string_init(value, value_len, ce->type & ZEND_INTERNAL_CLASS));
4764+
ZVAL_NEW_STR(&property, zend_string_init(value, value_len, ce->type == ZEND_INTERNAL_CLASS));
47664765
zend_declare_property(ce, name, name_length, &property, access_type);
47674766
}
47684767
/* }}} */
@@ -4876,7 +4875,7 @@ ZEND_API void zend_declare_class_constant_stringl(zend_class_entry *ce, const ch
48764875
{
48774876
zval constant;
48784877

4879-
ZVAL_NEW_STR(&constant, zend_string_init(value, value_length, ce->type & ZEND_INTERNAL_CLASS));
4878+
ZVAL_NEW_STR(&constant, zend_string_init(value, value_length, ce->type == ZEND_INTERNAL_CLASS));
48804879
zend_declare_class_constant(ce, name, name_length, &constant);
48814880
}
48824881
/* }}} */

Zend/zend_compile.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,6 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
10791079

10801080
#define ZEND_USER_CODE(type) ((type) != ZEND_INTERNAL_FUNCTION)
10811081

1082-
#define ZEND_INTERNAL_CLASS 1
1083-
#define ZEND_USER_CLASS 2
1084-
10851082
#define ZEND_EVAL (1<<0)
10861083
#define ZEND_INCLUDE (1<<1)
10871084
#define ZEND_INCLUDE_ONCE (1<<2)

Zend/zend_inheritance.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static zend_function *zend_duplicate_internal_function(const zend_function *func
100100
{
101101
zend_function *new_function;
102102

103-
if (UNEXPECTED(ce->type & ZEND_INTERNAL_CLASS)) {
103+
if (UNEXPECTED(ce->type == ZEND_INTERNAL_CLASS)) {
104104
new_function = (zend_function *)pemalloc(sizeof(zend_internal_function), 1);
105105
memcpy(new_function, func, sizeof(zend_internal_function));
106106
} else {
@@ -1669,7 +1669,7 @@ static void do_inherit_class_constant(zend_string *name, zend_class_constant *pa
16691669
Z_CONSTANT_FLAGS(c->value) |= CONST_OWNED;
16701670
}
16711671
}
1672-
if (ce->type & ZEND_INTERNAL_CLASS) {
1672+
if (ce->type == ZEND_INTERNAL_CLASS) {
16731673
c = pemalloc(sizeof(zend_class_constant), 1);
16741674
memcpy(c, parent_const, sizeof(zend_class_constant));
16751675
parent_const = c;
@@ -2151,7 +2151,7 @@ static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c,
21512151
Z_CONSTANT_FLAGS(c->value) |= CONST_OWNED;
21522152
}
21532153
}
2154-
if (ce->type & ZEND_INTERNAL_CLASS) {
2154+
if (ce->type == ZEND_INTERNAL_CLASS) {
21552155
ct = pemalloc(sizeof(zend_class_constant), 1);
21562156
memcpy(ct, c, sizeof(zend_class_constant));
21572157
c = ct;

ext/standard/var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static int php_var_serialize_get_sleep_props(
940940

941941
priv_name = zend_mangle_property_name(
942942
ZSTR_VAL(ce->name), ZSTR_LEN(ce->name),
943-
ZSTR_VAL(name), ZSTR_LEN(name), ce->type & ZEND_INTERNAL_CLASS);
943+
ZSTR_VAL(name), ZSTR_LEN(name), ce->type == ZEND_INTERNAL_CLASS);
944944
if (php_var_serialize_try_add_sleep_prop(ht, props, priv_name, name, struc) == SUCCESS) {
945945
zend_tmp_string_release(tmp_name);
946946
zend_string_release(priv_name);
@@ -955,7 +955,7 @@ static int php_var_serialize_get_sleep_props(
955955
}
956956

957957
prot_name = zend_mangle_property_name(
958-
"*", 1, ZSTR_VAL(name), ZSTR_LEN(name), ce->type & ZEND_INTERNAL_CLASS);
958+
"*", 1, ZSTR_VAL(name), ZSTR_LEN(name), ce->type == ZEND_INTERNAL_CLASS);
959959
if (php_var_serialize_try_add_sleep_prop(ht, props, prot_name, name, struc) == SUCCESS) {
960960
zend_tmp_string_release(tmp_name);
961961
zend_string_release(prot_name);

0 commit comments

Comments
 (0)