Skip to content

Zend: Accumulate parsed integer locally in _zend_handle_numeric_str_ex() - #484

Closed
iliaal wants to merge 32 commits into
masterfrom
opt/handle-numeric-str-local-acc
Closed

iliaal wants to merge 32 commits into
masterfrom
opt/handle-numeric-str-local-acc

Conversation

@iliaal

@iliaal iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Owner

_zend_handle_numeric_str_ex() updates *idx on every digit, forcing GCC to reload and store *idx on every iteration because key (const char *) may alias *idx under C strict-aliasing rules.

Accumulate the value in a local zend_ulong register and store to *idx once after the overflow check passes.

On ARM64 (Neoverse-N1, GCC 13.3 -O2 NTS), disassembly confirms the per-digit load/store pair is removed, speeding up numeric-key symtable insert and lookup by 12.07% (-9.96% cycles) with date (-0.65%) and alpha (-0.03%) controls unchanged.

NattyNarwhal and others added 30 commits November 27, 2026 13:51
Introduced in 99c7ddc; previously
called in some SAPIs, but the callsites have all been removed for years.
DCE rewrites a dead instruction whose operand still needs freeing into a
FREE, but kept the instruction's extended_value. After (float) and (array)
casts and empty() it has bit 0 set, which ZEND_HANDLE_EXCEPTION reads as
ZEND_FREE_ON_RETURN: when a destructor run by that FREE throws, the throw
point moves by the FREE's op2, which is (uint32_t)-1, and
cleanup_live_vars() frees the operand a second time.

Closes phpGH-25836
* PHP-8.4:
  Zend: Reset extended_value of FREE synthesized by DCE
Since b1242c3 a server stream seeded from a session stream shares the
parent's SSL_CTX and ignores its own context options. The SNI callback
registered on that context looks up the certificate table of the stream
doing the handshake, but the table was left only on the parent, so the
child always served the default certificate. Give the child its own table
that references the parent's per-name contexts.
* PHP-8.6:
  ext/openssl: Fix SNI certs not used on streams sharing a session SSL_CTX
* PHP-8.5:
  Zend: Reset extended_value of FREE synthesized by DCE
* PHP-8.6:
  Zend: Reset extended_value of FREE synthesized by DCE
The DB-Lib error and message handlers estrdup() server and library text
into the connection's pdo_dblib_err. For a persistent connection, errors
raised through PDO::exec() and the transaction and lastInsertId() calls
stay there until the next statement execute, so a request that ends after
such an error leaves pointers into the reset request heap. The next
request efree()s them from the message or error handler or the cursor
closer, and module shutdown does from the handle closer. Free them from
persistent_shutdown once the last PDO object using the connection is
released.

Closes phpGH-25159
* PHP-8.4:
  ext/pdo_dblib: Release persistent handle error strings at request end
* PHP-8.5:
  ext/pdo_dblib: Release persistent handle error strings at request end
* PHP-8.6:
  ext/pdo_dblib: Release persistent handle error strings at request end
…#25719)

Dereference the options element of the context parameters before checking
its type, so stream_context_create() and stream_context_set_params()
accept references to valid options arrays. References to other types
still raise a TypeError.

Co-authored-by: Gina Peter Banyard <girgias@php.net>

Closes php#25719
* PHP-8.4:
  Fix stream context functions rejecting options held by reference (php#25719)
snmp_init_mib() passed ZSTR_VAL(mibdirs) to netsnmp_ds_set_string() even
when $mibdirs was null, so calling it without an argument or with null
crashed. It now passes NULL in that case, which makes net-snmp fall back
to its default MIB directories, as the RFC describes and as RSHUTDOWN
already does. The stub also lacked the = null default even though ZPP
treats the argument as optional, so debug builds hit an arginfo/zpp
mismatch on snmp_init_mib().

Fix phpGH-25858
Close phpGH-25861
* PHP-8.6:
  ext/snmp: snmp_init_mib() crashes when $mibdirs is omitted or null
* PHP-8.5:
  Fix stream context functions rejecting options held by reference (php#25719)
* PHP-8.6:
  Fix stream context functions rejecting options held by reference (php#25719)
…down.

Objects outliving RSHUTDOWN dropped an empty archive at refcount 0
through the already destroyed fname map, while another object still
held it. The archive is now left to its last holder.

Fix phpGH-25722
Close phpGH-25728
* PHP-8.4:
  ext/phar: phar_archive_delref() double free on shared archive at shutdown.
* PHP-8.5:
  ext/phar: phar_archive_delref() double free on shared archive at shutdown.

# Conflicts:
#	ext/phar/phar.c
* PHP-8.6:
  ext/phar: phar_archive_delref() double free on shared archive at shutdown.
socket_addrinfo_lookup(), socket_bind(), socket_connect(), socket_sendto()
and socket_sendmsg() would otherwise resolve only the part before the NUL
byte.

Closes phpGH-25774
# Conflicts:
#	ext/sockets/conversions.c
# Conflicts:
#	NEWS
#	ext/sockets/sockets.c
# Conflicts:
#	NEWS
When zend_string_safe_falloc() fails under memory_limit,
php_str_to_str_i_ex() returned NULL without releasing the lowercased needle.

Closes phpGH-25848
* PHP-8.4:
  ext/standard: Release lc_needle on OOM in php_str_to_str_i_ex()
* PHP-8.5:
  ext/standard: Release lc_needle on OOM in php_str_to_str_i_ex()
* PHP-8.6:
  ext/standard: Release lc_needle on OOM in php_str_to_str_i_ex()
Keep the dereferencing QM_ASSIGN when its source is IS_VAR. ZEND_RETURN
only accepts CONST, TMP, and CV, so folding the assignment into the
return can produce an invalid opcode for by-reference assignments or
list destructuring.

Fixes phpGH-25756
Closes phpGH-25814
* PHP-8.6:
  ext/opcache: Do not drop QM_ASSIGN of IS_VAR before ZEND_RETURN
_zend_handle_numeric_str_ex() updated *idx on every digit. Because key
is a const char * that may alias *idx, GCC loaded and stored *idx on
every loop iteration. Accumulate into a local zend_ulong and store *idx
once at the end of the string.
@iliaal
iliaal force-pushed the opt/handle-numeric-str-local-acc branch from 84bed00 to 4d09bb8 Compare November 28, 2026 15:26
@iliaal

iliaal commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php/php-src phpGH-25874.

@iliaal iliaal closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants