Skip to content

Commit fd1d5ec

Browse files
committed
Add ZEND_CLASS_CONST_FLAGS() macro
And drop Z_ACCESS_FLAGS(). We no longer store *only* access flags in these.
1 parent 88ce1c7 commit fd1d5ec

File tree

12 files changed

+40
-39
lines changed

12 files changed

+40
-39
lines changed

Zend/Optimizer/pass1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
268268

269269
if ((cc = zend_hash_find_ptr(&ce->constants_table,
270270
Z_STR(ZEND_OP2_LITERAL(opline)))) != NULL &&
271-
(Z_ACCESS_FLAGS(cc->value) & ZEND_ACC_PPP_MASK) == ZEND_ACC_PUBLIC) {
271+
(ZEND_CLASS_CONST_FLAGS(cc) & ZEND_ACC_PPP_MASK) == ZEND_ACC_PUBLIC) {
272272
c = &cc->value;
273273
if (Z_TYPE_P(c) == IS_CONSTANT_AST) {
274274
zend_ast *ast = Z_ASTVAL_P(c);

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *c
43264326
c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
43274327
}
43284328
ZVAL_COPY_VALUE(&c->value, value);
4329-
Z_ACCESS_FLAGS(c->value) = access_type;
4329+
ZEND_CLASS_CONST_FLAGS(c) = access_type;
43304330
c->doc_comment = doc_comment;
43314331
c->attributes = NULL;
43324332
c->ce = ce;

Zend/zend_compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,9 @@ static bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *c
16511651
/* We don't use zend_verify_const_access because we need to deal with unlinked classes. */
16521652
static bool zend_verify_ct_const_access(zend_class_constant *c, zend_class_entry *scope)
16531653
{
1654-
if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PUBLIC) {
1654+
if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PUBLIC) {
16551655
return 1;
1656-
} else if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PRIVATE) {
1656+
} else if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PRIVATE) {
16571657
return c->ce == scope;
16581658
} else {
16591659
zend_class_entry *ce = c->ce;
@@ -7759,7 +7759,7 @@ static void zend_compile_enum_case(zend_ast *ast)
77597759
zval value_zv;
77607760
zend_const_expr_to_zval(&value_zv, &const_enum_init_ast);
77617761
zend_class_constant *c = zend_declare_class_constant_ex(enum_class, enum_case_name, &value_zv, ZEND_ACC_PUBLIC, NULL);
7762-
Z_ACCESS_FLAGS(c->value) |= ZEND_CLASS_CONST_IS_CASE;
7762+
ZEND_CLASS_CONST_FLAGS(c) |= ZEND_CLASS_CONST_IS_CASE;
77637763
zend_ast_destroy(const_enum_init_ast);
77647764

77657765
zend_ast *attr_ast = ast->child[2];

Zend/zend_compile.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ typedef struct _zend_oparray_context {
234234
#define ZEND_ACC_PRELOADED (1 << 10) /* X | X | | */
235235
/* | | | */
236236
/* Flag to differentiate cases from constants. | | | */
237-
/* Stored in Z_ACCESS_FLAGS, must not conflict with | | | */
238-
/* ZEND_ACC_ visibility flags or IS_CONSTANT_VISITED_MARK | | | */
237+
/* Must not conflict with ZEND_ACC_ visibility flags | | | */
238+
/* or IS_CONSTANT_VISITED_MARK | | | */
239239
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
240240
/* | | | */
241+
/* Class constant is deprecated | | | */
242+
#define ZEND_CLASS_CONST_DEPRECATED (1 << 7) /* | | | X */
243+
/* | | | */
241244
/* Class Flags (unused: 29...) | | | */
242245
/* =========== | | | */
243246
/* | | | */
@@ -393,12 +396,14 @@ typedef struct _zend_property_info {
393396
((offset - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
394397

395398
typedef struct _zend_class_constant {
396-
zval value; /* access flags and other constant flags are stored in reserved: zval.u2.access_flags */
399+
zval value; /* flags are stored in u2 */
397400
zend_string *doc_comment;
398401
HashTable *attributes;
399402
zend_class_entry *ce;
400403
} zend_class_constant;
401404

405+
#define ZEND_CLASS_CONST_FLAGS(c) Z_CONSTANT_FLAGS((c)->value)
406+
402407
/* arg_info for internal functions */
403408
typedef struct _zend_internal_arg_info {
404409
const char *name;

Zend/zend_constants.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
/* Protection from recursive self-referencing class constants */
3030
#define IS_CONSTANT_VISITED_MARK 0x80
3131

32-
#define IS_CONSTANT_VISITED(zv) (Z_ACCESS_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
33-
#define MARK_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
34-
#define RESET_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
32+
#define IS_CONSTANT_VISITED(zv) (Z_CONSTANT_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
33+
#define MARK_CONSTANT_VISITED(zv) Z_CONSTANT_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
34+
#define RESET_CONSTANT_VISITED(zv) Z_CONSTANT_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
3535

3636
/* Use for special null/true/false constants. */
3737
static zend_constant *null_const, *true_const, *false_const;
@@ -265,12 +265,12 @@ ZEND_API zend_constant *_zend_get_special_const(const char *name, size_t len) /*
265265

266266
ZEND_API bool zend_verify_const_access(zend_class_constant *c, zend_class_entry *scope) /* {{{ */
267267
{
268-
if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PUBLIC) {
268+
if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PUBLIC) {
269269
return 1;
270-
} else if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PRIVATE) {
270+
} else if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PRIVATE) {
271271
return (c->ce == scope);
272272
} else {
273-
ZEND_ASSERT(Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PROTECTED);
273+
ZEND_ASSERT(ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PROTECTED);
274274
return zend_check_protected(c->ce, scope);
275275
}
276276
}
@@ -371,7 +371,7 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
371371
} else {
372372
if (!zend_verify_const_access(c, scope)) {
373373
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
374-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
374+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
375375
}
376376
goto failure;
377377
}
@@ -467,7 +467,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
467467
} else {
468468
if (!zend_verify_const_access(c, scope)) {
469469
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
470-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
470+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
471471
}
472472
goto failure;
473473
}

Zend/zend_enum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func)
226226
array_init(return_value);
227227

