Skip to content

Commit 973c861

Browse files
zend_apply_internal_attribute_validation()
1 parent 59426bc commit 973c861

File tree

3 files changed

+31
-48
lines changed

3 files changed

+31
-48
lines changed

Zend/zend_attributes.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,36 +122,41 @@ void compile_alias_attributes(
122122
}
123123

124124
if (*attributes != NULL) {
125-
/* Validate attributes in a secondary loop (needed to detect repeated attributes). */
126-
ZEND_HASH_PACKED_FOREACH_PTR(*attributes, attr) {
127-
if (attr->offset != 0 || NULL == (config = zend_internal_attribute_get(attr->lcname))) {
128-
continue;
129-
}
125+
zend_apply_internal_attribute_validation(*attributes, 0, ZEND_ATTRIBUTE_TARGET_CLASS_ALIAS);
126+
}
127+
}
128+
/* }}} */
130129

131-
uint32_t target = ZEND_ATTRIBUTE_TARGET_CLASS_ALIAS;
130+
ZEND_API void zend_apply_internal_attribute_validation(HashTable *attributes, uint32_t offset, uint32_t target) {
131+
zend_attribute *attr;
132+
zend_internal_attribute *config;
132133

133-
if (!(target & (config->flags & ZEND_ATTRIBUTE_TARGET_ALL))) {
134-
zend_string *location = zend_get_attribute_target_names(target);
135-
zend_string *allowed = zend_get_attribute_target_names(config->flags);
134+
/* Validate attributes in a secondary loop (needed to detect repeated attributes). */
135+
ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) {
136+
if (attr->offset != offset || NULL == (config = zend_internal_attribute_get(attr->lcname))) {
137+
continue;
138+
}
136139

137-
zend_error_noreturn(E_ERROR, "Attribute \"%s\" cannot target %s (allowed targets: %s)",
138-
ZSTR_VAL(attr->name), ZSTR_VAL(location), ZSTR_VAL(allowed)
139-
);
140-
}
140+
if (!(target & (config->flags & ZEND_ATTRIBUTE_TARGET_ALL))) {
141+
zend_string *location = zend_get_attribute_target_names(target);
142+
zend_string *allowed = zend_get_attribute_target_names(config->flags);
141143

142-
if (!(config->flags & ZEND_ATTRIBUTE_IS_REPEATABLE)) {
143-
if (zend_is_attribute_repeated(*attributes, attr)) {
144-
zend_error_noreturn(E_ERROR, "Attribute \"%s\" must not be repeated", ZSTR_VAL(attr->name));
145-
}
146-
}
144+
zend_error_noreturn(E_ERROR, "Attribute \"%s\" cannot target %s (allowed targets: %s)",
145+
ZSTR_VAL(attr->name), ZSTR_VAL(location), ZSTR_VAL(allowed)
146+
);
147+
}
147148

148-
if (config->validator != NULL) {
149-
config->validator(attr, target, CG(active_class_entry));
149+
if (!(config->flags & ZEND_ATTRIBUTE_IS_REPEATABLE)) {
150+
if (zend_is_attribute_repeated(attributes, attr)) {
151+
zend_error_noreturn(E_ERROR, "Attribute \"%s\" must not be repeated", ZSTR_VAL(attr->name));
150152
}
151-
} ZEND_HASH_FOREACH_END();
152-
}
153+
}
154+
155+
if (config->validator != NULL) {
156+
config->validator(attr, target, CG(active_class_entry));
157+
}
158+
} ZEND_HASH_FOREACH_END();
153159
}
154-
/* }}} */
155160

156161
uint32_t zend_attribute_attribute_get_flags(zend_attribute *attr, zend_class_entry *scope)
157162
{

Zend/zend_attributes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ ZEND_API zend_attribute *zend_add_attribute(
9696

9797
uint32_t zend_attribute_attribute_get_flags(zend_attribute *attr, zend_class_entry *scope);
9898

99+
ZEND_API void zend_apply_internal_attribute_validation(HashTable *attributes, uint32_t offset, uint32_t target);
100+
99101
END_EXTERN_C()
100102

101103
static zend_always_inline zend_attribute *zend_add_class_attribute(zend_class_entry *ce, zend_string *name, uint32_t argc)

Zend/zend_compile.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7468,31 +7468,7 @@ static void zend_compile_attributes(
74687468
}
74697469

74707470
if (*attributes != NULL) {
7471-
/* Validate attributes in a secondary loop (needed to detect repeated attributes). */
7472-
ZEND_HASH_PACKED_FOREACH_PTR(*attributes, attr) {
7473-
if (attr->offset != offset || NULL == (config = zend_internal_attribute_get(attr->lcname))) {
7474-
continue;
7475-
}
7476-
7477-
if (!(target & (config->flags & ZEND_ATTRIBUTE_TARGET_ALL))) {
7478-
zend_string *location = zend_get_attribute_target_names(target);
7479-
zend_string *allowed = zend_get_attribute_target_names(config->flags);
7480-
7481-
zend_error_noreturn(E_ERROR, "Attribute \"%s\" cannot target %s (allowed targets: %s)",
7482-
ZSTR_VAL(attr->name), ZSTR_VAL(location), ZSTR_VAL(allowed)
7483-
);
7484-
}
7485-
7486-
if (!(config->flags & ZEND_ATTRIBUTE_IS_REPEATABLE)) {
7487-
if (zend_is_attribute_repeated(*attributes, attr)) {
7488-
zend_error_noreturn(E_ERROR, "Attribute \"%s\" must not be repeated", ZSTR_VAL(attr->name));
7489-
}
7490-
}
7491-
7492-
if (config->validator != NULL) {
7493-
config->validator(attr, target, CG(active_class_entry));
7494-
}
7495-
} ZEND_HASH_FOREACH_END();
7471+
zend_apply_internal_attribute_validation(*attributes, offset, target);
74967472
}
74977473
}
74987474
/* }}} */

0 commit comments

Comments
 (0)