-
Couldn't load subscription status.
- Fork 8k
[FFI] Track unsized types #9642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --TEST-- | ||
| Disallow instantiation of unsized types | ||
| --EXTENSIONS-- | ||
| ffi | ||
| --INI-- | ||
| ffi.enable=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function test(string $type) { | ||
| echo $type . ': '; | ||
| try { | ||
| FFI::new($type); | ||
| echo 'sized'; | ||
| } catch (Throwable $e) { | ||
| echo $e->getMessage(); | ||
| } | ||
| echo "\n"; | ||
| } | ||
|
|
||
| test('char[0]'); | ||
| test('char[1]'); | ||
| test('char*'); | ||
| test('struct {}'); | ||
| test('struct {}*'); | ||
| test('struct {int32_t length; char data[];}'); | ||
| test('struct {int32_t length; char data[0];}'); | ||
| test('union {}'); | ||
| test('union {}*'); | ||
| test('enum { FOO }'); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| char[0]: Cannot instantiate FFI\CData of zero size | ||
| char[1]: sized | ||
| char*: sized | ||
| struct {}: Cannot instantiate FFI\CData of zero size | ||
| struct {}*: sized | ||
| struct {int32_t length; char data[];}: Cannot instantiate FFI\CData of unsized type | ||
| struct {int32_t length; char data[0];}: Cannot instantiate FFI\CData of unsized type | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree
|
||
| union {}: Cannot instantiate FFI\CData of zero size | ||
| union {}*: sized | ||
| enum { FOO }: sized | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't introduce new field. Use ZEND_FFI_ATTR_INCOMPLETE_ARRAY and ZEND_FFI_ATTR_VLA attribute. Or add a new attribute ZEND_FFI_ATTR_UNKNOWN_SIZE (may be with a better name).