228228
ZEND_HASH_FOREACH_PTR(CE_CONSTANTS_TABLE(ce), c) {
229-
if (!(Z_ACCESS_FLAGS(c->value) & ZEND_CLASS_CONST_IS_CASE)) {
229+
if (!(ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE)) {
230230
continue;
231231
}
232232
zval *zv = &c->value;

Zend/zend_inheritance.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,11 +1178,11 @@ static void do_inherit_class_constant(zend_string *name, zend_class_constant *pa
11781178

11791179
if (zv != NULL) {
11801180
c = (zend_class_constant*)Z_PTR_P(zv);
1181-
if (UNEXPECTED((Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PPP_MASK) > (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PPP_MASK))) {
1181+
if (UNEXPECTED((ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PPP_MASK) > (ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PPP_MASK))) {
11821182
zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::%s must be %s (as in class %s)%s",
1183-
ZSTR_VAL(ce->name), ZSTR_VAL(name), zend_visibility_string(Z_ACCESS_FLAGS(parent_const->value)), ZSTR_VAL(parent_const->ce->name), (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PUBLIC) ? "" : " or weaker");
1183+
ZSTR_VAL(ce->name), ZSTR_VAL(name), zend_visibility_string(ZEND_CLASS_CONST_FLAGS(parent_const)), ZSTR_VAL(parent_const->ce->name), (ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PUBLIC) ? "" : " or weaker");
11841184
}
1185-
} else if (!(Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PRIVATE)) {
1185+
} else if (!(ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PRIVATE)) {
11861186
if (Z_TYPE(parent_const->value) == IS_CONSTANT_AST) {
11871187
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
11881188
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;

Zend/zend_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ struct _zval_struct {
324324
uint32_t num_args; /* arguments number for EX(This) */
325325
uint32_t fe_pos; /* foreach position */
326326
uint32_t fe_iter_idx; /* foreach iterator index */
327-
uint32_t access_flags; /* class constant access flags */
328327
uint32_t property_guard; /* single property guard */
329328
uint32_t constant_flags; /* constant flags */
330329
uint32_t extra; /* not further specified */
@@ -588,9 +587,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
588587
#define Z_FE_ITER(zval) (zval).u2.fe_iter_idx
589588
#define Z_FE_ITER_P(zval_p) Z_FE_ITER(*(zval_p))
590589

591-
#define Z_ACCESS_FLAGS(zval) (zval).u2.access_flags
592-
#define Z_ACCESS_FLAGS_P(zval_p) Z_ACCESS_FLAGS(*(zval_p))
593-
594590
#define Z_PROPERTY_GUARD(zval) (zval).u2.property_guard
595591
#define Z_PROPERTY_GUARD_P(zval_p) Z_PROPERTY_GUARD(*(zval_p))
596592

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5832,7 +5832,7 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
58325832
c = Z_PTR_P(zv);
58335833
scope = EX(func)->op_array.scope;
58345834
if (!zend_verify_const_access(c, scope)) {
5835-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
5835+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
58365836
ZVAL_UNDEF(EX_VAR(opline->result.var));
58375837
HANDLE_EXCEPTION();
58385838
}

Zend/zend_vm_execute.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7023,7 +7023,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_CONS
70237023
c = Z_PTR_P(zv);
70247024
scope = EX(func)->op_array.scope;
70257025
if (!zend_verify_const_access(c, scope)) {
7026-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
7026+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
70277027
ZVAL_UNDEF(EX_VAR(opline->result.var));
70287028
HANDLE_EXCEPTION();
70297029
}
@@ -24332,7 +24332,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_VAR_
2433224332
c = Z_PTR_P(zv);
2433324333
scope = EX(func)->op_array.scope;
2433424334
if (!zend_verify_const_access(c, scope)) {
24335-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
24335+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
2433624336
ZVAL_UNDEF(EX_VAR(opline->result.var));
2433724337
HANDLE_EXCEPTION();
2433824338
}
@@ -32755,7 +32755,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_UNUS
3275532755
c = Z_PTR_P(zv);
3275632756
scope = EX(func)->op_array.scope;
3275732757
if (!zend_verify_const_access(c, scope)) {
32758-
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
32758+
zend_throw_error(NULL, "Cannot access %s constant %s::%s", zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)), ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
3275932759
ZVAL_UNDEF(EX_VAR(opline->result.var));
3276032760
HANDLE_EXCEPTION();
3276132761
}

0 commit comments

Comments
 (0)