Commit graph

69984 commits

Author SHA1 Message Date
Niels Dossche
68794e074b Use RETURN_NEW_STR() in url.c
This avoids an extra branch.
2025-04-22 18:41:45 +02:00
Niels Dossche
1b4bca605c Add assertion as optimization hint in php_url_encode_impl()
This avoids the code bloat induced by zend_string_truncate().
2025-04-22 18:41:45 +02:00
Derick Rethans
7e1c8efa02
Merge branch 'PHP-8.4' 2025-04-22 17:11:32 +01:00
Derick Rethans
d54aee5b0c
Merge branch 'PHP-8.3' into PHP-8.4 2025-04-22 17:11:15 +01:00
Carlos Buenosvinos
c9f3127ca8
Fix GH-18076: date_sun_info() function returns inaccurate sunrise and sunset times
Closes GH-18317: Avoid double counting the 15 minutes radial correction of the sun
2025-04-22 16:45:57 +01:00
David CARLIER
32a45769d1
ext/calendar: array optimisations. (#18388)
turn arrays to packed when applied/pre-allocate sizes.
2025-04-21 20:49:21 +01:00
David CARLIER
b233c55b12
ext/curl: curl_getinfo, curl_multi_get_handles and curl_multi_setopt array optimisations. (#18389)
mainly change to packed arrays.
2025-04-21 17:13:57 +01:00
David CARLIER
3b387ef274
ext/standard: stream_get_filters() user filters list as packed arrays. (#18384) 2025-04-21 17:03:35 +01:00
Niels Dossche
c15cacc902
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix uouv in pg_put_copy_end()
2025-04-21 17:47:55 +02:00
Niels Dossche
4621423e5e
Fix uouv in pg_put_copy_end()
Closes GH-18383.
2025-04-21 17:47:37 +02:00
David CARLIER
bd8c770439
ext/sqlite3: querySingle amd fetchArray methods optimisations. (#18385)
pre-allocated size for the former and packed array.
2025-04-21 16:37:34 +01:00
David CARLIER
df39586a88
ext/zlib: gzfile() files list as packed array (#18380) 2025-04-21 14:47:52 +01:00
David CARLIER
0c2025cdc4
ext/tidy: array optimisations, children node arrays as packed. (#18375) 2025-04-21 13:47:53 +01:00
David CARLIER
8f6bc97a36
ext/pgsql: pg_fetch_all_columns/pg_copy_to arrays optimisations. (#18374)
changes to packed arrays for output userland values.
2025-04-21 13:43:44 +01:00
Niels Dossche
864ad1b5bb
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
2025-04-21 13:15:50 +02:00
Niels Dossche
1a1a83f1fc
Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
On win64, xmm6-xmm15 are preserved registers, but the prologues and
epilogues of JITted code don't handle these. The issue occurs when
calling into the JIT code again via an internal handler
(like call_user_func). Therefore, we want to save/restore xmm registers
upon entering/leaving execute_ex. Since MSVC x64 does not support inline
assembly, we create an assembly wrapper around the real execute_ex
function.
The alternative is to always save/restore these xmm registers into the
fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register
8 to 15. However, there we can use inline asm to fix this.

Closes GH-18352.
2025-04-21 13:15:43 +02:00
David CARLIER
158181ff37
ext/pcntl: pcntl_sigprocmask/pcntl_getcpuaffinity to packed arrays. (#18369) 2025-04-20 23:23:56 +01:00
David CARLIER
b385e0dd2b
ext/posix: preallocate arrays and/or change to packed ones. (#18370) 2025-04-20 23:23:43 +01:00
David CARLIER
68d54030a1
ext/sockets: using array optimisations. (#18367)
mostly explicit packed arrays.
2025-04-20 19:34:11 +01:00
David CARLIER
2c3a2da48a
ext/gd: array supplied to user optimisations. (#18366)
explictly allocate packed arrays when it applies.
2025-04-20 17:30:12 +01:00
Niels Dossche
eeaa60f6fa
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix reference support for intltz_get_offset()
2025-04-20 14:24:02 +02:00
Niels Dossche
affffe1122
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix reference support for intltz_get_offset()
2025-04-20 14:23:56 +02:00
Niels Dossche
bf4b470098
Fix reference support for intltz_get_offset()
It should use the helper macros such that types are properly respected.

Closes GH-18364.
2025-04-20 14:23:31 +02:00
Niels Dossche
e9b01f202b Use pre-allocated array sizes and packed where possible in intl 2025-04-20 12:18:15 +02:00
Niels Dossche
68b904884b Factor out duplicated code 2025-04-20 12:17:50 +02:00
Niels Dossche
dc9039086c Avoid pointless refcounting in php_intl_idn_to_46() 2025-04-20 12:17:50 +02:00
Niels Dossche
f39c07a3bb DOM/XPath: Use RETURN_NEW_STR
These strings are newly allocated and can't be interned, so we can use
RETURN_NEW_STR.
2025-04-19 18:00:00 +02:00
Niels Dossche
35e96f621b DOM/XPath: Use ZSTR_LEN abstraction instead of direct member access 2025-04-19 18:00:00 +02:00
Niels Dossche
91a310e603
Get rid of separate DOM HashPosition member (#18354)
Besides the fact that this is only used for DOM_NODESET and thus makes
no sense of being on the iterator itself, it's also redundant now that
we have the index member.
2025-04-19 17:59:48 +02:00
David CARLIER
2e7df9e423
ext/gd: imagefilter* using overflow checks. (#18283)
Accept up to UINT_MAX * sizeof(int) colors.
2025-04-19 16:27:14 +01:00
Kamil Tekiela
25f4f7982c
Drop unused variables (#18023) 2025-04-19 13:26:09 +01:00
David Carlier
fcd0f72cdd
GH-18345: adding Locale::isRightToLeft.
Checks is the locale is written left to right.
It makes sure all the needed likely subtags are included (maximization)
then determines the direction by known matches.

close GH-18351
2025-04-19 10:23:03 +01:00
David CARLIER
ba83d5daeb
sapi/litespeed and ext/standard: Fix few build warnings. (#18265) 2025-04-19 10:18:53 +01:00
Saki Takamachi
23687672f3
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fixed GH-17383 - pdo_firebird: PDOException has wrong code and message since PHP 8.4 (#18072)
2025-04-19 14:11:35 +09:00
Saki Takamachi
685baf77df
Fixed GH-17383 - pdo_firebird: PDOException has wrong code and message since PHP 8.4 (#18072)
Closes #18072
Fixes #17383
2025-04-19 14:11:20 +09:00
Niels Dossche
8376904aeb
Implement GH-17321: Add setAuthorizer to Pdo\Sqlite (#17905) 2025-04-18 00:34:46 +02:00
Niels Dossche
66d5cf8d2d
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak on error return of collation callback in pdo_sqlite
2025-04-16 13:52:34 +02:00
Niels Dossche
ce7304f909
Fix memory leak on error return of collation callback in pdo_sqlite
We should destroy it when it's not IS_LONG, not when it's IS_LONG.

Closes GH-18332.
2025-04-16 13:52:23 +02:00
Niels Dossche
2d3ac4e2ed
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix NULL deref on high modification key
2025-04-16 11:41:33 +02:00
Niels Dossche
bfa2cfc9ed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix NULL deref on high modification key
2025-04-16 11:38:38 +02:00
Niels Dossche
c905d59106
Fix NULL deref on high modification key
We should re-index in the loop.

Closes GH-18331.
2025-04-16 11:37:49 +02:00
Niels Dossche
b50f7c22c3
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak when handling a too long path in ZipArchive::addGlob()
  Fix uouv when handling empty options in ZipArchive::addGlob()
2025-04-16 10:46:23 +02:00
Niels Dossche
ecd2872cf4
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak when handling a too long path in ZipArchive::addGlob()
  Fix uouv when handling empty options in ZipArchive::addGlob()
2025-04-16 10:46:17 +02:00
Niels Dossche
91c6c727d5
Fix memory leak when handling a too long path in ZipArchive::addGlob()
Closes GH-18330.
2025-04-16 10:45:35 +02:00
Niels Dossche
0a6326c6ac
Fix uouv when handling empty options in ZipArchive::addGlob()
Reported by OpenAI AARDVARK.

php_zip_parse_option is only called when options are passed to the function.
Prior to this patch, php_zip_parse_option was responsible for zeroing the
opts variable. So in the case when php_zip_parse_option is not called,
opts remains uninitialized yet it is being used anyway.
By just always zeroing opts at declaration time, we avoid this issue
and we are unlikely to reintroduce this in the future.

Closes GH-18329.
2025-04-16 10:44:59 +02:00
Niels Dossche
ea387fcfb7
Avoid useless initializations of fci/fcc in array functions (#18273)
These cause cache misses due to global access, in phpstan
(notably the array_map).
Initializing these isn't necessary because ZPP initializes it for us.
Only for optional arguments do we need to be careful; for `array_filter`
we still reset the `fci` but not `fci_cache` because `fci` is not
necessarily set by ZPP but is conditionally used to access `fci_cache`.
2025-04-15 23:08:12 +02:00
Arnaud Le Blanc
76d7c616bb
Pass opline as argument to opcode handlers in CALL VM
This changes the signature of opcode handlers in the CALL VM so that the opline
is passed directly via arguments. This reduces the number of memory operations
on EX(opline), and makes the CALL VM considerably faster.

Additionally, this unifies the CALL and HYBRID VMs a bit, as EX(opline) is now
handled in the same way in both VMs.

This is a part of GH-17849.

Currently we have two VMs:

 * HYBRID: Used when compiling with GCC. execute_data and opline are global
   register variables
 * CALL: Used when compiling with something else. execute_data is passed as
   opcode handler arg, but opline is passed via execute_data->opline
   (EX(opline)).

The Call VM looks like this:

    while (1) {
        ret = execute_data->opline->handler(execute_data);
        if (UNEXPECTED(ret != 0)) {
            if (ret > 0) { // returned by ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {       // returned by ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    int ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data) {
        // load opline
        const zend_op *opline = execute_data->opline;

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        execute_data->opline++;
        return 0; // ZEND_VM_CONTINUE()
    }

Opcode handlers return a positive value to signal that the loop must load a
new execute_data from EG(current_execute_data), typically when entering
or leaving a function.

Here I make the following changes:

 * Pass opline as opcode handler argument
 * Return next opline from opcode handlers
 * ZEND_VM_ENTER / ZEND_VM_LEAVE return opline|(1<<0) to signal that
   execute_data must be reloaded from EG(current_execute_data)

This gives us:

    while (1) {
        opline = opline->handler(execute_data, opline);
        if (UNEXPECTED((uintptr_t) opline & ZEND_VM_ENTER_BIT) {
            opline = opline & ~ZEND_VM_ENTER_BIT;
            if (opline != 0) { // ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {           // ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    const zend_op * ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data, const zend_op *opline) {
        // opline already loaded

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        return ++opline;
    }

bench.php is 23% faster on Linux / x86_64, 18% faster on MacOS / M1.

Symfony Demo is 2.8% faster.

When using the HYBRID VM, JIT'ed code stores execute_data/opline in two fixed
callee-saved registers and rarely touches EX(opline), just like the VM.

Since the registers are callee-saved, the JIT'ed code doesn't have to
save them before calling other functions, and can assume they always
contain execute_data/opline. The code also avoids saving/restoring them in
prologue/epilogue, as execute_ex takes care of that (JIT'ed code is called
exclusively from there).

The CALL VM can now use a fixed register for execute_data/opline as well, but
we can't rely on execute_ex to save the registers for us as it may use these
registers itself. So we have to save/restore the two registers in JIT'ed code
prologue/epilogue.

Closes GH-17952
2025-04-15 18:51:54 +02:00
Arnaud Le Blanc
49891d89fc
Merge branch 'PHP-8.4'
* PHP-8.4:
  Save opline in zend_jit_hot_func()
2025-04-15 14:11:53 +02:00
Florian Engelhardt
061b46e09d
Save opline in zend_jit_hot_func()
Closes GH-18289
2025-04-15 14:11:32 +02:00
Saki Takamachi
3b87093bff
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fixed GH-18276 - persistent connection - "zend_mm_heap corrupted" with setAttribute() (#18280) Closes #18280 Fixes #18276
2025-04-15 09:07:06 +09:00