Skip to content

Commit 9b228ec

Browse files
committed
Address review comments.
1 parent 4cc905c commit 9b228ec

13 files changed

+62
-58
lines changed

Zend/tests/attributes/004_name_resolution.phpt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ namespace Doctrine\ORM\Mapping {
1515
}
1616
}
1717

18+
namespace Doctrine\ORM\Attributes {
19+
class Table {
20+
}
21+
}
22+
1823
namespace Foo {
1924
use Doctrine\ORM\Mapping\Entity;
2025
use Doctrine\ORM\Mapping as ORM;
26+
use Doctrine\ORM\Attributes;
2127

2228
<<Entity("imported class")>>
2329
<<ORM\Entity("imported namespace")>>
2430
<<\Doctrine\ORM\Mapping\Entity("absolute from namespace")>>
2531
<<\Entity("import absolute from global")>>
32+
<<Attributes\Table()>>
2633
function foo() {
2734
}
2835
}
@@ -34,7 +41,7 @@ namespace {
3441
}
3542
?>
3643
--EXPECTF--
37-
array(4) {
44+
array(5) {
3845
[0]=>
3946
array(2) {
4047
["name"]=>
@@ -75,4 +82,12 @@ array(4) {
7582
string(27) "import absolute from global"
7683
}
7784
}
85+
[4]=>
86+
array(2) {
87+
["name"]=>
88+
string(29) "Doctrine\ORM\Attributes\Table"
89+
["args"]=>
90+
array(0) {
91+
}
92+
}
7893
}

Zend/tests/attributes/006_filter.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ Array
107107
)
108108

109109
string(7) "ERROR 1"
110-
string(39) "Invalid attribute filter flag specified"
110+
string(103) "ReflectionFunctionAbstract::getAttributes(): Argument #2 ($flags) must be a valid attribute filter flag"
111111
string(7) "ERROR 2"
112112
string(34) "Class 'SomeMissingClass' not found"

