[php-src] Issue #7949: FFI struct with flexible array member
| From: | cmb69 | Date: | Sun, 16 Jan 2022 18:18:53 +0000 |
| Subject: | [php-src] Issue #7949: FFI struct with flexible array member | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239038@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7949
Comment Author: cmb69
There is actually support for flexible array members (and the struct hack
char[0]), but
the programmer is responsible to allocate a proper struct (FFI::new() can't do
that). Assuming you have such a properly allocated struct, the following works:
````
$value->data[100] = "a";
var_dump($value->data[100]); // "a"
````
This is explicitly supported due to https://github.com/php/php-src/blob/655e578e816e6eec767b25963e93d8e044a9f392/ext/ffi/ffi.c#L1345
The fact that FFI::memcpy() does not work, looks like a bug to me. I think there should
be an exception for ZEND_FFI_TYPE_ARRAY with type1->size == 0 at
https://github.com/php/php-src/blob/655e578e816e6eec767b25963e93d8e044a9f392/ext/ffi/ffi.c#L4245