From d6a64fb63d6ed3c3fcb6dd8fe42831e20606bccd Mon Sep 17 00:00:00 2001 From: DPDmancul Date: Wed, 18 Nov 2026 16:10:22 +0100 Subject: [PATCH] Fix #25558: FFI: struct with an enum field passed by value is described to libffi with a void element --- ext/ffi/ffi.c | 6 ++++- ext/ffi/tests/bug25558.phpt | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ext/ffi/tests/bug25558.phpt diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 73e738202c8d..06f564c2e7ea 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -359,7 +359,11 @@ static ffi_type* zend_ffi_face_struct_add_fields(ffi_type* t, zend_ffi_type *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-- +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)