Commit Graph

706 Commits

Author SHA1 Message Date
Máté Kocsis
8d12f666ae
Fix registration of internal readonly child classes (#15459)
Currently, internal classes are registered with the following code:

INIT_CLASS_ENTRY(ce, "InternalClass", class_InternalClass_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ...;

This has worked well so far, except if InternalClass is readonly. It is because some inheritance checks are run by zend_register_internal_class_ex before ZEND_ACC_READONLY_CLASS is added to ce_flags.

The issue is fixed by adding a zend_register_internal_class_with_flags() zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.3 and below.
2024-08-24 12:36:54 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
96d572a18e Zend: Add helper for "cannot be empty" ValueError 2024-08-21 21:12:17 +01:00
Gina Peter Banyard
51379d66ec
Zend: Add object_init_with_constructor() API (#14440)
This will instantiate the object and execute its constructor with the given parameters.
2024-06-06 21:21:16 +01:00
Tim Düsterhus
c2a9166ef0
Merge branch 'PHP-8.3'
* PHP-8.3:
  Make the `fcc` parameter `const` in `zend_call_known_fcc` (#14259)
2024-05-17 16:14:45 +02:00
Tim Düsterhus
a89d22cc0c
Make the fcc parameter const in zend_call_known_fcc (#14259)
This makes it legal to call the function from a caller that only has a `const`
pointer to the `fcc` to prevent accidental modification.
2024-05-17 16:14:16 +02:00
Ilija Tovilo
1c30c5e707
Print location on class redeclaration
Fixes GH-13950
Closes GH-13999
2024-04-30 14:34:43 +02:00
Arnaud Le Blanc
fd73681c86
Fix GCC warning when using getThis() in a conditional (#13923)
Since GCC 12.x, using getThis() in a conditional yields a warning:

    <source>:12:22: warning: the comparison will always evaluate as 'true' for
                    the address of 'This' will never be NULL [-Waddress]
       12 |     return getThis() ? 2 : 3;
          |                      ^
2024-04-09 19:09:07 +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
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
Niels Dossche
345ac90eac
Introduce Z_PARAM_FUNC_EX2 to maintain compatibility (#12419)
Commit d86314939c added an additional parameter to Z_PARAM_FUNC_EX.
To maintain compatibility with third-party extensions, we keep
Z_PARAM_FUNC_EX as it used to be, and add Z_PARAM_FUNC_EX2 instead.
2023-10-11 19:55:00 +02:00
George Peter Banyard
d86314939c Zend: Add ZPP F type check for callables that do not free trampolines
As refetching it with the new FCC API does get tedious
2023-10-10 13:44:21 +01:00
Niels Dossche
8a812c3fda Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (PHP 8.4)
When we try to load an extension multiple times, we still overwrite the
type, module number, and handle. If the module number is used to
indicate module boundaries (e.g. in reflection and in dom, see e.g.
dom_objects_set_class_ex), then all sorts of errors can happen.

In the case of ext/dom, OP's error happens because the following
happens:
- The property handler is set up incorrectly in
  dom_objects_set_class_ex() because the wrong module number is
  specified. The class highest in the hierarchy is DOMNode, so the
  property handler is incorrectly set to that of DOMNode instead of
  DOMDocument.
- The documentElement property doesn't exist on DOMNode, it only exists
  on DOMDocument, so it tries to read using zend_std_read_property().
  As there is no user property called documentElement, that read
  operation returns an undef value.
  However, the type is still checked, resulting in the strange exception.

Solve this by changing the API such that the data is only overwritten if
it's owned data.

Closes GH-12246.
2023-09-20 21:02:51 +02:00
George Peter Banyard
80e90ad7ba
Add number or str ZPP macros 2023-06-18 13:09:03 +01:00
Ilija Tovilo
6f63d4b274
Fix -Wenum-int-mismatch warnings on gcc 13
Closes GH-11103
2023-04-20 16:04:59 +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
Dmitry Stogov
0e70693701 Revert "Zend/zend_types.h: move IS_* to zend_type_code.h"
This reverts commit 0270a1e54c.
2023-04-04 22:48:26 +03:00
Dmitry Stogov
61b19ba3f0 Revert "Zend/zend_types.h: move zend_uchar.h to zend_char.h"
This reverts commit 42577c6b6b.
2023-04-04 22:47:45 +03:00
Derick Rethans
78937c93ef Merge branch 'PHP-8.2' 2023-03-09 13:39:31 +00:00
Derick Rethans
a45bef0ac6 Merge branch 'PHP-8.1' into PHP-8.2 2023-03-09 13:37:19 +00:00
Derick Rethans
717335ec63 Fixed macro generation for variadics, which don't have a default value 2023-03-09 11:39:22 +00:00
Derick Rethans
792400bc68 Merge branch 'PHP-8.2' 2023-03-03 16:52:51 +00:00
Derick Rethans
bbcc1dadea Merge branch 'PHP-8.1' into PHP-8.2 2023-03-03 16:52:26 +00:00
Derick Rethans
7fcea9d260 Add missing ZEND_ARG_VARIADIC_OBJ_TYPE_MASK macro, and use consistent class_name variable name 2023-03-03 16:51:51 +00:00
Max Kellermann
42577c6b6b Zend/zend_types.h: move zend_uchar.h to zend_char.h
Prepare to fix the cyclic header dependency from `zend_string.h`.
2023-02-26 14:16:53 +00:00
Max Kellermann
0270a1e54c Zend/zend_types.h: move IS_* to zend_type_code.h
More decoupling of circular header dependencies.
2023-02-26 14:16:53 +00: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
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Christoph M. Becker
bf1cfc0753
Revert GH-10300
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit 68ada76f9a.
his reverts commit 45384c6e20.
This reverts commit ef7fbfd710.
This reverts commit 9b9ea0d7c6.
This reverts commit f15747c26b.
This reverts commit e883ba93c4.
This reverts commit 7e87551c37.
This reverts commit 921274d2b8.
This reverts commit fc1f528e5e.
This reverts commit 0961715cda.
This reverts commit a93f264526.
This reverts commit 72dd94e1c6.
This reverts commit 29b2dc8964.
This reverts commit 05c7653bba.
This reverts commit 5190e5c260.
This reverts commit 6b55bf228c.
This reverts commit 184b4a12d3.
This reverts commit 4c31b7888a.
This reverts commit d44e9680f0.
This reverts commit 4069a5c43f.
2023-01-16 12:22:54 +01:00
Max Kellermann
ef7fbfd710 Zend/zend_API: include cleanup 2023-01-15 15:07:58 +00:00
Dennis Buteyn
d0e3919458
Close GH-10217: Use strlen() for determining the class_name length
Closes GH-10231.
2023-01-05 17:16:21 +01:00
Max Kellermann
f5149535e8 Zend/zend_API: make several pointers const 2023-01-04 12:59:16 +00:00
George Peter Banyard
c4a0fc62a2
Fix zend_fcc_equals() with trampolines (#10012)
We cannot compare the function handler pointer directly for trampolines, as they may be reallocated
2022-12-02 12:34:11 +00:00
George Peter Banyard
32d3cae19f
Handle trampolines correctly in new FCC API + usages (#9877) 2022-11-22 17:12:53 +00:00
George Peter Banyard
de4cfff5f6 Add various APIs to handle FCC structures 2022-11-02 14:52:54 +00:00
George Peter Banyard
7c45b95894 Store a reference to closures in the FCC 2022-11-02 14:52:54 +00:00
George Peter Banyard
76fe989cd2 Add zend_call_function_with_return_value()
This API handles the common case of calling a userland function and passing a return value pointer.
This allows to remove the 'incorrect' usage of zend_fcall_info_call(fci, fcc, retval, NULL)
2022-10-21 17:26:21 +01:00
Bob Weinand
5a0b68bed7 Revert "Store default object handlers alongside the class entry"
This reverts commit 9e6eab3c13.

Reverted along a01dd9feda.
2022-09-14 11:18:14 +02:00
Bob Weinand
9e6eab3c13 Store default object handlers alongside the class entry
Object handlers being separate from class entries is a legacy inherited from PHP 5. Today it has little benefit to keep them separate: in fact, accessing object handlers usually requires not-so-safe hacks.
While it is possible to swap handlers in a custom installed create_object handler, this mostly is tedious, as well as it requires allocating the object handlers struct at runtime, possibly caching it etc..

This allows extensions, which intend to observe other classes to install their own class handlers.
The life cycle of internal classes may now be simply observed by swapping the class handlers in post_startup stage.
The life cycle of userland classes may be observed by iterating over the new classes in zend_compile_file and zend_compile_string and then swapping their handlers.

In general, this would also be a first step in directly tying the object handlers to classes. Especially given that I am not aware of any case where the object handlers would be different between various instances of a given class.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Tim Starling
11796229f2
Add libxml_get_external_entity_loader()
Add libxml_get_external_entity_loader(), which returns the currently
installed external entity loader, i.e. the value which was passed to
libxml_set_external_entity_loader() or null if no loader was installed
and the default entity loader will be used.

This allows libraries to save and restore the loader, controlling entity
expansion without interfering with the rest of the application.

Add macro Z_PARAM_FUNC_OR_NULL_WITH_ZVAL(). This allows us to get the
zval for a callable parameter without duplicating callable argument
parsing.

The saved zval keeps the object needed for fcc/fci alive, simplifying
memory management.

Fixes #76763.
2022-08-28 12:47:20 +01: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
George Peter Banyard
faa83f2f34
Convert some macros to zend_always_inline functions (#8288)
This doesn't have an effect really, but humans and IDEs can struggle to see through the macro soup when they first interact with PHP's source code.

Moreover, this reduces some of the macro expansion hell when they appear in compiler warnings.
2022-08-04 13:24:12 +01:00
George Peter Banyard
9115211ebf
Use uint32_t in Z_PARAM_VARIADIC_WITH_NAMED 2022-07-26 11:55:26 +01:00
Ilija Tovilo
7aadbcb8f4
GH-8344 Fetch properties of enums in const expressions 2022-07-18 23:52:28 +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
Ilija Tovilo
76fcd70c13
Fix enum preloading again (#8859) 2022-06-25 14:55:46 +02:00
George Peter Banyard
280b3db054
Use same type error wording for alias iterable in ZPP (#8838)
Follow-up from #7309 as I didn't change the ZPP TypeError wording.
2022-06-21 15:19:23 +01:00
twosee
b1223ee35f
Use get_active_function_or_method_name() for zend_forbid_dynamic_call() (#8762)
A slight imperfection in https://github.com/php/php-src/pull/7443.
As a zend_API, we should also consider other extensions that may call it in methods. This change will not break the behavior of php-src.
2022-06-16 12:02:53 +01:00
Jakub Zelenka
a6387fa383
Merge branch 'PHP-8.1' 2022-06-09 19:57:08 +01:00
Jakub Zelenka
976cbba76e Merge branch 'PHP-8.0' into PHP-8.1 2022-06-09 19:55:46 +01:00