[php-src] master: Merge branch 'PHP-8.6'
| From: | ndossche | Date: | Wed, 25 Nov 2026 22:06:05 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144184@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-11-25T23:05:53+01:00
Commit: https://github.com/php/php-src/commit/e6077077d8194ed76ed7ed28a031b00ab85e4006
Raw diff: https://github.com/php/php-src/commit/e6077077d8194ed76ed7ed28a031b00ab85e4006.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix GH-25558: FFI: struct with an enum field passed by value is described to libffi with a void
element
Changed paths:
A ext/ffi/tests/bug25558.phpt
M ext/ffi/ffi.c
Diff:
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
index 8e2a205838cf..ff3b753d9490 100644
--- a/ext/ffi/ffi.c
+++ b/ext/ffi/ffi.c
@@ -349,7 +349,11 @@ static ffi_type* zend_ffi_face_struct_add_fields(ffi_type* t, const
zend_ffi_typ
zend_ffi_field *field;
ZEND_HASH_MAP_FOREACH_PTR(&type->record.fields, field) {
- switch (ZEND_FFI_TYPE(field->type)->kind) {
+ zend_ffi_type_kind field_kind = ZEND_FFI_TYPE(field->type)->kind;
+ if (field_kind == ZEND_FFI_TYPE_ENUM) {
+ field_kind = ZEND_FFI_TYPE(field->type)->enumeration.kind;
+ }
+ switch (field_kind) {
case ZEND_FFI_TYPE_FLOAT:
t->elements[(*i)++] = &ffi_type_float;
break;
diff --git a/ext/ffi/tests/bug25558.phpt b/ext/ffi/tests/bug25558.phpt
new file mode 100644
index 000000000000..815bc5a66ba1
--- /dev/null
+++ b/ext/ffi/tests/bug25558.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #25558 (FFI: struct with an enum field passed by value is described to libffi with a void
element)
+--EXTENSIONS--
+ffi
+--INI--
+ffi.enable=1
+--FILE--
+<?php
+
+$ffi = FFI::cdef(<<<EOF
+ typedef enum {
+ RED = 0,
+ GREEN = 1
+ } color;
+
+ typedef struct {
+ char a;
+ color b;
+ char c;
+ } test;
+
+ typedef struct {
+ int (*read_b)(test x);
+ char (*read_c)(test x);
+ } functions;
+ EOF,
+);
+
+$functions = $ffi->new('functions');
+
+$functions->read_b = fn ($x) => $x->b;
+$functions->read_c = fn ($x) => $x->c;
+
+$test = $ffi->new('test');
+$test->a = 2;
+$test->b = $ffi->GREEN;
+$test->c = 3;
+
+var_dump(($functions->read_b)($test));
+var_dump((int)($functions->read_c)($test));
+
+?>
+--EXPECT--
+int(1)
+int(3)