Add ZEND_CLASS_CONST_FLAGS() macro

And drop Z_ACCESS_FLAGS(). We no longer store *only* access flags
in these.
This commit is contained in:
Nikita Popov 2021-04-28 14:51:54 +02:00
parent 88ce1c71b5
commit fd1d5ec2b4
12 changed files with 40 additions and 39 deletions

View File

@ -268,7 +268,7 @@ constant_binary_op:
if ((cc = zend_hash_find_ptr(&ce->constants_table,
Z_STR(ZEND_OP2_LITERAL(opline)))) != NULL &&
(Z_ACCESS_FLAGS(cc->value) & ZEND_ACC_PPP_MASK) == ZEND_ACC_PUBLIC) {
(ZEND_CLASS_CONST_FLAGS(cc) & ZEND_ACC_PPP_MASK) == ZEND_ACC_PUBLIC) {
c = &cc->value;
if (Z_TYPE_P(c) == IS_CONSTANT_AST) {
zend_ast *ast = Z_ASTVAL_P(c);

View File

@ -4326,7 +4326,7 @@ ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *c
c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
}
ZVAL_COPY_VALUE(&c->value, value);
Z_ACCESS_FLAGS(c->value) = access_type;
ZEND_CLASS_CONST_FLAGS(c) = access_type;
c->doc_comment = doc_comment;
c->attributes = NULL;
c->ce = ce;

View File

@ -1651,9 +1651,9 @@ static bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *c
/* We don't use zend_verify_const_access because we need to deal with unlinked classes. */
static bool zend_verify_ct_const_access(zend_class_constant *c, zend_class_entry *scope)
{
if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PUBLIC) {
if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PUBLIC) {
return 1;
} else if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PRIVATE) {
} else if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PRIVATE) {
return c->ce == scope;
} else {
zend_class_entry *ce = c->ce;
@ -7759,7 +7759,7 @@ static void zend_compile_enum_case(zend_ast *ast)
zval value_zv;
zend_const_expr_to_zval(&value_zv, &const_enum_init_ast);
zend_class_constant *c = zend_declare_class_constant_ex(enum_class, enum_case_name, &value_zv, ZEND_ACC_PUBLIC, NULL);
Z_ACCESS_FLAGS(c->value) |= ZEND_CLASS_CONST_IS_CASE;
ZEND_CLASS_CONST_FLAGS(c) |= ZEND_CLASS_CONST_IS_CASE;
zend_ast_destroy(const_enum_init_ast);
zend_ast *attr_ast = ast->child[2];

View File

@ -234,10 +234,13 @@ typedef struct _zend_oparray_context {
#define ZEND_ACC_PRELOADED (1 << 10) /* X | X | | */
/* | | | */
/* Flag to differentiate cases from constants. | | | */
/* Stored in Z_ACCESS_FLAGS, must not conflict with | | | */
/* ZEND_ACC_ visibility flags or IS_CONSTANT_VISITED_MARK | | | */
/* Must not conflict with ZEND_ACC_ visibility flags | | | */
/* or IS_CONSTANT_VISITED_MARK | | | */
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
/* | | | */
/* Class constant is deprecated | | | */
#define ZEND_CLASS_CONST_DEPRECATED (1 << 7) /* | | | X */
/* | | | */
/* Class Flags (unused: 29...) | | | */
/* =========== | | | */
/* | | | */
@ -393,12 +396,14 @@ typedef struct _zend_property_info {
((offset - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
typedef struct _zend_class_constant {
zval value; /* access flags and other constant flags are stored in reserved: zval.u2.access_flags */
zval value; /* flags are stored in u2 */
zend_string *doc_comment;
HashTable *attributes;
zend_class_entry *ce;
} zend_class_constant;
#define ZEND_CLASS_CONST_FLAGS(c) Z_CONSTANT_FLAGS((c)->value)
/* arg_info for internal functions */
typedef struct _zend_internal_arg_info {
const char *name;

View File

@ -29,9 +29,9 @@
/* Protection from recursive self-referencing class constants */
#define IS_CONSTANT_VISITED_MARK 0x80
#define IS_CONSTANT_VISITED(zv) (Z_ACCESS_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
#define MARK_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
#define RESET_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
#define IS_CONSTANT_VISITED(zv) (Z_CONSTANT_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
#define MARK_CONSTANT_VISITED(zv) Z_CONSTANT_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
#define RESET_CONSTANT_VISITED(zv) Z_CONSTANT_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
/* Use for special null/true/false constants. */
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) /*
ZEND_API bool zend_verify_const_access(zend_class_constant *c, zend_class_entry *scope) /* {{{ */
{
if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PUBLIC) {
if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PUBLIC) {
return 1;
} else if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PRIVATE) {
} else if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PRIVATE) {
return (c->ce == scope);
} else {
ZEND_ASSERT(Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PROTECTED);
ZEND_ASSERT(ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PROTECTED);
return zend_check_protected(c->ce, scope);
}
}
@ -371,7 +371,7 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
} else {
if (!zend_verify_const_access(c, scope)) {
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
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));
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));
}
goto failure;
}
@ -467,7 +467,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
} else {
if (!zend_verify_const_access(c, scope)) {
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
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));
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));
}
goto failure;
}

