Skip to content

Commit b737879

Browse files
committed
Adjust tests, fix node conversion, still leaking and not resolving names.
1 parent ed76308 commit b737879

File tree

5 files changed

+32
-102
lines changed

5 files changed

+32
-102
lines changed

Zend/tests/attributes_001.phpt

Lines changed: 10 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Bar {
2222
const C = 2;
2323
<<TestProp>>
2424
public $x = 3;
25-
25+
2626
}
2727
$r = new ReflectionClass("Bar");
2828
var_dump($r->getAttributes());
@@ -38,7 +38,7 @@ $r = new ReflectionFunction("f1");
3838
var_dump($r->getAttributes());
3939

4040
// Attributes with AST
41-
<<a1,a2(1+"a"),a3(1+"b",2+"c"),a4(["a"=>1,"b"=>2])>>
41+
<<a1,a2(1+1),a3(1+3,2+2),a4(["a"=>1,"b"=>2])>>
4242
function f2() {}
4343
$r = new ReflectionFunction("f2");
4444
var_dump($r->getAttributes());
@@ -97,102 +97,21 @@ array(4) {
9797
["a2"]=>
9898
array(1) {
9999
[0]=>
100-
object(ast\Node)#4 (4) {
101-
["kind"]=>
102-
int(520)
103-
["flags"]=>
104-
int(1)
105-
["lineno"]=>
106-
NULL
107-
["children"]=>
108-
array(2) {
109-
[0]=>
110-
int(1)
111-
[1]=>
112-
string(1) "a"
113-
}
114-
}
100+
int(2)
115101
}
116102
["a3"]=>
117-
array(2) {
103+
array(1) {
118104
[0]=>
119-
object(ast\Node)#5 (4) {
120-
["kind"]=>
121-
int(520)
122-
["flags"]=>
123-
int(1)
124-
["lineno"]=>
125-
NULL
126-
["children"]=>
127-
array(2) {
128-
[0]=>
129-
int(1)
130-
[1]=>
131-
string(1) "b"
132-
}
133-
}
134-
[1]=>
135-
object(ast\Node)#6 (4) {
136-
["kind"]=>
137-
int(520)
138-
["flags"]=>
139-
int(1)
140-
["lineno"]=>
141-
NULL
142-
["children"]=>
143-
array(2) {
144-
[0]=>
145-
int(2)
146-
[1]=>
147-
string(1) "c"
148-
}
149-
}
105+
int(4)
150106
}
151107
["a4"]=>
152108
array(1) {
153109
[0]=>
154-
object(ast\Node)#7 (4) {
155-
["kind"]=>
156-
int(130)
157-
["flags"]=>
158-
int(0)
159-
["lineno"]=>
160-
NULL
161-
["children"]=>
162-
array(2) {
163-
[0]=>
164-
object(ast\Node)#8 (4) {
165-
["kind"]=>
166-
int(525)
167-
["flags"]=>
168-
int(0)
169-
["lineno"]=>
170-
NULL
171-
["children"]=>
172-
array(2) {
173-
[0]=>
174-
int(1)
175-
[1]=>
176-
string(1) "a"
177-
}
178-
}
179-
[1]=>
180-
object(ast\Node)#9 (4) {
181-
["kind"]=>
182-
int(525)
183-
["flags"]=>
184-
int(0)
185-
["lineno"]=>
186-
NULL
187-
["children"]=>
188-
array(2) {
189-
[0]=>
190-
int(2)
191-
[1]=>
192-
string(1) "b"
193-
}
194-
}
195-
}
110+
array(2) {
111+
["a"]=>
112+
int(1)
113+
["b"]=>
114+
int(2)
196115
}
197116
}
198117
}

Zend/tests/attributes_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace Doctrine\ORM {
1414
function GetClassAttributes($class_name) {
1515
$reflClass = new \ReflectionClass($class_name);
1616
$attrs = $reflClass->getAttributes();
17-
foreach ($attrs as $name => &$values) {
17+
foreach ($attrs as $name => $values) {
1818
$name = "Doctrine\\" . $name;
19-
$values = new $name($values);
19+
$attrs[$name] = new $name($values);
2020
}
2121
return $attrs;
2222
}

Zend/tests/attributes_003.phpt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,25 @@ namespace Doctrine\ORM\Mapping {
88
}
99
}
1010

11-
namespace {
11+
namespace Foo {
1212
use Doctrine\ORM\Mapping\Entity;
1313

14-
<<Entity(["foo"])>>
14+
<<Entity(["foo" => "bar"])>>
1515
function foo() {
1616
}
17-
var_dump((new ReflectionFunction('foo'))->getAttributes());
17+
}
18+
19+
namespace {
20+
var_dump((new ReflectionFunction('Foo\foo'))->getAttributes());
1821
}
1922
--EXPECTF--
23+
array(1) {
24+
["Doctrine\ORM\Mapping\Entity"]=>
25+
array(1) {
26+
[0]=>
27+
array(1) {
28+
["foo"]=>
29+
string(3) "bar"
30+
}
31+
}
32+
}

Zend/zend_ast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,7 @@ ZEND_API void zend_ast_convert_to_object(zval *p, zend_ast *ast, zend_class_entr
21352135
if (UNEXPECTED(zend_ast_evaluate(&tmp, ast, ce) != SUCCESS)) {
21362136
return;
21372137
}
2138+
21382139
ZVAL_COPY_VALUE(p, &tmp);
21392140
}
21402141
}

Zend/zend_compile.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9286,12 +9286,12 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
92869286
void zend_add_attribute(zend_ast *name, zend_ast *value) /* {{{ */
92879287
{
92889288
zval *val, tmp;
9289-
//zend_string *key = zend_ast_get_str(name);
9289+
zend_string *key;
92909290

92919291
znode class_node;
92929292

92939293
zend_compile_class_ref(&class_node, name, ZEND_FETCH_CLASS_EXCEPTION);
9294-
zend_string *key = Z_STR(class_node.u.constant);
9294+
key = Z_STR(class_node.u.constant);
92959295

92969296
if (!CG(attributes)) {
92979297
ALLOC_HASHTABLE(CG(attributes));
@@ -9316,16 +9316,13 @@ void zend_add_attribute(zend_ast *name, zend_ast *value) /* {{{ */
93169316
zend_hash_next_index_insert_new(Z_ARRVAL_P(val), zv);
93179317
}
93189318
} else {
9319-
ZVAL_AST(&tmp, zend_ast_copy(value));
9320-
zend_ast_destroy(value);
9319+
zend_const_expr_to_zval(&tmp, value);
93219320
array_init(val);
93229321
zend_hash_next_index_insert_new(Z_ARRVAL_P(val), &tmp);
93239322
}
93249323
} else {
93259324
array_init(val);
93269325
}
9327-
9328-
zend_string_release(key);
93299326
}
93309327
/* }}} */
93319328

0 commit comments

Comments
 (0)