Commit graph

1299 commits

Author SHA1 Message Date
Niels Dossche
5b673e99fc
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
2024-07-04 13:36:46 +02:00
Niels Dossche
6467655568
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
2024-07-04 13:35:53 +02:00
Niels Dossche
7b74cadf8c
Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
Fixes one issue in GH-14806.
2024-07-04 13:34:33 +02:00
Niels Dossche
c151d2d135 standard: change uses of sprintf into snprintf and zend_string_concat2 2024-06-14 08:12:03 -07:00
Gina Peter Banyard
25a5146180
Clean-up unused headers (#14365)
* ext/mbstring.c: clean-up headers and include intrinsics
2024-06-01 17:12:42 +01:00
Niels Dossche
75e3f3e0ca
Optimize strpbrk (#13558) 2024-03-05 20:51:12 +01:00
Tim Düsterhus
dce6ed3199
random: Adjust status to state (#13521)
* random: Rename `status` local to `state`

* random: Rename `php_random_algo_with_state`'s `status` member to `state`
2024-02-26 20:38:45 +01:00
Tim Düsterhus
79133df156
random: Pass algorithm and state together as php_random_algo_with_state (#13350)
* random: Remove `php_random_status`

Since 162e1dce98, the `php_random_status` struct
contains just a single `void*`, resulting in needless indirection when
accessing the engine state and thus decreasing readability because of the
additional non-meaningful `->state` references / the local helper variables.

There is also a small, but measurable performance benefit:

    <?php
    $e = new Random\Engine\Xoshiro256StarStar(0);
    $r = new Random\Randomizer($e);

    for ($i = 0; $i < 15; $i++)
    	var_dump(strlen($r->getBytes(100000000)));

goes from roughly 3.85s down to 3.60s.

The names of the `status` variables have not yet been touched to keep the diff
small. They will be renamed to the more appropriate `state` in a follow-up
cleanup commit.

* Introduce `php_random_algo_with_state`
2024-02-25 20:48:58 +01:00
Ilija Tovilo
631bc81607
Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
Cristian Rodríguez
927adfb1a6
Use a single version of mempcpy(3) (#12257)
While __php_mempcpy is only used by ext/standard/crypt_sha*, the
mempcpy "pattern" is used everywhere.

This commit removes __php_mempcpy, adds zend_mempcpy and transforms
open-coded parts into function calls.
2023-12-20 15:16:32 +00:00
Niels Dossche
e78966386b Remove always-false condition from substr_replace()
l < 0 is checked before and set to a different value.
2023-12-12 16:43:43 +00:00
Vinicius Dias
f1af7223f8
Fixing incorrect error message when passing null to join/implode's array parameter (#12683)
Closes GH-12682
2023-12-01 09:55:20 +00:00
Niels Dossche
9a973a3743
Optimize strcspn (#12594) 2023-11-04 13:54:30 +00:00
Ilija Tovilo
d35faecbf2
Split strtr zpp (#12583) 2023-11-01 13:08:06 +01:00
Niels Dossche
d0b29d8286 Optimize strspn()
The current implementation uses a nested loop (for + goto), which has
complexity O(|s1| * |s2|). If we instead use a lookup table, the
complexity drops to O(|s1| + |s2|).
This is conceptually the same strategy that common C library
implementations such as glibc and musl use.
The variation with a bitvector instead of a table also gives a speed-up,
but the table variation was about 1.34x faster.

On microbenchmarks this easily gave a 5x speedup.

This can bring a 1.4-1.5% performance improvement in the Symfony
benchmark.

Closes GH-12431.
2023-10-14 21:24:55 +02:00
Ilija Tovilo
b31a5b2731
Fix str_decrement() on "1"
Closes GH-12339
2023-10-02 16:42:04 +02:00
Kamil Tekiela
649872f105
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix param name in implode() error message
2023-08-24 21:07:50 +01:00
Kamil Tekiela
ec82927d25
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix param name in implode() error message
2023-08-24 21:07:18 +01:00
Kamil Tekiela
b1ce1d1f21
Fix param name in implode() error message 2023-08-24 21:05:26 +01:00
HypeMC
f25474f7f2
Add before_needle argument to strrchr()
Closes GH-11430
2023-08-24 14:26:46 +01:00
George Peter Banyard
d8696f9216
[RFC] Path to Saner Increment/Decrement operators (#10358)
* Add behavioural tests for incdec operators

* Add support to ++/-- for objects castable to _IS_NUMBER

* Add str_increment() function

* Add str_decrement() function

RFC: https://wiki.php.net/rfc/saner-inc-dec-operators

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2023-07-17 15:51:24 +01:00
Niels Dossche
93e0f6b424 Fix undefined behaviour in string uppercasing and lowercasing
At least on 32-bit, the address computations overflow in running the
test on CI with UBSAN enabled. Fix it by reordering the arithmetic.
Since a part of the expression is already used in the code above the
computation, this should not negatively affect performance.

Closes GH-10936.
2023-03-25 21:17:15 +01:00
Michael Voříšek
3821938e81
Imply UTF8 validity in implode function (#10780)
Sets the UTF-8 valid flag if all parts are valid, or numeric (which are valid UTF-8 by definition).

* remove unuseful comments

* Imply UTF8 validity in implode function

* revert zend_string_dup change
2023-03-07 19:30:35 +01:00
George Peter Banyard
524391bcf6
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed ValueError message in count_chars()
  Fixed ValueError message in substr_compare()
  The userland constants do not start with PHP_
2023-02-26 14:28:49 +00:00
George Peter Banyard
f440911057
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed ValueError message in count_chars()
  Fixed ValueError message in substr_compare()
  The userland constants do not start with PHP_
2023-02-26 14:28:22 +00:00
George Peter Banyard
adc5edd411
Fixed ValueError message in count_chars()
The value of the mode argument must be between 0 and 4 inclusive, not 1 and 4.
2023-02-26 14:27:46 +00:00
George Peter Banyard
2133970152
Fixed ValueError message in substr_compare()
It used some random argument name instead of
2023-02-26 14:25:02 +00:00
Niels Dossche
c2d4bafc4f Copy UTF-8 flag for str_repeat 2023-02-05 14:32:50 +00:00
Niels Dossche
2b55dee4dc
Make stripslashes() only dependent on SSE2 configuration. (#10408)
Alex Dowad noticed[1] that the SIMD stripslashes implementation actually
only depended on SSE2, and not on SSE4.2 instructions. Remove the
checking for SSE4.2 and only check for SSE2. This also greatly
simplifies the supporting code.

[1] https://github.com/php/php-src/pull/10313#issuecomment-1382825073
2023-01-23 13:25:00 +00:00
David Carlier
256a34ed15 strtok warns in case the string to split was not set.
Close GH-10016.
2023-01-23 12:13:49 +00:00
George Peter Banyard
5624cbbed1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix wrong flags check for compression method in phar_object.c
  Fix missing check for xmlTextWriterEndElement
  Fix substr_replace with slots in repl_ht being UNDEF
2023-01-15 15:43:57 +00:00
George Peter Banyard
ec377c687d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix wrong flags check for compression method in phar_object.c
  Fix missing check for xmlTextWriterEndElement
  Fix substr_replace with slots in repl_ht being UNDEF
2023-01-15 15:43:34 +00:00
Niels Dossche
4bbbe6d652
Fix substr_replace with slots in repl_ht being UNDEF
The check that was supposed to check whether the array slot was UNDEF
was wrong and never triggered. This resulted in a replacement with the
empty string or the wrong string instead of the correct one. The correct
check pattern can be observed higher up in the function's code.

Closes GH-10323

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-15 15:31:34 +00:00
Niels
e951202a69
Remove useless check, search_str is always true here (#10322) 2023-01-15 00:32:51 +01:00
George Peter Banyard
11f6022365 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10187: Segfault in stripslashes() with arm64
  Fix memory leak in posix_ttyname()
2022-12-30 16:43:05 +00:00
George Peter Banyard
e6c9b176d4 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10187: Segfault in stripslashes() with arm64
  Fix memory leak in posix_ttyname()
2022-12-30 16:42:45 +00:00
Niels Dossche
4c9375e504 Fix GH-10187: Segfault in stripslashes() with arm64
Closes GH-10188

Co-authored-by: todeveni <toni.viemero@iki.fi>
Signed-off-by: George Peter Banyard <girgias@php.net>
2022-12-30 16:40:56 +00:00
Máté Kocsis
a4fd2609ce
Declare ext/standard constants in stubs - part 9 (#9717) 2022-10-13 13:13:36 +02:00
Máté Kocsis
3227d04fa9
Declare ext/standard constants in stubs - part 7 (#9505) 2022-09-08 13:57:07 +02:00
dixyes
3a843f953b
Windows arm64 zend and standard extension support
* Port zend_cpuid for windows arm64
* Fix zend_atomic windows arm64 build
* Fix windows arm64 multiply
* Enable arm64 neon for windows in standard extension
* Enable arm64 neon for windows in zend_hash.c
* Workaround for msvc arm64 optimization bug

Closes GH-9115.
2022-08-09 12:45:14 +02:00
Nikita Popov
6ff662b2e6 Fix unused-but-set-variable warning in hebrev() 2022-07-28 22:29:42 +02:00
Tim Düsterhus
5c693c770a
Remove ->last_unsafe from php_random_status (#9132)
Whenever ->last_unsafe is set to `true` an exception has been thrown. Thus we
can replace the check for `->last_unsafe` with a check for `EG(exception)`
which is a much more natural way to ommunicate an error up the chain.
2022-07-26 09:02:51 +02:00
Go Kudo
4d8dd8d258
Implement Random Extension
https://wiki.php.net/rfc/rng_extension
https://wiki.php.net/rfc/random_extension_improvement
2022-07-19 10:27:38 +01:00
Michael Voříšek
e80925445c Fix GH-8924 str_split of empty string must return empty array
Closes #8945.
2022-07-08 15:49:45 +01:00
Arnaud Le Blanc
4df3dd7679
Reduce memory allocated by var_export, json_encode, serialize, and other (#8902)
smart_str uses an over-allocated string to optimize for append operations. Functions that use smart_str tend to return the over-allocated string directly. This results in unnecessary memory usage, especially for small strings.

The overhead can be up to 231 bytes for strings smaller than that, and 4095 for other strings. This can be avoided for strings smaller than `4096 - zend_string header size - 1` by reallocating the string.

This change introduces `smart_str_trim_to_size()`, and calls it in `smart_str_extract()`. Functions that use `smart_str` are updated to use `smart_str_extract()`.

Fixes GH-8896
2022-07-08 14:47:46 +02:00
George Peter Banyard
4ccf0b0181
Make php_fgetcsv() return a HashTale instead of in-out zval param (#8936)
Also refactor what happens on an empty line to return NULL instead of setting the array to [NULL] which makes no design sense at all.
However, as this is the current behaviour create a BC Shim inline function to recreate this weird HashTable in the functions which currently use this API
2022-07-08 12:11:05 +01:00
George Peter Banyard
ef287bfceb
Minor refactoring of std string extension (#8196)
Mainly using more appropriate types, early returns, and moving the happy path to the primary scope (failure path is guarded by ``UNEXPECTED`` macros.
2022-04-23 12:15:13 +01:00
George Peter Banyard
5171cb435a Fix [-Wundef] warnings in standard extension 2022-04-01 15:48:41 +01:00
Max Kellermann
b9e895bca0
Replace memcmp() with zend_string functions (#8216)
* ext/oci8: use zend_string_equals()

Eliminate duplicate code.

* main/php_variables: use zend_string_equals_literal()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_equals_cstr()

Allows eliminating duplicate code.

* Zend, ext/{opcache,standard}, main/output: use zend_string_equals_cstr()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_starts_with()

* ext/{opcache,phar,spl,standard}: use zend_string_starts_with()

This adds missing length checks to several callers, e.g. in
cache_script_in_shared_memory().  This is important when the
zend_string is shorter than the string parameter, when memcmp()
happens to check backwards; this can result in an out-of-bounds memory
access.
2022-03-31 16:27:58 +02:00
George Peter Banyard
e948d3c9c8
Use zend_string_to(upper|lower)() API directly 2022-03-23 23:59:41 +00:00