View File

@ -226,7 +226,7 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func)
array_init(return_value);
ZEND_HASH_FOREACH_PTR(CE_CONSTANTS_TABLE(ce), c) {
if (!(Z_ACCESS_FLAGS(c->value) & ZEND_CLASS_CONST_IS_CASE)) {
if (!(ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE)) {
continue;
}
zval *zv = &c->value;

View File

@ -1178,11 +1178,11 @@ static void do_inherit_class_constant(zend_string *name, zend_class_constant *pa
if (zv != NULL) {
c = (zend_class_constant*)Z_PTR_P(zv);
if (UNEXPECTED((Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PPP_MASK) > (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PPP_MASK))) {
if (UNEXPECTED((ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PPP_MASK) > (ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PPP_MASK))) {
zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::%s must be %s (as in class %s)%s",
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");
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");
}
} else if (!(Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PRIVATE)) {
} else if (!(ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PRIVATE)) {
if (Z_TYPE(parent_const->value) == IS_CONSTANT_AST) {
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;

View File

@ -324,7 +324,6 @@ struct _zval_struct {
uint32_t num_args; /* arguments number for EX(This) */
uint32_t fe_pos; /* foreach position */
uint32_t fe_iter_idx; /* foreach iterator index */
uint32_t access_flags; /* class constant access flags */
uint32_t property_guard; /* single property guard */
uint32_t constant_flags; /* constant flags */
uint32_t extra; /* not further specified */
@ -588,9 +587,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define Z_FE_ITER(zval) (zval).u2.fe_iter_idx
#define Z_FE_ITER_P(zval_p) Z_FE_ITER(*(zval_p))
#define Z_ACCESS_FLAGS(zval) (zval).u2.access_flags
#define Z_ACCESS_FLAGS_P(zval_p) Z_ACCESS_FLAGS(*(zval_p))
#define Z_PROPERTY_GUARD(zval) (zval).u2.property_guard
#define Z_PROPERTY_GUARD_P(zval_p) Z_PROPERTY_GUARD(*(zval_p))

View File

@ -5832,7 +5832,7 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
c = Z_PTR_P(zv);
scope = EX(func)->op_array.scope;
if (!zend_verify_const_access(c, scope)) {
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)));
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)));
ZVAL_UNDEF(EX_VAR(opline->result.var));
HANDLE_EXCEPTION();
}

View File

@ -7023,7 +7023,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_CONS
c = Z_PTR_P(zv);
scope = EX(func)->op_array.scope;
if (!zend_verify_const_access(c, scope)) {
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)));
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)));
ZVAL_UNDEF(EX_VAR(opline->result.var));
HANDLE_EXCEPTION();
}
@ -24332,7 +24332,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_VAR_
c = Z_PTR_P(zv);
scope = EX(func)->op_array.scope;
if (!zend_verify_const_access(c, scope)) {
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)));
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)));
ZVAL_UNDEF(EX_VAR(opline->result.var));
HANDLE_EXCEPTION();
}
@ -32755,7 +32755,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_UNUS
c = Z_PTR_P(zv);
scope = EX(func)->op_array.scope;
if (!zend_verify_const_access(c, scope)) {
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)));
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)));
ZVAL_UNDEF(EX_VAR(opline->result.var));
HANDLE_EXCEPTION();
}

View File

