Skip to content

Conversation

@iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Sep 29, 2022

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.

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
Copy link
Contributor

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?

Copy link
Member

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

@iluuu1994
Copy link
Member Author

@dstogov Do you think this adds any value? If not, feel free to close this PR.

Copy link
Member

@dstogov dstogov left a 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;
Copy link
Member

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
Copy link
Member

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

@iluuu1994
Copy link
Member Author

I'm not currently interested in working on FFI, so I'm closing this. Anyone else is free to take over if they wish.

@iluuu1994 iluuu1994 closed this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants