Skip to content

Commit bb252e4

Browse files
committed
Do not add closures in const-expr to dynamic func defs
1 parent 0d5191f commit bb252e4

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

Zend/zend_ast.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_op_array(zend_op_array *op_arr
120120
ast->attr = 0;
121121
ast->lineno = CG(zend_lineno);
122122
ast->op_array = op_array;
123-
function_add_ref((zend_function *)op_array);
124123

125124
return (zend_ast *) ast;
126125
}
@@ -1355,8 +1354,7 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
13551354
} else if (EXPECTED(ast->kind == ZEND_AST_CONSTANT)) {
13561355
zend_string_release_ex(zend_ast_get_constant_name(ast), 0);
13571356
} else if (EXPECTED(ast->kind == ZEND_AST_OP_ARRAY)) {
1358-
zend_ast_op_array *op_array = zend_ast_get_op_array(ast);
1359-
destroy_op_array(op_array->op_array);
1357+
destroy_op_array(zend_ast_get_op_array(ast)->op_array);
13601358
} else if (EXPECTED(zend_ast_is_decl(ast))) {
13611359
zend_ast_decl *decl = (zend_ast_decl *) ast;
13621360

Zend/zend_compile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8244,9 +8244,6 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
82448244

82458245
zend_register_seen_symbol(lcname, ZEND_SYMBOL_FUNCTION);
82468246
switch (level) {
8247-
case FUNC_DECL_LEVEL_CONSTEXPR:
8248-
zend_add_dynamic_func_def(op_array);
8249-
break;
82508247
case FUNC_DECL_LEVEL_NESTED: {
82518248
uint32_t func_ref = zend_add_dynamic_func_def(op_array);
82528249
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
@@ -8261,6 +8258,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
82618258
}
82628259
break;
82638260
}
8261+
case FUNC_DECL_LEVEL_CONSTEXPR:
82648262
case FUNC_DECL_LEVEL_TOPLEVEL:
82658263
/* Nothing to do. */
82668264
break;

ext/opcache/zend_file_cache.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ static void zend_file_cache_unserialize_zval(zval *zv,
242242
zend_persistent_script *script,
243243
void *buf);
244244

245+
static void zend_file_cache_serialize_func(zval *zv,
246+
zend_persistent_script *script,
247+
zend_file_cache_metainfo *info,
248+
void *buf);
249+
250+
static void zend_file_cache_unserialize_func(zval *zv,
251+
zend_persistent_script *script,
252+
void *buf);
253+
245254
static void *zend_file_cache_serialize_interned(zend_string *str,
246255
zend_file_cache_metainfo *info)
247256
{
@@ -364,8 +373,10 @@ static void zend_file_cache_serialize_ast(zend_ast *ast,
364373
}
365374
}
366375
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
367-
/* The op_array itself will be serialized as part of the dynamic_func_defs. */
368-
SERIALIZE_PTR(zend_ast_get_op_array(ast)->op_array);
376+
zval z;
377+
ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
378+
zend_file_cache_serialize_func(&z, script, info, buf);
379+
zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
369380
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
370381
zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
371382
ZEND_MAP_PTR_INIT(fcc->fptr, NULL);
@@ -1252,8 +1263,10 @@ static void zend_file_cache_unserialize_ast(zend_ast *ast,
12521263
}
12531264
}
12541265
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
1255-
/* The op_array itself will be unserialized as part of the dynamic_func_defs. */
1256-
UNSERIALIZE_PTR(zend_ast_get_op_array(ast)->op_array);
1266+
zval z;
1267+
ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
1268+
zend_file_cache_unserialize_func(&z, script, buf);
1269+
zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
12571270
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
12581271
zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
12591272
ZEND_MAP_PTR_NEW(fcc->fptr);

0 commit comments

Comments
 (0)