Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 45 additions & 0 deletions ext/ffi/tests/bug25558.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
Bug #25558 (FFI: struct with an enum field passed by value is described to libffi with a void element)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug #XYZ is for the old bugsnet bugtracker (bugs.php.net); whereas GH-XYZ is for github bugs.
You don't need to change this PR, I'll fix it up when I merge

Suggested change
Bug #25558 (FFI: struct with an enum field passed by value is described to libffi with a void element)
GH-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)
Loading