Commit graph

243 commits

Author SHA1 Message Date
Niels Dossche
250e0ffe90
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16013 and bug #80857: Big endian issues
2024-12-25 21:33:43 +01:00
Niels Dossche
99a14b805e
Fix GH-16013 and bug #80857: Big endian issues
The FFI call return values follow widening rules.
We must widen to `ffi_arg` in the case we're handling a return value for types shorter than the machine width.
From http://www.chiark.greenend.org.uk/doc/libffi-dev/html/The-Closure-API.html:
> In most cases, ret points to an object of exactly the size of the type specified when cif was constructed.
> However, integral types narrower than the system register size are widened.
> In these cases your program may assume that ret points to an ffi_arg object.

If we don't do this, we get wrong values when reading the return values.

Closes GH-17255.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2024-12-25 21:33:14 +01:00
Niels Dossche
d1ed8beb2f
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak on ZEND_FFI_TYPE_CHAR conversion failure
2024-12-23 14:23:09 +01:00
Niels Dossche
a7f7e169d6
Fix memory leak on ZEND_FFI_TYPE_CHAR conversion failure
The success path frees tmp_str, but the error path does not.

Closes GH-17243.
2024-12-23 14:22:18 +01:00
Niels Dossche
226a0c5131
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix bug #79075: FFI header parser chokes on comments
2024-12-09 22:30:23 +01:00
Niels Dossche
612a34cbec
Fix bug #79075: FFI header parser chokes on comments
The directives for FFI should be first in the file, which is fine,
however sometimes there can be comments or whitespace before or between
these defines. One practical example is for license information or when
a user adds newlines "by accident". In these cases, it's quite confusing
that the directives do not work properly.
To solve this, make the zend_ffi_parse_directives() aware of comments.

Closes GH-17082.
2024-12-09 22:29:02 +01:00
Niels Dossche
7a7ab73d3b
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
2024-10-14 19:24:17 +02:00
Niels Dossche
c924af0d6b
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
2024-10-14 19:24:01 +02:00
Niels Dossche
ec8a24f746
Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] 35c8a010c6/Zend/zend_object_handlers.h (L231C1-L231C64)

