Commit graph

10 commits

Author SHA1 Message Date
Ilija Tovilo
93fc88e808
Fix Enum::from/tryFrom memory leak in JIT for internal enums
when passing an int to a string enum. Previously, the int was coerced to
a string. The JIT skips parameter clean up when unnecessary. In this
particular case, passing int to from(int|string) normally doesn't cause
a coercion so no dtor for the $value zval is generated.

To circumvent this we avoid coersion by explicitly allowing ints and
converting them to strings ourselves. Then we can free it appropriately.

See GH-8518
Closes GH-8633
2022-05-28 10:51:17 +02:00
Nikita Popov
c03f97cd1c Add missing const qualitier in zend_register_internal_enum() 2021-08-31 13:12:31 +02:00
Nikita Popov
a027247289 Fix message in test
Looks like I did not "git add" the message update.

Also drop the now dead ZEND_ENUM_PROPERTY_ERROR() macro while
here.
2021-08-13 17:01:16 +02:00
Nikita Popov
caefc6a507 Don't use custom object handlers for enum properties
Instead mark name/value as readonly and the class as
NO_DYNAMIC_PROPERTIES. This gives us the desired limitations
using native features.

In fact, this also fixes a bug where opcache cache slot merging
might result in a write to the name/value properties being
allowed. The readonly implementation handles this case correctly.
2021-08-13 16:44:39 +02:00
Nikita Popov
aef3bb70f4 Fix enum cast AST allocation, again
We always need to allocate space for the three children, and only
don't need one of the zend_ast_zval structures.
2021-07-27 11:05:45 +02:00
Nikita Popov
645ef62693 Fix enum cast AST allocation
I missed this occurrence of the hardcoded number "3".
2021-07-27 10:44:33 +02:00
Nikita Popov
a374230c15 Add support for internal enums
This adds support for internal enums with the same basic approach
as userland enums. Enum values are stored as CONSTANT_AST and
objects created during constant updating at runtime. This means
that we need to use mutable_data for internal enums.

This just adds basic support and APIs, it does not include the
stubs integration from #7212.

Closes GH-7302.
2021-07-27 09:19:14 +02:00
Nikita Popov
fd1d5ec2b4 Add ZEND_CLASS_CONST_FLAGS() macro
And drop Z_ACCESS_FLAGS(). We no longer store *only* access flags
in these.
2021-04-28 14:51:54 +02:00
Dmitry Stogov
84a843dff6 Use better function 2021-03-30 20:20:54 +03:00
Ilija Tovilo
269c8dac1d
Implement enums
RFC: https://wiki.php.net/rfc/enumerations

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>

Closes GH-6489.
2021-03-17 19:08:03 +01:00