Commit Graph

271 Commits

Author SHA1 Message Date
Jeremy Mikola
25cdb3b83d
[skip ci] Document zend_enum_get_case_by_value() function
This function was introduced in d62d50b88e.
2022-10-20 11:08:57 +02:00
Máté Kocsis
4af695e908
Require PHP 7.4 at least for running the build system (#9519) 2022-09-10 18:31:43 +02:00
Andreas Braun
f7d42f646b
Update gen_stub to avoid compile errors on duplicate function names
Closes GH-9406
2022-08-30 11:33:45 +02:00
Christoph M. Becker
ca011bbf56
Drop unsupported libxml2 2.10.0 symbols
The Docbook parser module has been removed completely.  Support for
XPointer locations (ranges and points) is disabled by default, and will
eventually be removed completely.  Given that the maintainer comments
on the latter: "Be warned that this part of the code base is buggy and
had many security issues in the past", it seems to be prudent to no
longer build with XPointer locations support right away.

To be able to build against libxml2 2.10.0, we remove the export
definitions for Windows.

Closes GH-9358.
2022-08-28 13:56:34 +02:00
George Peter Banyard
d0d6dae8f7
Add a new zend API to check that strings don't have NUL bytes (#9375)
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2022-08-22 15:28:38 +01:00
Ilija Tovilo
98bdb7f99b
Make pestr[n]dup infallible (#9295)
Fixes GH-9128
Closes GH-9295
2022-08-12 12:21:14 +02:00
Bob Weinand
625f164963 Include internal functions in the observer API
There are two main motivations to this:
a) The logic for handling internal and userland observation can be unified.
b) Unwinding of observed functions on a bailout does notably not include observers. Even if users of observers were to ensure such handling themselves, it would be impossible to retain the relative ordering - either the user has to unwind all internal observed frames before the automatic unwinding (zend_observer_fcall_end_all) or afterwards, but not properly interleaved.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-07-30 19:20:55 +02:00
Rowan Tommins
af15923bc3
Extend deprecation notices to is_callable($foo) and callable $foo
Implements https://wiki.php.net/rfc/partially-supported-callables-expand-deprecation-notices
so that uses of "self" and "parent" in is_callable() and callable
type constraints now raise a deprecation notice, independent of the
one raised when and if the callable is actually invoked.

A new flag is added to the existing check_flags parameter of
zend_is_callable / zend_is_callable_ex, for use in internal calls
that would otherwise repeat the notice multiple times. In particular,
arguments to internal function calls are checked first based on
arginfo, and then again during ZPP, so the former suppresses the
deprecation notice.

Some existing tests which raised this deprecation have been updated
to avoid the syntax, but the existing version retained for maximum
regression coverage until it is made an error.

With thanks to Juliette Reinders Folmer for the RFC and initial
investigation.

Closes GH-8823.
2022-07-14 17:07:42 +02: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
eacf6f43ed
Add upgrading internals entry for fgetcsv() changes 2022-07-08 13:32:01 +01:00
Max Kellermann
e2bd3b1e99 main/streams/plain_wrapper: skip lseek(SEEK_CUR) for newly opened files
A file that has just been opened is known to be at offset zero, and
the lseek(SEEK_CUR) system call to determine the current offset can be
skipped.