Closes GH-16401.
2024-10-14 19:23:04 +02:00
Peter Kokot
888eb370cf
Fix -Wundef/C4668 warnings (#15853)
- ZTS is either undefined or defined (to 1)
- PHP_WIN32 is either undefined or defined (to 1)
- HAVE_LIBEDIT is either undefined or defined (to 1)
2024-09-14 11:28:32 +02:00
Bob Weinand
25d761623c
Make internal run_time_cache a persistent allocation (#15040)
We also add zend_map_ptr_static, so that we do not incur the overhead of constantly recreating the internal run_time_cache pointers on each request.
This mechanism might be extended for mutable_data of internal classes too.
2024-09-07 01:45:26 +02:00
Arnaud Le Blanc
58aa6fc830
Lazy objects
RFC: https://wiki.php.net/rfc/lazy-objects

Closes GH-15019
2024-08-30 17:30:03 +02:00
Niels Dossche
77f870e98e
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14286 (ffi enum type (when enum has no name) make memory leak)
2024-07-22 17:45:28 +02:00
Niels Dossche
b2963e96ee
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14286 (ffi enum type (when enum has no name) make memory leak)
2024-07-22 17:45:20 +02:00
Niels Dossche
c0de7214aa
Fix GH-14286 (ffi enum type (when enum has no name) make memory leak)
For top-level anonymous type definition we never store the declaration anywhere
else nor the type anywhere else.
The declaration keeps owning the type and it goes out of scope.
For anonymous fields this gets handled by the add_anonymous_field code that
removes the type from the declaration.
This patch does something similar in the parsing code when it is
detected we're dealing with an anonymous enum in a top-level declaration.

Closes GH-14839.
2024-07-22 17:44:47 +02:00
Niels Dossche
889f308e01
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
2024-05-14 19:56:05 +02:00
Niels Dossche
0e98a05a3d
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
2024-05-14 19:52:19 +02:00
Niels Dossche
ebd1a36670
Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
Some modules may reset _fmode, which causes mangling of line endings.
Always be explicit like we do in other places where the native open call
is used.

Closes GH-14218.
2024-05-14 19:49:22 +02:00
Niels Dossche
8aec95e23f
Fix build on Clang 18 (#14136)
Clang 18 only allows counted_by to work on real flexible array members,
not ones with a zero size. Otherwise you get errors like:
```
ext/opcache/jit/zend_jit_ir.c:149:12: error: 'counted_by' only applies to C99 flexible array members
```
2024-05-04 19:17:42 +02:00
Niels Dossche
b9a2533cb3
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix gcc-14 Wcalloc-transposed-args warnings
2024-04-01 20:34:44 +02:00
Niels Dossche
e34c86ce1a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix gcc-14 Wcalloc-transposed-args warnings
2024-04-01 20:34:37 +02:00
Cristian Rodríguez
18d70db091
Fix gcc-14 Wcalloc-transposed-args warnings
gcc-14 and later warns of inverted arguments in calloc or
calloc-like __alloc_size__ annotated functions.

Closes GH-13818.
2024-04-01 20:34:14 +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
David CARLIER
9726721560
general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00: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
1fc85a30b3 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12905: FFI::new interacts badly with observers
2023-12-19 15:59:43 +01:00
Niels Dossche
87c906c33a Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12905: FFI::new interacts badly with observers
2023-12-19 15:59:35 +01:00
Niels Dossche
c727f29942 Fix GH-12905: FFI::new interacts badly with observers
Because these functions are copied and not properly registered (which we
can't), the observer code doesn't add the temporaries on startup.
Add them via a callback during startup.

Closes GH-12906.
2023-12-19 15:59:01 +01:00
Jakub Zelenka
d6299206dd
Merge branch 'PHP-8.3' 2023-12-15 14:14:15 +00:00
Jakub Zelenka
1b8be9acf0
Merge branch 'PHP-8.2' into PHP-8.3 2023-12-15 14:13:41 +00:00
Jakub Zelenka
40ccc8ea7e
Fix GH-9698: stream_wrapper_register crashes with FFI\CData provided as class
Closes GH-12926
2023-12-15 14:11:56 +00:00
Dmitry Stogov
889dadd636 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed regression introduced by https://github.com/php/php-src/pull/9601
2023-11-22 21:25:45 +03:00
Dmitry Stogov
adaf726373 Fixed regression introduced by https://github.com/php/php-src/pull/9601 2023-11-22 21:25:15 +03:00
David CARLIER
cc2bf11951
zend: introducing ZEND_ELEMENT_COUNT for struct's dynamic arrays. (#12650)
zend: introducing ZEND_ELEMENT_COUNT for struct's dynamic and flexible arrays.

It is mostly for ubsan and helping array bound checking.
2023-11-13 12:42:45 +00:00
Arnaud Le Blanc
d30c78d7f9 Merge branch 'PHP-8.3'
* PHP-8.3:
  [ci skip] NEWS
  [ci skip] NEWS
  [ci skip] NEWS
  Fix segfault caused by weak references to FFI objects (#12488)
2023-10-28 15:06:36 +02:00
Arnaud Le Blanc
198f613401 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix segfault caused by weak references to FFI objects (#12488)
2023-10-28 15:05:55 +02:00
Arnaud Le Blanc
7a617ee223 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix segfault caused by weak references to FFI objects (#12488)
2023-10-28 15:03:17 +02:00
sji
04b35a44ce
Fix segfault caused by weak references to FFI objects (#12488)
Thank you!
2023-10-28 14:59:06 +02:00
Ilija Tovilo
692cea5cbc
Use zend_error_noreturn for E_ERROR consistently
To be clear, these already don't return. zend_error_noreturn just hints at this
fact through the ZEND_NORETURN attribute.

Closes GH-12204
2023-09-14 11:44:55 +02:00
Niels Dossche
0b9702c9ed Implement GH-11934: Allow to pass CData into struct and/or union fields
Co-authored-by: KapitanOczywisty <44417092+KapitanOczywisty@users.noreply.github.com>

Closes GH-11935.
2023-08-29 17:01:10 +02:00
Ilija Tovilo
ac99f7306c
Fix merge conflict
Sorry...
2023-07-21 11:17:01 +02:00
Ilija Tovilo
84cb42e0f1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix leaking definitions on FFI::cdef()->new()
2023-07-21 10:43:13 +02:00
Ilija Tovilo
88fab26365
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix leaking definitions on FFI::cdef()->new()
2023-07-21 10:42:42 +02:00
Ilija Tovilo
11d6bea98a
Fix leaking definitions on FFI::cdef()->new()
Previously, FFI_G(symbols) and FFI_G(tags) were never cleaned up when calling
new on an existing object. However, if cdef() is called without parameters these
globals are NULL and might be created when new() creates new definitions. These
would then be discarded without freeing them.

Closes GH-11751
2023-07-21 10:42:19 +02:00
Máté Kocsis
4acf0084dc Deprecate calling FFI::cast(), FFI::new(), and FFI::type() statically 2023-07-18 12:59:21 +02:00
Max Kellermann
d5c649b36b
zend_compiler, ...: use uint8_t instead of zend_uchar (#10621)
`zend_uchar` suggests that the value is an ASCII character, but here,
it's about very small integers.  This is misleading, so let's use a
C99 integer instead.

On all architectures currently supported by PHP, `zend_uchar` and
`uint8_t` are identical.  This change is only about code readability.
2023-02-23 14:56:54 +00:00
Max Kellermann
d46dea169c
Make globals const (part 2) (#10610)
* Zend/zend_enum: make `forbidden_methods` static+const

* main/php_syslog: make `xdigits` static

* sapi/fpm: make several globals `const`

* sapi/phpdbg: make `OPTIONS` static

* sapi/phpdbg/help: make help texts const

* sapi/cli: make `template_map` const

* ext/ffi: make `zend_ffi_types` static

* ext/bcmath: make `ref_str` const

* ext/phar: make several globals static+const
2023-02-18 19:52:53 +00:00
Dmitry Stogov
851e4623f5 Make C functions returning "void" to return PHP "null"
In PHP-2.0 and below we by mistake returned "obcect(FFI\CData:void)#2 (0) {}".
We decided not to fix this in PHP-2.0 and below to aboid BC breaks.
2023-02-13 22:42:39 +03:00
Dmitry Stogov
2abb5850ba Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix assertion failure when var_dump'ing void FFI result (#10568)
2023-02-13 22:38:52 +03:00
Dmitry Stogov
cec528d06b Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix assertion failure when var_dump'ing void FFI result (#10568)
2023-02-13 22:38:43 +03:00