Commit Graph

399 Commits

Author SHA1 Message Date
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
f39b5c4c25
Close PHP tags in tests
Closes GH-12422
2023-10-18 17:34:10 +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
Máté Kocsis
6988973bc6
Declare type for ext/ffi internal class constants
Since the relevant classes are final, it's straightforward to declare the type of these class constants
2023-07-18 10:09:26 +02:00
Ilija Tovilo
7b355e8d34
Revert "Merge branch 'PHP-8.2'"
This reverts commit 45a3f178dc, reversing
changes made to b2a54bc6af.
2023-07-04 09:18:49 +02:00
Máté Kocsis
45a3f178dc
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs

Closes GH-10170
2023-07-03 11:17:08 +02:00
George Peter Banyard
82e761eaac
Fix [-Wenum-int-mismatch] compiler warnings (#11352) 2023-06-01 13:27:46 +01:00
Ilija Tovilo
50f58c8923
Add ASAN XLEAK support
Only disable LSAN instead of skipping the test. This way we can still detect
memory issues which is arguably more important anyway.

Closes GH-10996
2023-04-03 08:02:19 +02:00
Ilija Tovilo
f1333bc9fe
Merge branch 'PHP-8.2'
* PHP-8.2:
  Reset EG(trampoline).op_array.last_var that FFI may modify
2023-03-27 23:00:12 +02:00
Ilija Tovilo
69c57bea3d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reset EG(trampoline).op_array.last_var that FFI may modify
2023-03-27 22:59:58 +02:00
Ilija Tovilo
4e0bd03681
Reset EG(trampoline).op_array.last_var that FFI may modify
Closes GH-10916
2023-03-27 22:59:00 +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
Niels Dossche
1a5fc6e1a3
Fix assertion failure when var_dump'ing void FFI result (#10568) 2023-02-13 22:38:28 +03:00
rj1
d2cdfdbe44
fixed some misspellings (#10503) 2023-02-04 07:03:10 +00:00
Tyson Andre
ab87283118 Merge branch 'PHP-8.2' 2023-02-03 09:23:48 -05:00
Tyson Andre
e3f04ddb0b Merge branch 'PHP-8.1' into PHP-8.2 2023-02-03 09:18:03 -05:00
Tyson Andre
fe2dc2b481
Avoid crash for reset/end/next/prev() on ffi classes (#9711)
(And any PECLs returning `zend_empty_array` in the handler->get_properties
overrides)

Closes GH-9697

This is similar to the fix used in d9651a9419
for array_walk.

This should make it safer for php-src (and PECLs, long-term) to return
the empty immutable array in `handler->get_properties` to avoid wasting memory.
See https://github.com/php/php-src/issues/9697#issuecomment-1273613175

The only possible internal iterator position for the empty array is at the end
of the empty array (nInternalPointer=0).
The `zend_hash*del*` helpers will always set nInternalPointer to 0 when an
array becomes empty,
regardless of previous insertions/deletions/updates to the array.
2023-02-03 09:17:33 -05:00
Dmitry Stogov
4cd929877e Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect bitshifting and masking in ffi bitfield (#10403)
2023-01-24 09:15:44 +03:00
Dmitry Stogov
d5b307c434 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect bitshifting and masking in ffi bitfield (#10403)
2023-01-24 09:15:27 +03:00
Niels Dossche
560ca9c7ae
Fix incorrect bitshifting and masking in ffi bitfield (#10403)
When a uint8_t is bitshifted to the left, it is actually promoted to an
int. For the current code this has the effect of a wrong sign-extension,
and the result will also wrongly become zero when insert_pos >= 32.
Fix this by adding an explicit cast.
Furthermore, the partial prefix byte mask was computed incorrectly: the
byte is already shifted so the mask should not account for the shift.
2023-01-24 09:15:03 +03: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
Máté Kocsis
7a9726d651
Merge branch 'PHP-8.2'
- PHP-8.2:
  Customize the link of some constants in the manual
2023-01-19 09:06:39 +01:00
Máté Kocsis
148ac364e9 Customize the link of some constants in the manual
These changes are necessary because the links which are generated by default are already taken.
2023-01-19 09:05:32 +01:00
Marcos Marcolin
6f785b033d
chore: remove semicolon left over.
Closes GH-10236.
2023-01-06 11:14:22 +01:00
Thomas PIRAS
289822d3ad
Add a proper error message for ffi load
We call dlerror when a library failed to load properly.

Closes GH-9913.
2022-11-28 16:19:54 +01:00
Ilija Tovilo
86af42be1b
Merge branch 'PHP-8.2'
* PHP-8.2:
  Migrate i386 to GitHub actions
2022-11-03 14:40:35 +01:00
Ilija Tovilo
b08901b63f
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Migrate i386 to GitHub actions
2022-11-03 14:37:59 +01:00
Ilija Tovilo
ed1e703716
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Migrate i386 to GitHub actions
2022-11-03 14:37:17 +01:00
Ilija Tovilo
75970077b0
Migrate i386 to GitHub actions
Closes GH-9856
2022-11-03 14:34:54 +01:00
Dmitry Stogov
4650a8c710 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2022-10-10 11:25:42 +03:00
Dmitry Stogov
626e909877 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2022-10-10 11:25:33 +03:00
Dmitry Stogov
fa2c519544 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2022-10-10 11:25:23 +03:00
Dmitry Stogov
d9651a9419 Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array 2022-10-10 11:21:05 +03:00
Ilija Tovilo
d4ad9b7289
Throw in FFI::addr() when referencing temporary pointer
Closes GH-9601
2022-09-26 23:15:38 +02:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
Arnaud Le Blanc
0a9a8a90ae
Fix GH-9139: Allow FFI in opcache.preload when opcache.preload_user=root (#9473) 2022-09-09 11:00:57 +02:00
George Peter Banyard
163c0b5f4c Merge branch 'PHP-8.2' 2022-09-06 10:42:34 +01:00
George Peter Banyard
1ad59b32c2 Update INI validator and displayers depending on INI type
Closes GH-9451
2022-09-06 10:33:34 +01:00
Tim Düsterhus
03fd405423
Use php_info_print_table_header for actual column headers only (#9485)
Using php_info_print_table_header() for "Foo: bar" looks odd and out of place,
because the whole line is colored. It is also questionable from a HTML
semantics point of view, because it does not described the columns that follow.

The use of this across extensions is inconsistent. It was part of the skeleton,
but ext/date or ext/json already use a regular row.
2022-09-06 08:48:22 +02:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Dmitry Stogov
04d5faed23 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix order of checks to throw exception with better message
2022-08-11 09:32:18 +03:00
Dmitry Stogov
18183ff9c7 Fix order of checks to throw exception with better message
This clarifies the "->cdata" meaning.
2022-08-11 09:30:47 +03:00
Adam Saponara
8cf9c2f200
Fix GH-9090: Support assigning function pointers in FFI
Closes GH-9107.
2022-07-27 10:42:25 +02:00
Máté Kocsis
e328c68305
Rename @cname to @cvalue in stubs (#9043)
@cname currently refers to the constant name in C. However, it is not always a (constant) name, but sometimes a function invocation, so naming it as @cvalue would be more appropriate.
2022-07-19 15:11:42 +02: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
Máté Kocsis
413cbdf72f
Declare FFI::__BIGGEST_ALIGNMENT__ in stubs as well 2022-06-04 09:59:29 +02:00
Máté Kocsis
d476da7818
Declare ext/ffi constants in stubs (#8695) 2022-06-04 09:51:27 +02:00
Bob Weinand
7f34afc32b Merge branch 'PHP-8.1' 2022-04-24 18:05:08 +02:00
Bob Weinand
ff6b813557 Merge branch 'PHP-8.0' into PHP-8.1 2022-04-24 18:04:37 +02:00
Bob Weinand
a74b865123 Add missing SKIPIF for new ext/ffi test 2022-04-24 18:02:46 +02:00
Bob Weinand
ab1d5a9d2a Merge branch 'PHP-8.1' 2022-04-24 14:55:01 +02:00
Bob Weinand
01b91cb3b1 Merge branch 'PHP-8.0' into PHP-8.1 2022-04-24 14:53:51 +02:00
Bob Weinand
2397e7685e Fix GH-8433: Assigning function pointers to structs in FFI leaks memory 2022-04-24 14:53:18 +02:00
Christoph M. Becker
ede1568967
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-7867: FFI::cast() from pointer to array is broken
2022-01-11 00:00:31 +01:00
Christoph M. Becker
1632ebb542
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-7867: FFI::cast() from pointer to array is broken
2022-01-10 23:59:55 +01:00
Christoph M. Becker
703cac33db
Fix GH-7867: FFI::cast() from pointer to array is broken
Casting from pointer to array is special, so we must not fall back to
the general FFI casting.  There is a particular issue regarding the
size comparison, namely that the pointer size is always 8 for 64bit
architectures, but the size of an array is determined by its
declaration, so as is casting a pointer to an array with more than 8
elements would fail, but casting to an array with less than 9 elements
succeeds, but the internal pointer would point to some arbitrary
memory.

We fix this by properly supporting the cast.  An alternative would be
to deny this kind of cast generally, since it is not necessarily safe.
However, FFI isn't necessarily safe anyway.

We also check pointer/array type compatibility when casting.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-7876.
2022-01-10 23:58:39 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
George Peter Banyard
875a43a42c Voidify zend_ffi_zval_to_bit_field() 2021-09-30 14:33:48 +01:00
George Peter Banyard
8d9306327a Use bool/zend_result instead of int in FFI
Also use == FAILURE instead of != SUCCESS
2021-09-30 14:33:48 +01:00
Dmitry Stogov
b4a5bc4a62 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed error message
2021-09-15 15:01:08 +03:00
Dmitry Stogov
23327bf4b3 Fixed error message 2021-09-15 15:00:49 +03:00
Dmitry Stogov
6f65a1b263 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed error message
2021-09-15 14:59:14 +03:00
Dmitry Stogov
de20a89b06 Fixed error message 2021-09-15 14:58:55 +03:00
Dmitry Stogov
46c09a34d5 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
2021-09-15 14:53:00 +03:00
Dmitry Stogov
594cba7f8e Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
2021-09-15 14:49:35 +03:00
Dmitry Stogov
0badc7de96 Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined) 2021-09-15 14:48:33 +03:00
Bob Weinand
1440d15e00
Add missing zend_test requirement to ffi test for bug80847 2021-08-18 17:16:54 +02:00
Máté Kocsis
2378f35787
Use single line phpdoc in stubs where possible 2021-07-20 13:16:56 +02:00
Joe Watkins
570d9b63e9
Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Máté Kocsis
b382883696
Indent stubs inside global namespace blocks (#7261) 2021-07-20 10:23:58 +02:00
Nikita Popov
02b803a5fd Rename getStructFieldOffset/Type() parameter
By convention, parameter names of camel case methods should also
be camel case, i.e. the name should be $fieldName rather than
$field_name.

However, following GH-7236, which changed $arg_index to just $index,
this also changes $field_name to just $name. The fact that it is
a field name is obvious from context.
2021-07-14 15:13:42 +02:00
Tyson Andre
efbdcb8e49
Rename FFI getFuncArg* to getFuncParameter*, $arg_index->$index (#7236)
PHP is already already using "Parameter" instead of "Argument" for reflection on types elsewhere.

Parameter is used to refer to the function declarations
(AST_PARAM internally in the AST, ReflectionFunctionAbstract->getParameters(),
etc.)
Argument is used to refer to expressions passed to the functions by the caller
(ArgumentCountError, etc.).
(Error messages were also changed in php 8.x to refer to passing too many arguments to a
function)

Other languages use similar definitions,
e.g. https://developer.mozilla.org/en-US/docs/Glossary/Parameter
2021-07-14 09:12:25 -04:00
Dmitry Stogov
a2845e32cb FFI::CType reflection API 2021-07-13 13:13:51 +03:00
Nikita Popov
1cba7764b4
Remove zend_atoi() (#7232)
It's the same as (int) zend_atol() -- it doesn't try to do anything
integer size specific. Canonicalize to one function in preparation
for renaming zend_atol() to something less misleading.

FFI test is adjusted to use a zend_test function. It just calls
zend_atol() internally, but could really be anything.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2021-07-13 09:22:31 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Nikita Popov
62cb7dc4f5 Disable FFI preload tests with opcache.preload_user 2021-05-19 10:36:55 +02:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
Max Semenik
bd9f4fa676 Migrate skip checks to --EXTENSIONS--, p2
For rationale, see https://github.com/php/php-src/pull/6787

Make extension checks lowercase, add a special case for opcache
that has internal name not matching .so filename.

Extensions migrated in part 2:
* dom
* exif
* fileinfo
* ffi
2021-04-01 12:08:24 +01:00
Dmitry Stogov
6800f0a3c2 XFAIL on WIN64 because of problem in libffi
(cherry picked from commit 6689bedd17)
2021-03-24 13:57:31 +01:00
Dmitry Stogov
6689bedd17 XFAIL on WIN64 because of problem in libffi 2021-03-19 12:19:24 +03:00
Dmitry Stogov
c8a8c47f7e Merge branch 'PHP-8.0'
* PHP-8.0:
  Additional fix for bug #80847. On x86_64 part of structure may be passed in CPU registers.
2021-03-18 16:16:29 +03:00
Dmitry Stogov
465cfc499b Additional fix for bug #80847.
On x86_64 part of structure may be passed in CPU registers.
2021-03-18 16:13:42 +03:00
Dmitry Stogov
9373d159c2 "zend-test" was renamed to "zend_test" 2021-03-18 14:36:46 +03:00
Dmitry Stogov
1494e87bd0 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80847 (CData structs with fields of type struct can't be passed as C function argument)
2021-03-17 09:56:07 +03:00
Dmitry Stogov
38ebb55c7c Fixed bug #80847 (CData structs with fields of type struct can't be passed as C function argument) 2021-03-17 09:55:20 +03:00
Máté Kocsis
bf0f6aaf18
Improve class entry generation
Related to GH-6701
2021-02-16 13:09:56 +01:00
Máté Kocsis
45fa7596dc
Add missing classes to stubs 2021-02-09 22:38:06 +01:00
Máté Kocsis
99b08ac281
Implicitly enable function entry generation when class entry generation is enabled
Closes GH-6675
2021-02-09 13:37:24 +01:00