Skip to content

Commit

Permalink
Allocate map_ptr for mutable_data during preloading
Browse files Browse the repository at this point in the history
We need to discard objects in the class constants if they happened
to be evaluated during preloading. To allow doing so, we need to
use mutable_data, which will place the evaluated constants into
a separate table.
  • Loading branch information
nikic committed Jul 27, 2021
1 parent aef3bb7 commit b354184
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7687,6 +7687,7 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
ce->ce_flags |= ZEND_ACC_PRELOADED;
ZEND_MAP_PTR_NEW(ce->static_members_table);
ZEND_MAP_PTR_NEW(ce->mutable_data);
}

ce->ce_flags |= decl->flags;
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/tests/preload_enum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ enum MyEnum {
case Foo;
case Bar;
}
var_dump(MyEnum::Bar);
3 changes: 3 additions & 0 deletions ext/opcache/tests/preload_enum.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows
<?php

var_dump(MyEnum::Foo);
var_dump(MyEnum::Bar);

?>
--EXPECT--
enum(MyEnum::Bar)
enum(MyEnum::Foo)
enum(MyEnum::Bar)

0 comments on commit b354184

Please sign in to comment.