[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Wed, 25 Nov 2026 22:06:02 +0000
Subject: [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144182@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-11-25T23:05:28+01:00 Commit: https://github.com/php/php-src/commit/f3da0f6c9a7646da5b60f45a303089bb9f27d79e Raw diff: https://github.com/php/php-src/commit/f3da0f6c9a7646da5b60f45a303089bb9f27d79e.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: 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 NEWS M ext/ffi/ffi.c Diff: diff --git a/NEWS b/NEWS index 99cb66865daa..56f8b8c15e06 100644 --- a/NEWS +++ b/NEWS @@ -62,6 +62,10 @@ PHP NEWS . Fixed use-after-free in getElementById() after a removed ID attribute is freed. (Ilia Alshanetsky) +- FFI: + . Fixed bug GH-25558 (struct with an enum field passed by value is described + to libffi with a void element). (Davide Peressoni) + - Filter: . Fixed stack overflow in filter_var() and filter_var_array() with deeply nested arrays. (Eyüp Can Akman) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 97d32e5b99cc..13aa17f6977b 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -353,7 +353,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)

« previous php.cvs (#144182) next »