Closes #8540.
2022-06-29 18:11:01 +01:00
Ilija Tovilo
3b92a96610
Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
Arnaud Le Blanc
efc8f0ebf8
Deprecate zend_atol() / add zend_ini_parse_quantity() (#7951)
Add zend_ini_parse_quantity() and deprecate zend_atol(), zend_atoi()

zend_atol() and zend_atoi() don't just do number parsing.
They also check for a 'K', 'M', or 'G' at the end of the string,
and multiply the parsed value out accordingly.

Unfortunately, they ignore any other non-numerics between the
numeric component and the last character in the string.
This means that numbers such as the following are both valid
and non-intuitive in their final output.

* "123KMG" is interpreted as "123G" -> 132070244352
* "123G " is interpreted as "123 " -> 123
* "123GB" is interpreted as "123B" -> 123
* "123 I like tacos." is also interpreted as "123." -> 123

Currently, in php-src these functions are used only for parsing ini values.

In this change we deprecate zend_atol(), zend_atoi(), and introduce a new
function with the same behavior, but with the ability to report invalid inputs
to the caller. The function's name also makes the behavior less unexpected:
zend_ini_parse_quantity().

Co-authored-by: Sara Golemon <pollita@php.net>
2022-06-17 14:12:53 +02:00
George Peter Banyard
2958c7ccd8 [skip ci] Add missing UPGRADING.INTERNALS entries 2022-06-08 13:25:17 +01:00
George Peter Banyard
d08451b2ca
Replace php_stdint.h header with standard headers (#8613) 2022-05-29 11:20:56 +01:00
Levi Morrison
b63df3ce0e
Stop copying zend_module_entry (#8551)
I did some historical digging and could not figure out why a copy is
made. Additionally, the copy was not using the `.size` member, so it
was probably wrong, but it's been that way for quite some time.
2022-05-24 09:13:38 -06:00
Levi Morrison
282655083e
Fix some minor warnings (#8568)
* Fix php_apache_get_version prototype

Avoids an error with -Werror=strict-prototypes when building the
Apache SAPI.

* Fix -Werror=stringop-truncation in pdo_raise_impl_error

* Note pdo_error_type BC break
2022-05-18 08:30:59 -06:00
George Peter Banyard
71a110fcaa
Remove strnatcmp_ex() wrappers
These APIs always returned SUCCESS.

Closes GH-8195
2022-03-23 23:53:12 +00:00
Ilija Tovilo
2f5295692f
Optimize stripos/stristr
Closes GH-7847
Closes GH-7852

Previously stripos/stristr would lowercase both the haystack and the
needle to reuse strpos. The approach in this PR is similar to strpos.
memchr is highly optimized so we're using it to search for the first
character of the needle in the haystack. If we find it we compare the
remaining characters of the needle manually.

The new implementation seems to perform about half as well as strpos (as
two memchr calls are necessary to find the next candidate).
2022-01-31 21:44:31 +01:00
George Peter Banyard
da684582d7
ZEND_INIT_FCALL is only produced when function exists at compile time (#7728) 2021-12-09 17:15:59 +00:00
George Peter Banyard
1afe89f8c3
Remove (ZEND_)WRONG_PARAM_COUNT_WITH_RETVAL macros
A TypeError is always emitted therefore assigning a retval is pointless and incorrect.
2021-10-22 06:44:48 +02:00
Nikita Popov
498674058c Remove zend_binary_zval_strcasecmp() APIs
These are thin wrappers ... around the wrong functions. They call
the "_l()" version of the underlying APIs. For clarify, just call
the wrapped API directly.
2021-09-24 09:38:08 +02:00
Patrick Allaert
1c33ddb5e5
Prepare for PHP 8.2 2021-08-31 19:13:49 +02:00
Nikita Popov
14f599ea7d Use zend_long for resource ID
Currently, resource IDs are limited to 32-bits. As resource IDs
are not reused, this means that resource ID overflow for
long-running processes is very possible.

This patch switches resource IDs to use zend_long instead, which
means that on 64-bit systems, 64-bit resource IDs will be used.
This makes resource ID overflow practically impossible.

The tradeoff is an 8 byte increase in zend_resource size.

Closes GH-7436.
2021-08-31 14:58:59 +02:00
Joe Watkins
00c668a15d
Drop TsHashTable (#7351) 2021-08-08 10:45:44 +02:00
George Peter Banyard
fb52b3c915 [skip-ci] Fix comments and UPGRADING.INTERNALS for zend_type changes 2021-07-28 13:31:52 +02:00
Levi Morrison
ae8647d9d3
Remove leading underscore for _zend_hash_find_known_hash (#7260)
Convert zend_hash_find_ex(..., 1) to zend_hash_find_known_hash(...)
Convert zend_hash_find_ex(..., 0) to zend_hash_find(...)

Also add serializable changes to UPGRADING.INTERNALS summary
2021-07-20 17:07:17 -06:00
Joe Watkins
322864b569
Drop serial denier functions 2021-07-20 13:11:11 +02:00
Nikita Popov
814a932734 Add ZEND_ACC_NOT_SERIALIZABLE flag
This prevents serialization and unserialization of a class and its
children in a way that does not depend on the zend_class_serialize_deny
and zend_class_unserialize_deny handlers that will be going away
in PHP 9 together with the Serializable interface.

In stubs, `@not-serializable` can be used to set this flag.

This patch only uses the new flag for a handful of Zend classes,
converting the remainder is left for later.

Closes GH-7249.
Fixes bug #81111.
2021-07-19 15:59:11 +02:00
George Peter Banyard
453a5163ce [skip-ci] Fixup UPGRADING documents
Some entries were in the wrong section/wrong document.
2021-07-17 23:27:26 +02:00
Nikita Popov
a733b1ada7 Restore zend_atoi()
I dropped this in preparation for changes that I didn't end up
doing. Restore the function for now to avoid unnecessary churn for
extensions.
2021-07-16 14:46:56 +02:00
Nikita Popov
5f8489a11d Add upgrading note
I was originally planning more changes here, but then I realized
that zend_atol() is actually used to parse all numbers in inis,
not just those expecting sizes. I think I'll just leave it at
that.

[ci skip]
2021-07-13 11:03:12 +02:00
Nikita Popov
0d6358f2cf Drop support for printf p modifier
To be conservative, cause a fatal error if the p modifier is
encountered, in case this is still used by some extension.
2021-06-16 17:59:00 +02:00
Nikita Popov
e11468a79b Remove ZVAL_NEW_ARR() macro
This macro is a footgun because it creates an uninitialized array
(only an allocation). This macro is no longer used in php-src,
and we have better alternatives like array_init() or
ZVAL_ARR(arr, zend_new_array(size_hint)).
2021-06-07 12:49:58 +02:00
Anatol Belski
805b391d99
NEWS: UPGRADING.INTERNALS: Add PCRE2 10.37 info
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
2021-05-30 13:06:16 +02:00
George Peter Banyard
612609e1bd
Refactor PGSQL extension to use zend_string*
* Prevents some unnecessary strlen() computation
 * Use interned "NULL"
 * Certain PGSQL_API functions now accept zend_string* instead of char*

Closes GH-6792
2021-04-19 20:33:40 +01:00
George Peter Banyard
fabcfd6d81
Formalize return type to zend_result for PGSQL_API functions 2021-04-19 20:33:05 +01:00
George Peter Banyard
dcdc5d9069 Drop -Wno-implicit-fallthrough compiler flag
And add it back to ext/date, ext/hash, and ext/opcache
2021-04-19 13:59:18 +01:00
twosee
cb8f39f247
Add zend_get_opcode_id() to get opcode id from name 2021-04-06 11:44:10 +08:00
George Peter Banyard
caaf2e9981 [skip-ci] Update UPGRADING documents for the new argument for fputcsv() 2021-03-29 13:55:18 +01:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00
George Peter Banyard
0807c6cbb0 Remove php_pdo_str_tolower_dup() function 2021-03-15 14:48:33 +00:00
Máté Kocsis
91739b8c89
Fix bug #80816 Document the removal of alias class entries from ext/spl
Closes GH-6748 [skip-ci]
2021-03-03 09:43:55 +01:00
Anatol Belski
6055b72d0e UPGRADING: Add note about xxHash secret and fix a typo
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
2021-02-21 13:36:28 +01:00
George Peter Banyard
a78aea8948 Refactor PDO's last inserted ID handler to use and return zend_string
Closes GH-6617
2021-01-19 11:54:25 +00:00
George Peter Banyard
94ea8e247b Refactor PDO doer handler to use zend_string 2021-01-19 11:42:39 +00:00
George Peter Banyard
63cda0fea8 Refactor PDO's quoter handler to return a zend_string
Closes GH-6547
2021-01-07 15:53:48 +00:00
George Peter Banyard
9052f3b7d2 Update UPGRADIN.INTERNALS 2021-01-06 10:26:37 +00:00
Nikita Popov
caa710037e Rewrite PDO result binding
Instead of requiring the type to be determined in advance by the
describer function and then requiring get_col to return a buffer
of appropriate type, allow get_col to return an arbitrary zval.
See UPGRADING.INTERNALS for a more detailed description of the
change.

This makes the result fetching simpler, more efficient and more
flexible. The general possibility already existed via the special
PDO_PARAM_ZVAL type, but the usage was very inconvenient and/or
inefficient. Now it's possible to easily implement behavior like
"return int if it fits, otherwise string" and to avoid any kind
of complex management of temporary buffers.

This also fixes bug #40913 (our second highest voted bug of all
time, for some reason). PARAM_LOB result bindings will now
consistently return a stream resource, independently of the used
database driver.

I've tried my best to update all PDO drivers for this change, but
some of the changes may be broken, as I cannot test or even build
some of these drivers (in particular PDO dblib and PDO oci).
Fixes are appreciated -- a working CI setup would be even more
appreciated ;)
2020-12-22 15:56:34 +01:00
Anatol Belski
ffcc93e3e5 UPGRADING.INTERNALS: Document hash init signature changes [ci skip]
Signed-off-by: Anatol Belski <ab@php.net>
2020-12-13 16:52:01 +01:00