Skip to content

Commit 9eb084d

Browse files
committed
Changes to opcache. Fixed AST dump. Proper NULL-handling in reflection.
1 parent 0c3743d commit 9eb084d

File tree

6 files changed

+32
-51
lines changed

6 files changed

+32
-51
lines changed

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

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

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

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

3229
Warning: assert(): assert(0 && ($a = new <<A1>> class {
3330
<<A1>>
3431
<<A2>>
3532
const FOO = 'foo';
3633
<<A2>>
3734
public $x;
38-
<<A3>> public function a() {
35+
<<A3>>
36+
public function a() {
3937
}
4038

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

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);
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_ast.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,6 @@ static zend_always_inline zend_string *zend_ast_get_constant_name(zend_ast *ast)
315315
return Z_STR(((zend_ast_zval *) ast)->val);
316316
}
317317

318-
static zend_always_inline HashTable *zend_ast_get_hash(zend_ast *ast) {
319-
zval *zv = zend_ast_get_zval(ast);
320-
ZEND_ASSERT(Z_TYPE_P(zv) == IS_ARRAY);
321-
return Z_ARR_P(zv);
322-
}
323-
324318
static zend_always_inline uint32_t zend_ast_get_num_children(zend_ast *ast) {
325319
ZEND_ASSERT(!zend_ast_is_list(ast));
326320
return ast->kind >> ZEND_AST_NUM_CHILDREN_SHIFT;
@@ -334,12 +328,6 @@ static zend_always_inline uint32_t zend_ast_get_lineno(zend_ast *ast) {
334328
}
335329
}
336330

337-
static zend_always_inline zend_ast *zend_ast_create_zval_from_hash(HashTable *hash) {
338-
zval zv;
339-
ZVAL_ARR(&zv, hash);
340-
return zend_ast_create_zval(&zv);
341-
}
342-
343331
static zend_always_inline zend_ast *zend_ast_create_binary_op(uint32_t opcode, zend_ast *op0, zend_ast *op1) {
344332
return zend_ast_create_ex(ZEND_AST_BINARY_OP, opcode, op0, op1);
345333
}

ext/opcache/zend_file_cache.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -404,25 +404,23 @@ static void zend_file_cache_serialize_attribute(zval *zv,
404404
zend_file_cache_metainfo *info,
405405
void *buf)
406406
{
407-
if (!IS_SERIALIZED(Z_PTR_P(zv))) {
408-
zend_attribute *attr = Z_PTR_P(zv);
409-
uint32_t i;
407+
zend_attribute *attr = Z_PTR_P(zv);
408+
uint32_t i;
410409

411-
SERIALIZE_PTR(Z_PTR_P(zv));
412-
attr = Z_PTR_P(zv);
413-
UNSERIALIZE_PTR(attr);
410+
SERIALIZE_PTR(Z_PTR_P(zv));
411+
attr = Z_PTR_P(zv);
412+
UNSERIALIZE_PTR(attr);
414413

415-
if (!IS_SERIALIZED(attr->name)) {
416-
SERIALIZE_STR(attr->name);
417-
}
414+
if (!IS_SERIALIZED(attr->name)) {
415+
SERIALIZE_STR(attr->name);
416+
}
418417

419-
if (!IS_SERIALIZED(attr->lcname)) {
420-
SERIALIZE_STR(attr->lcname);
421-
}
418+
if (!IS_SERIALIZED(attr->lcname)) {
419+
SERIALIZE_STR(attr->lcname);
420+
}
422421

423-
for (i = 0; i < attr->argc; i++) {
424-
zend_file_cache_serialize_zval(&attr->argv[i], script, info, buf);
425-
}
422+
for (i = 0; i < attr->argc; i++) {
423+
zend_file_cache_serialize_zval(&attr->argv[i], script, info, buf);
426424
}
427425
}
428426

@@ -1175,24 +1173,22 @@ static void zend_file_cache_unserialize_zval(zval *zv,
11751173

11761174
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf)
11771175
{
1178-
if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
1179-
zend_attribute *attr;
1180-
uint32_t i;
1176+
zend_attribute *attr;
1177+
uint32_t i;
11811178

1182-
UNSERIALIZE_PTR(Z_PTR_P(zv));
1183-
attr = Z_PTR_P(zv);
1179+
UNSERIALIZE_PTR(Z_PTR_P(zv));
1180+
attr = Z_PTR_P(zv);
11841181

1185-
if (!IS_UNSERIALIZED(attr->name)) {
1186-
UNSERIALIZE_STR(attr->name);
1187-
}
1182+
if (!IS_UNSERIALIZED(attr->name)) {
1183+
UNSERIALIZE_STR(attr->name);
1184+
}
11881185

1189-
if (!IS_UNSERIALIZED(attr->lcname)) {
1190-
UNSERIALIZE_STR(attr->lcname);
1191-
}
1186+
if (!IS_UNSERIALIZED(attr->lcname)) {
1187+
UNSERIALIZE_STR(attr->lcname);
1188+
}
11921189

1193-
for (i = 0; i < attr->argc; i++) {
1194-
zend_file_cache_unserialize_zval(&attr->argv[i], script, buf);
1195-
}
1190+
for (i = 0; i < attr->argc; i++) {
1191+
zend_file_cache_unserialize_zval(&attr->argv[i], script, buf);
11961192
}
11971193
}
11981194

ext/opcache/zend_persist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static HashTable *zend_persist_attributes(HashTable *attributes)
271271

272272
ZEND_HASH_FOREACH_VAL(attributes, v) {
273273
zend_attribute *attr = Z_PTR_P(v);
274-
zend_attribute *copy = zend_shared_memdup(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
274+
zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
275275

276276
zend_accel_store_interned_string(copy->name);
277277
zend_accel_store_interned_string(copy->lcname);
@@ -281,7 +281,6 @@ static HashTable *zend_persist_attributes(HashTable *attributes)
281281
}
282282

283283
ZVAL_PTR(v, copy);
284-
efree(attr);
285284
} ZEND_HASH_FOREACH_END();
286285

287286
ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ static void reflect_attributes(INTERNAL_FUNCTION_PARAMETERS, HashTable *attribut
11501150
zend_long flags = 0;
11511151
zend_class_entry *base = NULL;
11521152

1153-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|Sl", &name, &flags) == FAILURE) {
1153+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!l", &name, &flags) == FAILURE) {
11541154
RETURN_THROWS();
11551155
}
11561156

0 commit comments

Comments
 (0)