@ -569,7 +569,7 @@ static void _const_string(smart_str *str, char *name, zval *value, char *indent)
/* {{{ _class_const_string */
static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char *indent)
{
char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value));
char *visibility = zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c));
const char *type;
if (zval_update_constant_ex(&c->value, c->ce) == FAILURE) {
@ -3666,7 +3666,7 @@ static void _class_constant_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /
RETURN_THROWS();
}
GET_REFLECTION_OBJECT_PTR(ref);
RETURN_BOOL(Z_ACCESS_FLAGS(ref->value) & mask);
RETURN_BOOL(ZEND_CLASS_CONST_FLAGS(ref) & mask);
}
/* }}} */
@ -3702,7 +3702,7 @@ ZEND_METHOD(ReflectionClassConstant, getModifiers)
}
GET_REFLECTION_OBJECT_PTR(ref);
RETURN_LONG(Z_ACCESS_FLAGS(ref->value));
RETURN_LONG(ZEND_CLASS_CONST_FLAGS(ref));
}
/* }}} */
@ -3777,7 +3777,7 @@ ZEND_METHOD(ReflectionClassConstant, isEnumCase)
GET_REFLECTION_OBJECT_PTR(ref);
RETURN_BOOL(Z_ACCESS_FLAGS(ref->value) & ZEND_CLASS_CONST_IS_CASE);
RETURN_BOOL(ZEND_CLASS_CONST_FLAGS(ref) & ZEND_CLASS_CONST_IS_CASE);
}
/* {{{ reflection_class_object_ctor */
@ -4525,7 +4525,7 @@ ZEND_METHOD(ReflectionClass, getConstants)
RETURN_THROWS();
}
if (Z_ACCESS_FLAGS(constant->value) & filter) {
if (ZEND_CLASS_CONST_FLAGS(constant) & filter) {
ZVAL_COPY_OR_DUP(&val, &constant->value);
zend_hash_add_new(Z_ARRVAL_P(return_value), key, &val);
}
@ -4555,7 +4555,7 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants)
array_init(return_value);
ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) {
if (Z_ACCESS_FLAGS(constant->value) & filter) {
if (ZEND_CLASS_CONST_FLAGS(constant) & filter) {
zval class_const;
reflection_class_constant_factory(name, constant, &class_const);
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &class_const);
@ -6595,7 +6595,7 @@ ZEND_METHOD(ReflectionEnum, hasCase)
RETURN_FALSE;
}
RETURN_BOOL(Z_ACCESS_FLAGS(class_const->value) & ZEND_CLASS_CONST_IS_CASE);
RETURN_BOOL(ZEND_CLASS_CONST_FLAGS(class_const) & ZEND_CLASS_CONST_IS_CASE);
}
ZEND_METHOD(ReflectionEnum, getCase)
@ -6615,7 +6615,7 @@ ZEND_METHOD(ReflectionEnum, getCase)
zend_throw_exception_ex(reflection_exception_ptr, 0, "Case %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
RETURN_THROWS();
}
if (!(Z_ACCESS_FLAGS(constant->value) & ZEND_CLASS_CONST_IS_CASE)) {
if (!(ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE)) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "%s::%s is not a case", ZSTR_VAL(ce->name), ZSTR_VAL(name));
RETURN_THROWS();
}
@ -6638,7 +6638,7 @@ ZEND_METHOD(ReflectionEnum, getCases)
array_init(return_value);
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) {
if (Z_ACCESS_FLAGS(constant->value) & ZEND_CLASS_CONST_IS_CASE) {
if (ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE) {
zval class_const;
reflection_enum_case_factory(ce, name, constant, &class_const);
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &class_const);
@ -6690,7 +6690,7 @@ ZEND_METHOD(ReflectionEnumUnitCase, __construct)
GET_REFLECTION_OBJECT_PTR(ref);
if (!(Z_ACCESS_FLAGS(ref->value) & ZEND_CLASS_CONST_IS_CASE)) {
if (!(ZEND_CLASS_CONST_FLAGS(ref) & ZEND_CLASS_CONST_IS_CASE)) {
zval *case_name = reflection_prop_name(ZEND_THIS);
zend_throw_exception_ex(reflection_exception_ptr, 0, "Constant %s::%s is not a case", ZSTR_VAL(ref->ce->name), Z_STRVAL_P(case_name));
RETURN_THROWS();

View File

@ -1373,7 +1373,7 @@ object ":" uiv ":" ["] {
goto fail;
}
if (!(Z_ACCESS_FLAGS(c->value) & ZEND_CLASS_CONST_IS_CASE)) {
if (!(ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE)) {
php_error_docref(NULL, E_WARNING, "%s::%s is not an enum case", ZSTR_VAL(enum_name), ZSTR_VAL(case_name));
goto fail;
}