Zend/tests/attributes/012-ast-export.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ assert(0 && ($a = function () {
2121

2222
?>
2323
--EXPECTF--
24-
Warning: assert(): assert(0 && ($a = <<A1>> <<A2>> function ($a, <<A3(1)>> $b) {
24+
Warning: assert(): assert(0 && ($a = <<A1>>
25+
<<A2>>
26+
function ($a, <<A3(1)>> $b) {
2527
})) failed in %s on line %d
2628

27-
Warning: assert(): assert(0 && ($a = <<A1(1, 2, 1 + 2)>> fn() => 1)) failed in %s on line %d
29+
Warning: assert(): assert(0 && ($a = <<A1(1, 2, 1 + 2)>>
30+
fn() => 1)) failed in %s on line %d
2831

2932
Warning: assert(): assert(0 && ($a = new <<A1>> class {
3033
<<A1>>
3134
<<A2>>
3235
const FOO = 'foo';
3336
<<A2>>
3437
public $x;
35-
<<A3>>
36-
public function a() {
38+
<<A3>> public function a() {
3739
}
3840

3941
})) failed in %s on line %d

Zend/tests/attributes/013_scope_resolution.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class C1
88
{
99
<<A1(self::class, self::FOO)>>
1010
private const FOO = 'foo';
11-
11+
1212
<<A1(self::class, self::FOO)>>
1313
public $a;
14-
14+
1515
<<A1(self::class, self::FOO)>>
1616
public function bar(<<A1(self::class, self::FOO)>> $p) { }
1717
}
@@ -28,7 +28,7 @@ echo "\n";
2828
class C2
2929
{
3030
private const FOO = 'foo';
31-
31+
3232
public static function foo()
3333
{
3434
return <<A1(self::class, self::FOO)>> function (<<A1(self::class, self::FOO)>> $p) { };
@@ -44,12 +44,12 @@ echo "\n";
4444
class C3
4545
{
4646
private const FOO = 'foo';
47-
47+
4848
public static function foo()
4949
{
5050
return new <<A1(self::class, self::FOO)>> class() {
5151
private const FOO = 'bar';
52-
52+
5353
<<A1(self::class, self::FOO)>>
5454
public function bar() { }
5555
};

Zend/zend_API.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,6 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
25882588
zend_initialize_class_data(class_entry, 0);
25892589
class_entry->ce_flags = ce_flags | ZEND_ACC_CONSTANTS_UPDATED | ZEND_ACC_LINKED | ZEND_ACC_RESOLVED_PARENT | ZEND_ACC_RESOLVED_INTERFACES;
25902590
class_entry->info.internal.module = EG(current_module);
2591-
class_entry->attributes = NULL;
25922591

25932592
if (class_entry->info.internal.builtin_functions) {
25942593
zend_register_functions(class_entry, class_entry->info.internal.builtin_functions, &class_entry->function_table, EG(current_module)->type);

Zend/zend_ast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ static ZEND_COLD void zend_ast_export_attributes(smart_str *str, zend_ast *ast,
13251325
zend_ast *attr = list->child[i];
13261326

13271327
smart_str_appends(str, "<<");
1328-
smart_str_append(str, zend_ast_get_str(attr->child[0]));
1328+
zend_ast_export_ns_name(str, attr->child[0], 0, indent);
13291329

13301330
if (attr->child[1]) {
13311331
zend_ast_list *args = zend_ast_get_list(attr->child[1]);
@@ -1446,7 +1446,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
14461446
case ZEND_AST_METHOD:
14471447
decl = (zend_ast_decl *) ast;
14481448
if (decl->attributes) {
1449-
zend_bool newlines = (ast->kind == ZEND_AST_CLOSURE || ast->kind == ZEND_AST_ARROW_FUNC) ? 0 : 1;
1449+
zend_bool newlines = (ast->kind == ZEND_AST_CLOSURE || ast->kind == ZEND_AST_ARROW_FUNC);
14501450
zend_ast_export_attributes(str, decl->attributes, indent, newlines);
14511451
}
14521452
if (decl->flags & ZEND_ACC_PUBLIC) {

Zend/zend_attributes.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ZEND_API zend_attributes_internal_validator zend_attribute_get_validator(zend_st
1818
return zend_hash_find_ptr(&internal_validators, lcname);
1919
}
2020

21-
ZEND_API void zend_attribute_free(zend_attribute *attr)
21+
ZEND_API void zend_attribute_free(zend_attribute *attr, int persistent)
2222
{
2323
uint32_t i;
2424

@@ -29,7 +29,7 @@ ZEND_API void zend_attribute_free(zend_attribute *attr)
2929
zval_ptr_dtor(&attr->argv[i]);
3030
}
3131

32-
efree(attr);
32+
pefree(attr, persistent);
3333
}
3434

3535
static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)
@@ -86,7 +86,7 @@ ZEND_API zend_attribute *zend_get_parameter_attribute_str(HashTable *attributes,
8686

8787
static void attribute_ptr_dtor(zval *v)
8888
{
89-
zend_attribute_free((zend_attribute *) Z_PTR_P(v));
89+
zend_attribute_free((zend_attribute *) Z_PTR_P(v), 1);
9090
}
9191

9292
ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator)
@@ -96,7 +96,6 @@ ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attrib
9696
}
9797

9898
zend_string *lcname = zend_string_tolower_ex(ce->name, 1);
99-
zval tmp;
10099

101100
zend_hash_update_ptr(&internal_validators, lcname, validator);
102101
zend_string_release(lcname);
@@ -113,8 +112,7 @@ ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attrib
113112
attr->offset = 0;
114113
attr->argc = 0;
115114

116-
ZVAL_PTR(&tmp, attr);
117-
zend_hash_next_index_insert(ce->attributes, &tmp);
115+
zend_hash_next_index_insert_ptr(ce->attributes, attr);
118116
}
119117

120118
void zend_register_attribute_ce(void)

Zend/zend_attributes.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#ifndef ZEND_ATTRIBUTES_H
22
#define ZEND_ATTRIBUTES_H
33

4-
#define ZEND_ATTRIBUTE_TARGET_CLASS 1
5-
#define ZEND_ATTRIBUTE_TARGET_FUNCTION 2
6-
#define ZEND_ATTRIBUTE_TARGET_METHOD 4
7-
#define ZEND_ATTRIBUTE_TARGET_PROPERTY 8
8-
#define ZEND_ATTRIBUTE_TARGET_CLASS_CONST 16
9-
#define ZEND_ATTRIBUTE_TARGET_PARAMETER 32
10-
#define ZEND_ATTRIBUTE_TARGET_ALL 63
4+
#define ZEND_ATTRIBUTE_TARGET_CLASS (1<<0)
5+
#define ZEND_ATTRIBUTE_TARGET_FUNCTION (1<<1)
6+
#define ZEND_ATTRIBUTE_TARGET_METHOD (1<<2)
7+
#define ZEND_ATTRIBUTE_TARGET_PROPERTY (1<<3)
8+
#define ZEND_ATTRIBUTE_TARGET_CLASS_CONST (1<<4)
9+
#define ZEND_ATTRIBUTE_TARGET_PARAMETER (1<<5)
10+
#define ZEND_ATTRIBUTE_TARGET_ALL (1<<6)
1111

1212
#define ZEND_ATTRIBUTE_SIZE(argc) (sizeof(zend_attribute) + sizeof(zval) * (argc) - sizeof(zval))
1313

@@ -26,7 +26,7 @@ typedef struct _zend_attribute {
2626

2727
typedef void (*zend_attributes_internal_validator)(zend_attribute *attr, int target);
2828

29-
ZEND_API void zend_attribute_free(zend_attribute *attr);
29+
ZEND_API void zend_attribute_free(zend_attribute *attr, int persistent);
3030

3131
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname);
3232
ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len);

Zend/zend_compile.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,12 +1822,12 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
18221822
} else {
18231823
ZEND_MAP_PTR_INIT(ce->static_members_table, &ce->default_static_members_table);
18241824
ce->info.user.doc_comment = NULL;
1825-
ce->attributes = NULL;
18261825
}
18271826

18281827
ce->default_properties_count = 0;
18291828
ce->default_static_members_count = 0;
18301829
ce->properties_info_table = NULL;
1830+
ce->attributes = NULL;
18311831

18321832
if (nullify_handlers) {
18331833
ce->constructor = NULL;
@@ -5751,7 +5751,7 @@ static zend_attribute *zend_compile_attribute(zend_ast *ast, uint32_t offset) /*
57515751

57525752
static void attribute_ptr_dtor(zval *v) /* {{{ */
57535753
{
5754-
zend_attribute_free((zend_attribute *) Z_PTR_P(v));
5754+
zend_attribute_free((zend_attribute *) Z_PTR_P(v), 0);
57555755
}
57565756
/* }}} */
57575757

@@ -5771,8 +5771,6 @@ static void zend_compile_attributes(HashTable *attributes, zend_ast *ast, uint32
57715771
zend_ast_list *list = zend_ast_get_list(ast);
57725772
uint32_t i;
57735773

5774-
zval tmp;
5775-
57765774
ZEND_ASSERT(ast->kind == ZEND_AST_ATTRIBUTE_LIST);
57775775

57785776
for (i = 0; i < list->children; i++) {
@@ -5785,8 +5783,7 @@ static void zend_compile_attributes(HashTable *attributes, zend_ast *ast, uint32
57855783
validator(attr, target);
57865784
}
57875785

5788-
ZVAL_PTR(&tmp, attr);
5789-
zend_hash_next_index_insert(attributes, &tmp);
5786+
zend_hash_next_index_insert_ptr(attributes, attr);
57905787
}
57915788
}
57925789
/* }}} */

Zend/zend_compile.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ typedef struct _zend_file_context {
120120
typedef union _zend_parser_stack_elem {
121121
zend_ast *ast;
122122
zend_string *str;
123-
HashTable *hash;
124123
zend_ulong num;
125124
unsigned char *ptr;
126125
} zend_parser_stack_elem;
@@ -406,7 +405,7 @@ struct _zend_op_array {
406405
uint32_t num_args;
407406
uint32_t required_num_args;
408407
zend_arg_info *arg_info;
409-
HashTable *attributes;
408+
HashTable *attributes;
410409
/* END of common elements */
411410

412411
int cache_size; /* number of run_time_cache_slots * sizeof(void*) */
@@ -456,7 +455,7 @@ typedef struct _zend_internal_function {
456455
uint32_t num_args;
457456
uint32_t required_num_args;
458457
zend_internal_arg_info *arg_info;
459-
HashTable *attributes;
458+
HashTable *attributes;
460459
/* END of common elements */
461460

462461
zif_handler handler;

ext/reflection/php_reflection.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,6 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s
11461146
static void reflect_attributes(INTERNAL_FUNCTION_PARAMETERS, HashTable *attributes,
11471147
uint32_t offset, zend_class_entry *scope) /* {{{ */
11481148
{
1149-
zval ret;
1150-
11511149
zend_string *name = NULL;
11521150
zend_long flags = 0;
11531151
zend_class_entry *base = NULL;
@@ -1157,7 +1155,7 @@ static void reflect_attributes(INTERNAL_FUNCTION_PARAMETERS, HashTable *attribut
11571155
}
11581156

11591157
if (flags & ~REFLECTION_ATTRIBUTE_IS_INSTANCEOF) {
1160-
zend_throw_error(NULL, "Invalid attribute filter flag specified");
1158+
zend_argument_value_error(2, "must be a valid attribute filter flag");
11611159
RETURN_THROWS();
11621160
}
11631161

@@ -1177,14 +1175,11 @@ static void reflect_attributes(INTERNAL_FUNCTION_PARAMETERS, HashTable *attribut
11771175
RETURN_EMPTY_ARRAY();
11781176
}
11791177

1180-
array_init(&ret);
1178+
array_init(return_value);
11811179

1182-
if (FAILURE == read_attributes(&ret, attributes, scope, offset, name, base)) {
1183-
zval_ptr_dtor(&ret);
1180+
if (FAILURE == read_attributes(return_value, attributes, scope, offset, name, base)) {
11841181
RETURN_THROWS();
11851182
}
1186-
1187-
RETURN_ZVAL(&ret, 1, 1);
11881183
}
11891184
/* }}} */
11901185

@@ -6393,6 +6388,8 @@ ZEND_METHOD(ReflectionAttribute, __construct)
63936388

63946389
ZEND_METHOD(ReflectionAttribute, __clone)
63956390
{
6391+
/* Should never be executable */
6392+
_DO_THROW("Cannot clone object using __clone()");
63966393
}
63976394

63986395
/* {{{ proto public string ReflectionAttribute::getName()
@@ -6415,6 +6412,7 @@ static zend_always_inline int import_attribute_value(zval *ret, zval *val, zend_
64156412
{
64166413
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
64176414
*ret = *val;
6415+
//ZVAL_COPY(ret, val);
64186416

64196417
if (FAILURE == zval_update_constant_ex(ret, scope)) {
64206418
return FAILURE;
@@ -6434,7 +6432,6 @@ ZEND_METHOD(ReflectionAttribute, getArguments)
64346432
reflection_object *intern;
64356433
attribute_reference *attr;
64366434

6437-
zval ret;
64386435
zval tmp;
64396436
uint32_t i;
64406437

@@ -6443,18 +6440,15 @@ ZEND_METHOD(ReflectionAttribute, getArguments)
64436440
}
64446441
GET_REFLECTION_OBJECT_PTR(attr);
64456442

6446-
array_init(&ret);
6443+
array_init(return_value);
64476444

64486445
for (i = 0; i < attr->data->argc; i++) {
64496446
if (FAILURE == import_attribute_value(&tmp, &attr->data->argv[i], attr->scope)) {
6450-
zval_ptr_dtor(&ret);
64516447
RETURN_THROWS();
64526448
}
64536449

6454-
add_next_index_zval(&ret, &tmp);
6450+
add_next_index_zval(return_value, &tmp);
64556451
}
6456-
6457-
RETURN_ZVAL(&ret, 1, 1);
64586452
}
64596453
/* }}} */
64606454

@@ -6582,7 +6576,7 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
65826576

65836577
attribute_ctor_cleanup(NULL, args, argc);
65846578

6585-
RETURN_ZVAL(&obj, 1, 1);
6579+
RETURN_COPY_VALUE(&obj);
65866580
}
65876581
/* }}} */
65886582
static const zend_function_entry reflection_ext_functions[] = { /* {{{ */

0 commit comments

Comments
 (0)