Commit graph

587 commits

Author SHA1 Message Date
Alexandre Daubois
bf64dfcd99
Add an enum for HASH_KEY_IS_* constants (GH-19376) 2025-08-13 13:59:01 +02:00
Tim Düsterhus
7f4076bae0
RFC: Clone with v2 (#18747)
RFC: https://wiki.php.net/rfc/clone_with_v2

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-07-17 21:13:42 +02:00
DanielEScherzer
ddd33fd7e4
Generated arginfo headers: combine preprocessor conditional blocks (2) (#18667)
When global constants' or class constants' availability is based on some
preprocessor condition, the generated arginfo header files wrap the
declarations in the preprocessor `#if` conditional blocks, one per declaration,
even if they are in the same conditional block based on comments in the stub
file. Instead of having multiple conditional blocks one after the other with
the same condition, combine them into a single conditional block.
2025-06-22 14:35:28 -07:00
Christoph M. Becker
252b52ac5a
Improve COM ctor exception code for failing ProgIDs (GH-17673)
The `$module_name` of `com::__construct()` can be a ProgID, ClassID or
moniker.  We first try `CLSIDFromString()`, and if that fails, we go
ahead and try to treat the `$module_name` as a moniker.  If that also
fails, we throw an exception with the result of `MkParseDisplayName()`
what would just be `MK_E_SYNTAX` if given a ProgID.  This result is
highly confusing for the common case where a ProgID is given, which is
not registered (e.g. due to a typo).  In this case, we use the original
`HRESULT` (`CO_E_CLASSSTRING`) instead.
2025-02-14 17:44:43 +01:00
Christoph M. Becker
e4999275c2
Fix GH-17658: COMPersistHelper::LoadFromStream() can segfault (GH-17659)
* Fix GH-17658: COMPersistHelper::LoadFromStream() can segfault

The actual fix is trivial, but to be able to test the behavior we have
to introduce an own COM object, since existing persistable objects
likely implement `IPersistInit`, not only `IPersist`.  We also want to
avoid further test dependencies on possibly unavailable objects, such
as `Word.Application`.

To this purposes, we add a small COM in-process server, which may be
extended for other testing purposes.  We keep it simple by implementing
it in C++, but without using any more sophisticated frameworks like ATL.

This component needs to be built explicitly (`nmake comtest.dll`), and
also needs to be explicitly registered (`nmake register_comtest`).
When no longer needed, it is possible to unregister the component
(`nmake unregister_comtest`).
2025-02-11 12:42:25 +01:00
Christoph M. Becker
4373c601ea
Remove more unused local variables (GH-17688)
Since `pdo_odbc_ucs22utf8()` doesn't actually use the `stmt`, we drop
this parameter as well.
2025-02-03 20:06:29 +01:00
Christoph M. Becker
ef74ea08ce
Drop superfluous php_com_dotnet_object.ce (GH-17603)
* Drop superfluous php_com_dotnet_object.ce

This is readily available via the `zend_object` (i.e. `zo.ce`), so
there is no need to duplicate it.

There is also no need to assign the ce to the std object,
since this is done be `zend_object_std_init()` anyway.
2025-01-27 20:26:57 +01:00
Christoph M. Becker
aa76127d01
Address more Clang warnings (GH-17506)
We prefer clean solutions (such as declaring the proper type in the
first place, or introducing a portable format specifier) where easily
possible, but resort to casts otherwise.

We also port f1480ab14b.
2025-01-21 20:05:29 +01:00
Christoph M. Becker
26bf239e6d
Resolve -Wincompatible-pointer-types warnings (GH-17456)
The phpdbg issue is a real issue, although it's unlikely that harm can
be done due to stack alignment and little-endianess.  The others seem
to be more cosmetic.
2025-01-13 10:54:13 +01:00
Christoph M. Becker
1d2c544cca
Refactor disp_invokeex() to avoid superfluous recheck (GH-17001)
Since we already know the method is callable, we can just call it
directly.
2024-12-01 18:55:38 +01:00
Christoph M. Becker
8b68274319
Fix method calls for PHP objects wrapped in variant
As is, methods of PHP can never be called, because we're first trying
to read the property with the name of the method.

We fix this by first checking for `DISPATCH_METHOD` and treat that as
method call, if the method would be callable.  Only otherwise we try to
access the respective property.

It needs to be noted that this breaks code which accesses a property of
an object, which defines a method of the same name.  However, instances
of such classes should never be wrapped in variants, because this can't
be distinguished by COM anyway.

Closes GH-16945.
2024-11-30 12:26:07 +01:00
Christoph M. Becker
38a28993fc
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16991: Getting typeinfo of non DISPATCH variant segfaults
2024-11-29 16:32:36 +01:00
Christoph M. Becker
8ea042d954
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16991: Getting typeinfo of non DISPATCH variant segfaults
2024-11-29 16:32:12 +01:00
Christoph M. Becker
a4874bb418
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16991: Getting typeinfo of non DISPATCH variant segfaults
2024-11-29 16:30:01 +01:00
Christoph M. Becker
9bae8933a3
Fix GH-16991: Getting typeinfo of non DISPATCH variant segfaults
We must not assume that any `VARIANT` implements `IDispatch`.

Closes GH-16992.
2024-11-29 16:29:11 +01:00
Christoph M. Becker
03cbb3ee58
Build com_dotnet shared by default
The official Windows builds and CI are doing this for ages, so it
appears to be overdue to finally switch the actual default.

Closes GH-16300.
2024-11-18 20:50:22 +01:00
Christoph M. Becker
c0136f0cb9
Avoid dl() in bug77578.phpt (GH-16663)
Avoid dl() in bug77578.phpt

`dl()` has known issues regarding permanent strings[1], so we better
avoid it, even if that means that we need to spawn two sub-processes.

[1] <https://github.com/php/php-src/issues/9196>
2024-11-01 22:13:02 +01:00
Christoph M. Becker
b14076a4e6
Fix property access of PHP objects wrapped in variant
First, we fix the long standing issue that property access throws a
`com_exception` ("0x80020003: member not found), because the `HRESULT`
was not properly set after accessing the property.

Next, we fix an issue introduced as of PHP 7.0.0, where the string
length for write access had been properly adapted, but the string
length for read access had been overlooked.

Then we fix an issue introduced as of PHP 8.0.0, where new `HashTable`s
no longer set `nNextFreeElement` to zero, but to `ZEND_LONG_MIN`.  This
doesn't work well with the `DISPID` lookup, which is a `LONG`.

Finally we fix a potential double-free due to erroneously destroying
the return value of `zend_read_property()`.

Closes GH-16331.
2024-10-11 16:50:35 +02:00
Christoph M. Becker
8ca1313e38
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix out of bound writes to SafeArray data
2024-10-09 21:16:52 +02:00
Christoph M. Becker
42a2b046fe
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix out of bound writes to SafeArray data
2024-10-09 21:16:29 +02:00
Christoph M. Becker
edb0af6f10
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix out of bound writes to SafeArray data
2024-10-09 21:15:35 +02:00
Christoph M. Becker
1ee56bdd5a
Fix out of bound writes to SafeArray data
Converting PHP arrays to Variants originally supported almost arbitrary
numeric arrays, possibly filling gaps with NULL values.  This is broken
as of PHP 7.0.0[1] so that the SafeArray only has as many elements as
the PHP array.  Thus, unless the array is a list, some elements may be
written outside of the SafeArray data.

To avoid breaking userland code after that long time, we do not restore
the original behavior, but instead only suppress the erroneous writes.

To avoid the need to split the regression test for 32bit and 64bit
Windows, we suppress the "max number 4294967295 of elements in safe
array exceeded" warning, which only occurs for 64bit versions.

[1] <c865472ef0>

Closes GH-16309.
2024-10-09 21:14:44 +02:00
DanielEScherzer
41996e8d4f
ext/[cd]*: fix a bunch of typos (#16298)
Only functional change is the renaming of the functions
`dom_document_substitue_entities_(read|write)` to replace `substitue` with
`substitute`.
2024-10-09 17:40:42 +02:00
Christoph M. Becker
2f52dbd7b7
Prevent direct instantiation of com_safearray_proxy (GH-10278)
* Prevent direct instantiation of com_safearray_proxy

The `com_safearray_proxy` class is meant for internal usage, but so far
it was possible to instantiate it from userland, although that made no
sense.  However, a while ago there was a relevant change[1], namely
that its `default_object_handlers` are now assigned when the class is
registered, while previously they only have been assigned when an
instance had been created internally.  So now when freeing a manually
created object, `free_obj()` is called, although the object never has
been properly initialized (causing segfaults).

We fix this by introducing a `create_object()` handler which properly
initializes the object with dummy values.  Since a manually created
`com_safearray_proxy` still does not make sense, we disallow its
instantiation.

[1] <94ee4f9834>

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-10-07 11:35:59 +02:00
DanielEScherzer
53cb89670c
Generated arginfo header files: remove empty zend_function_entry arrays (#15705)
When a class (or enum) has no methods, rather than using an array that only
contains `ZEND_FE_END`, use `NULL` for the functions. The implementation of
class registration for internal classes, `do_register_internal_class()` in
zend_API.c, already skips classes where the functions are `NULL`. By removing
these unneeded arrays, we can reduce the size of the header files, while also
removing an unneeded call to zend_register_functions() for each internal class
with no extra methods.
2024-09-03 23:19:53 +02:00
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
Peter Kokot
660a860f26
Fix GH-15501: Windows HAVE_<header>_H macros defined to 1 or undefined (#15508)
Previously the CHECK_HEADER_ADD_INCLUDE function defined the
`HAVE_<header>_H` preprocessor macros to value 0 or 1 whether the
`<header.h>` file was found. This syncs it with Autotools build system
where most of these macros are either undefined or defined to 1.

In possible edge cases where such macros might be intentionally used
like this without being aware that HAVE_HEADER_H can be 0 or 1 on
Windows:

| #ifdef HAVE_HEADER_H
| ...
| #endif

there is backwards incompatibility for PECL extensions in case the
header wouldn't exist on Windows such code wouldn't execute. However,
this is considered a bug if such case is present. From the Autotools
point of view, the check is correct though and should be used with
ifdef/defined() checks.

Help text is also synced to Autotools style:
`Define to 1 if you have the <header.h> header file.`
2024-08-20 21:10:50 +02:00
Christoph M. Becker
4b2dc58651
Fix format specifiers and arguments in com_dotnet (GH-15398)
This is mostly about minor glitches (signedness or length confusion),
but also fixes two occasions where `zend_string`s still have been
regarded as `char *`.

We also add a regression test case for failing property name lookup,
since that is the most relevant issue we're fixing here.
2024-08-15 10:59:10 +02:00
Niels Dossche
e1c8329b8c Update TODOs in com_dotnet 2024-08-10 23:24:26 +02:00
Niels Dossche
3f54be8053 Get rid of le_dispatch 2024-08-10 23:24:26 +02:00
Niels Dossche
b7be849fad Get rid of le_istream 2024-08-10 23:24:26 +02:00
Christoph M. Becker
ee02e4be6a
Fix violation of the one definition rule in ext/com_dotnet (GH-15327)
The definition of the class entries in the internal header file is not
correct, since that file is included several times, and even the
comment above the definition hints at com_extension.c where the actual
definition is.  We fix this by declaring these variables as `extern`.
2024-08-10 15:27:32 +02:00
Peter Kokot
f66feaec0f
Sync HAVE_<extension> help texts (#15167)
This syncs all help texts of extension preprocessor macros to the same
style "Define to 1 if the PHP extension '<ext>' is available.".
[skip ci]
2024-08-02 01:41:47 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Niels Dossche
3165456980
Include HRESULT error code if native .NET initialization fails (#14317)
This is a local patch I used to figure out why it didn't work on my
machine. Without the error codes: good luck to figure out what's wrong.
2024-05-25 00:20:07 +02:00
Niels Dossche
dbbd01235d
Merge branch 'PHP-8.3'
* PHP-8.3:
  Skip .NET tests if mscoree is not available (#14281)
2024-05-20 23:28:02 +02:00
Niels Dossche
59744a7fc0
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Skip .NET tests if mscoree is not available (#14281)
2024-05-20 23:27:51 +02:00
Niels Dossche
98288a27bc
Skip .NET tests if mscoree is not available (#14281) 2024-05-20 23:26:52 +02:00
Niels Dossche
700fbca58d
Change getThis() into ZEND_THIS where possible (#13641) 2024-03-08 22:19:06 +01: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
Máté Kocsis
10957e498c
Do not generate frameless info items when func info generation is disabled
While here, I fixed newlines around arginfo and function entry generation. Previously, newlines were repeated.
2024-02-18 11:39:00 +01:00
Peter Kokot
085da2725f Merge branch 'PHP-8.3'
* PHP-8.3:
  Use EXTENSIONS instead of SKIPIF sections in *.phpt
2024-01-31 11:20:56 +01:00
Peter Kokot
8d5fc8d23f Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use EXTENSIONS instead of SKIPIF sections in *.phpt
2024-01-31 11:20:44 +01:00
Peter Kokot
218a93b898 Use EXTENSIONS instead of SKIPIF sections in *.phpt
This also fixes skipped tests due to different naming "zend-test"
instead of "zend_test" and "PDO" instead of "pdo":

- ext/dom/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/simplexml/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/xmlreader/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/zend_test/tests/observer_sqlite_create_function.phpt

EXTENSIONS section is used for the Windows build to load the non-static
extensions.

Closes GH-13276
2024-01-31 11:18:21 +01:00
David CARLIER
9726721560
general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00:00
Ilija Tovilo
efc73f24c3
Revert "Call cast_object handler from get_properties_for"
This reverts commit 4182813ebf.
2023-08-07 12:58:12 +02:00
Ilija Tovilo
4182813ebf
Call cast_object handler from get_properties_for
Fixes GH-11547
Closes GH-11583
2023-07-25 17:59:44 +02:00
Ilija Tovilo
1a0ef2c1cc
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Closes GH-11604
2023-07-17 22:32:41 +02:00
Ilija Tovilo
ad1b70d67e
Revert "Revert "Remove name field from the zend_constant struct (#10954)""
This reverts commit 9f4bd3040d.
2023-07-04 16:42:40 +02:00
Máté Kocsis
9f4bd3040d
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Fix GH-11423
2023-07-03 15:16:24 +02:00