-
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
Conversation
This avoids surprises when creating instances of types like
struct { char[] foo }
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
-
test with 1 will be good here too
-
why unsized, shouldn't this ex warn about zero size?
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.
I agree
- Cannot instantiate FFI\CData of type "void"
- Cannot instantiate FFI\CData of type with variable size
- I don't think zero size arrays should be disallowed
|
@dstogov Do you think this adds any value? If not, feel free to close this PR. |
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.
I think the error message makes sense.
Please replace "sized" field by some attribute and improve the error messages,
| ffi_abi abi; | ||
| } func; | ||
| }; | ||
| bool 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).
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
- Cannot instantiate FFI\CData of type "void"
- Cannot instantiate FFI\CData of type with variable size
- I don't think zero size arrays should be disallowed
|
I'm not currently interested in working on FFI, so I'm closing this. Anyone else is free to take over if they wish. |
This avoids surprises when trying to create instances of structs that use the struct hack.
Got the idea from looking at #7949. Not sure if it makes sense.