1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

230 Commits

Author SHA1 Message Date
Arnaud Le Blanc
92b2887722 Fix handling of ZEND_AST_CALLABLE_CONVERT in file cache (#20860)
Nodes in zend_ast_fcc->args were serialized, but not zend_ast_fcc->args itself
2026-01-07 18:54:29 +01:00
Arnaud Le Blanc
5472cac806 Support PFA syntax
RFC: https://wiki.php.net/rfc/partial_function_application_v2

For FCCs, the parser generates a normal function call AST node, the but argument
list is a ZEND_AST_CALLABLE_CONVERT / zend_ast_fcc node.

We extend this for PFAs so that zend_ast_fcc can represent arguments.

 * Support PFA syntax in grammar
 * Update zend_ast_fcc so that arguments can be represented
 * Support serialization of zend_ast_fcc arguments in SHM / file cache
 * Introduce zend_ast_arg_list_add(): Same as zend_ast_list_add(), but wraps the
   list in a ZEND_AST_CALLABLE_CONVERT when adding any placeholder argument.

Technically the arg list wrapping is not required, but it results in simpler
code later as it will be very convenient in the compiler (determines whether a
function calls is a PFA/FCC), and for PFA-in-const-expr support. It also allows
to unify FCCs and PFAs in the grammar.

Closes GH-20717.
2026-01-06 12:01:48 +01:00
Arnaud Le Blanc
170fcf2381 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Remove CE cache from non-interned file cache strings
2025-11-06 11:21:45 +01:00
Arnaud Le Blanc
7e077f5a14 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Remove CE cache from non-interned file cache strings
2025-11-06 11:21:12 +01:00
Arnaud Le Blanc
b062410d32 Remove CE cache from non-interned file cache strings
Strings loaded from the file cache can not have a CE cache, because their cache
slot is invalid. Remove the IS_STR_CLASS_NAME_MAP_PTR flag from these strings.
We can also avoid updating the str flags in SERIALIZE_STR(), since the same
updates must also be done in UNSERIALIZE_STR().

This was already done for interned strings, but not for non-interned ones.

Fixes GH-20329
Closes GH-20337
2025-11-06 11:20:17 +01:00
Ilija Tovilo
ab0a9155d4 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Reset Z_EXTRA_P(op2) of ZEND_INIT_FCALL for opcache file cache
2025-10-31 17:50:42 +01:00
Ilija Tovilo
50c7f498b9 Reset Z_EXTRA_P(op2) of ZEND_INIT_FCALL for opcache file cache
The offset becomes stale if the environment changes. We're currently relying on
other factors in the environment staying constant, e.g. send types. But this
seems to be the worst offender.

Partially addresses GH-17733
Closes GH-20328
2025-10-31 17:50:02 +01:00
Daniel Scherzer
63acc4bf61 [RFC] Add #[\DelayedTargetValidation] attribute (#18817)
https://wiki.php.net/rfc/delayedtargetvalidation_attribute
2025-08-20 00:41:20 -07:00
Samuel Melrose
6f1501a601 Add opcache_is_script_cached_in_file_cache() function
Closes GH-16979
2025-07-16 17:37:12 +02:00
DanielEScherzer
3f03f7ed3d [RFC] Add support for attributes on compile-time constants
https://wiki.php.net/rfc/attributes-on-constants
2025-04-29 11:53:09 -07:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Tim Düsterhus
45d1acf916 Zend: Fix reference counting for Closures in const-expr (#17853)
* Clean up closure static variable handling

* Zend: Fix reference counting for Closures in const-expr

Fixes php/php-src#17851

---------

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-03-27 10:11:44 +01:00
Tim Düsterhus
2042fd34e0 Support first-class callables in const-expressions (#17213)
RFC: https://wiki.php.net/rfc/fcc_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-02-20 18:52:47 +01:00
Christoph M. Becker
107bd080a5 Fix Clang style nits (GH-17685)
This addresses all `-Wlogical-op-parentheses` and `-Wmissing-braces`
warnings across the whole code base (all Windows specific code).
2025-02-05 14:13:56 +01:00
Tim Düsterhus
cee64ed3bd Add dedicated zend_ast_op_array struct (#17391)
Given that the `ZEND_AST_OP_ARRAY` type already needed special handling in
various places, it makes sense to give it its own struct to avoid some of the
casts. As a side benefit, it is a little smaller than the `zend_ast_zval`
struct.
2025-01-08 11:26:35 +01:00
Tim Düsterhus
fd1eacc2ed Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes (#17390)
* zend_compile: Do not traverse children of ZEND_AST_CLOSURE in zend_compile_const_expr()

* Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes
2025-01-08 10:36:02 +01:00
Tim Düsterhus
f6a0bb4d04 Support Closures in constant expressions (#16458)
RFC: https://wiki.php.net/rfc/closures_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
2024-12-02 18:25:43 +01:00
Samuel Melrose
5191581e9c Fix merge of GH-16551
Some commits were mistakenly discarded during the rebase and squash of GH-16551.
2024-11-26 16:35:14 +01:00
Samuel Melrose
37995c09b7 Add opcache.file_cache_read_only
Closes GH-16551
2024-11-26 13:06:52 +01:00
Gina Peter Bnayard
3813ad10dc Remove unused ext/standard/basic_functions.h header inclusions
Those were probably included back in the day for the php_uint32 typedef
2024-08-18 18:20:22 +01:00
Ilija Tovilo
780a8280d2 [RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Peter Kokot
5d3fab9334 Sync #if/ifdef/defined (#14520)
These are either undefined or defined (to value 1):
- __DragonFly__
- __FreeBSD__
- HAS_MCAST_EXT
- HAVE_GETCWD
- HAVE_GETWD
- HAVE_GLIBC_ICONV
- HAVE_JIT
- HAVE_LCHOWN
- HAVE_NL_LANGINFO
- HAVE_RL_CALLBACK_READ_CHAR
- HAVE_RL_ON_NEW_LINE
- HAVE_SQL_EXTENDED_FETCH
- HAVE_UTIME

Follow up of GH-5526 (-Wundef)
2024-06-11 22:47:05 +02:00
Peter Kokot
84a0da1574 Sync #if/ifdef/defined (#14508)
This syncs CPP macro conditions:
- _WIN32
- _WIN64
- HAVE_ALLOCA_H
- HAVE_ALPHASORT
- HAVE_ARPA_INET_H
- HAVE_CONFIG_H
- HAVE_DIRENT_H
- HAVE_DLFCN_H
- HAVE_GETTIMEOFDAY
- HAVE_LIBDL
- HAVE_POLL_H
- HAVE_PWD_H
- HAVE_SCANDIR
- HAVE_SYS_FILE_H
- HAVE_SYS_PARAM_H
- HAVE_SYS_SOCKET_H
- HAVE_SYS_TIME_H
- HAVE_SYS_TYPES_H
- HAVE_SYS_WAIT_H
- HAVE_UNISTD_H
- PHP_WIN32
- ZEND_WIN32

These are either undefined or defined to 1 in Autotools and Windows.

Follow up of GH-5526 (-Wundef).
2024-06-09 14:23:41 +02:00
Máté Kocsis
f2e199e878 Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Ilija Tovilo
49ebfb04ef Fix JMP_FRAMELESS with ZEND_USE_ABS_JMP_ADDR
which is used on 32-bit machines.
2024-02-07 15:50:38 +01:00
Dmitry Stogov
5553092d85 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Reset inheritance_cache pointer of zend_class_entry upon serialization (#12401)
2023-10-11 09:57:43 +03:00
Dmitry Stogov
310b5283eb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reset inheritance_cache pointer of zend_class_entry upon serialization (#12401)
2023-10-11 09:57:35 +03:00
Sergei Turchanov
90f2e7607a Reset inheritance_cache pointer of zend_class_entry upon serialization (#12401)
to opcache filecache. Usually, when a class is being loaded, a dependency
tracking is performed after the call to zend_file_cache_script_store.
But sometimes, when opcache cache is empty and there are many simultaneous
outstanding requests for compilation, some classes do have their
inheritance_cache initialized before the call to zend_file_cache_script_store,
and in that case this pointer is serialized as-is. And when such a class
is loaded from opcache filecache this pointer also loaded as-is, and now
it points to some random location in memory. This causes segfaults occuring
when traversing inheritance_cache of such classes.

We need to reset inheritance_cache pointer of zend_class_entry
upon serialization. This should have been done anyway since it is a sensible
strategy to sanitize any memory pointer upon serialization (either by calling
SERIALIZE_x macros or setting to NULL or any other deterministic value).
2023-10-11 09:57:18 +03:00
Ilija Tovilo
35862641ba Unpoison opcache mem buf for file cache checksum calc
The buffer may contain uninitialized bytes, like padding, zval.value for
IS_TRUE, IS_NULL, etc. and other unused fields. The checksum calculation loops
over all bytes and thus will trigger uninitialized reads in MSAN. It doesn't
matter too much, as the bytes in the file will still match the checksum.
2023-08-02 19:23:54 +02:00
Ilija Tovilo
b2dbf0a2c6 Remove opcache.consistency_checks
This feature has been broken at least since the tracing JIT and inheritance
cache have been introduced. The attempted fix (GH-10798) was too complex. We
have thus decided to remove this feature for now.

Closes GH-11832
2023-08-02 19:22:30 +02:00
Ilija Tovilo
e8edd35c49 Merge branch 'PHP-8.2'
* PHP-8.2:
  Check if restart is pending before trying to lock SHM
2023-07-31 20:01:23 +02:00
Ilija Tovilo
f2328302b6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Check if restart is pending before trying to lock SHM
2023-07-31 20:00:49 +02:00
Mikhail Galanin
3e9792f4a2 Check if restart is pending before trying to lock SHM
This reduces lock contention when Opcache restart is scheduled
but not yet started.

Closes GH-11805
2023-07-31 20:00:31 +02:00
Ilija Tovilo
0b1d750d91 Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Máté Kocsis
414f71a902 Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Max Kellermann
413844d626 Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597)
These types are standard C99.

For compatibility with out-of-tree extensions, keep the typedefs
in main/php.h.
2023-02-18 19:31:28 +00:00
Christoph M. Becker
c8955c078a Revert GH-10220
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491.
This reverts commit 588a07f737.
This reverts commit f377e15751.
This reverts commit b4ba16fe18.
This reverts commit 694ec1deea.
This reverts commit 6b34de8eba.
This reverts commit aa1cd02a43.
This reverts commit 308fd311ea.
This reverts commit 16203b53e1.
This reverts commit 738fb5ca54.
This reverts commit 9fdbefacd3.
This reverts commit cd4a7c1d90.
This reverts commit 928685eba2.
This reverts commit 01e5ffc85c.
2023-01-16 12:27:33 +01:00
Max Kellermann
308fd311ea ext/{standard,json,random,...}: add missing includes 2023-01-10 14:19:03 +00:00
Ilija Tovilo
3daa8a93ee Fix default_object_handlers pointing to invalid memory with file_cache
Closes GH-9596
2022-10-27 10:48:31 +02:00
Arnaud Le Blanc
ea1287b015 Log the cause of error when opcache cannot write to file cache (#9258) 2022-09-03 11:23:43 +02:00
Ilija Tovilo
ddc0b490f7 Allow arbitrary const expressions in backed enums
Closes GH-7821
Closes GH-8190
Closes GH-8418
2022-06-12 22:56:05 +02:00
Max Kellermann
04a4864b65 ext/opcache: merge redundant code and "bool" refactoring (#8237)
* ext/opcache/ZendAccelerator: make check_persistent_script_access() static

* ext/opcache/ZendAccelerator: convert "int" to "bool"

* ext/opcache/zend_file_cache: convert "int" to "bool"

* ext/opcache: use true/false for zend_persistent_script.corrupted

* ext/opcache/ZendAccelerator: move duplicate code to zend_accel_discard_script()

* ext/opcache/ZendAccelerator: convert accel_deactivate_now() to function

Simplify the #iddef ZEND_WIN32.

* ext/opcache/zend_file_cache: simplify iovec initializer

* ext/opcache/zend_file_cache: add local zend_string* variables

Eliminates lots of redundant casts and avoids reloading the variable
from RAM into registers.

* ext/opcache/zend_file_cache: use ZSTR_VAL()

* ext/opcache/zend_file_cache: move code to zend_file_cache_script_write()

This eliminates duplicate error handling code.
2022-03-24 15:03:53 +01:00
Max Kellermann
63281763bf ext/opcache/zend_shared_alloc: add zend_shared_alloc_aligned()
Eliminate some duplicate code.
2022-03-20 20:42:14 +01:00
Nikita Popov
4543cd32ae Remove JMPZNZ opcode
While JMPZNZ can avoid execution of a separate JMP opcode in some
cases, it also prevents smart branch optimization, so creating
JMPZNZ may actually have a negative effect. It also adds additional
complexity for optimizations.

Drop JMPZNZ in favor of JMPZ+JMP or JMPNZ+JMP.

Closes GH-7857.
2022-01-10 22:07:10 +01:00
Tyson Andre
024d5f4b63 Cache method overrides of ArrayAccess in zend_class_entry
Previously, code such as subclasses of SplFixedArray would check for method
overrides when instantiating the objects.

This optimization was mentioned as a followup to GH-6552
2021-12-04 11:35:38 -05:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Dmitry Stogov
ddaf64b56c Avoid non-immutable map_ptr indirection 2021-10-14 12:16:18 +03:00
Nikita Popov
c19977d054 Fix delayed early binding with optimization
It's possible for delayed early binding opcodes to get optimized
away if they are "unreachable". However, we still need to attempt
early binding for them. (In some cases we also corrupt the early
binding list outright during optimization, which is how I got here.)

Fix this by storing information about delayed early binding
independently of DECLARE_CLASS_DELAYED opcodes, so early binding is
performed even after the opcode has been dropped.
2021-09-29 18:00:20 +02:00
Nikita Popov
ba8e5d336b Merge branch 'PHP-8.0'
* PHP-8.0:
  Test file_cache prime shm + use file combination
  Fix repeated file cache unserialization of zval string
2021-08-18 12:39:47 +02:00
Nikita Popov
de7ba3e737 Fix repeated file cache unserialization of zval string
The IS_UNSERIALIZED check here does not work if the string is
interned (serialized with file_cache_only=0) but unserialization
happens with file_cache_only=1. In this case the unserializde
string will be in the str area after mem, which is not included
in the script size, and which is also not accessible at this
point without threading through more information. Work around
the problem by checking for the serialized representation instead.
2021-08-18 12:38:27 +02:00