Skip to content
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

Disallow struct layout changes #735

Merged
merged 3 commits into from Jan 9, 2020
Merged

Conversation

larskanis
Copy link
Member

This seems like not only an odd feature, but a bad/dangerous one.
When the layout has been used for any existing objects, changing it will produce
very difficult-to-diagnose bugs (at least) or potentially memory violations
if the layout is re-retrieved from the class and used for previous pointers.

It was heavily used in the specs to overwrite one and the same class multiple times to change the layout immediatelly before the test.
However this use case is specific to testing and should not be used anyway.

Fixes #734

@larskanis
Copy link
Member Author

Lots of indents have changed, best view the diff by https://github.com/ffi/ffi/pull/735/files?w=1

Copy link
Contributor

@headius headius left a comment

Choose a reason for hiding this comment

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

Looks great! I agreed in the other issue that a warning would be ok to do before a 2.0 release, so that should change, but otherwise I'm glad this will not be a feature.

This seems like not only an odd feature, but a bad/dangerous one.
When the layout has been used for any existing objects, changing it will produce
very difficult-to-diagnose bugs (at least) or potentially memory violations
if the layout is re-retrieved from the class and used for previous pointers.

It was heavily used in the specs to overwrite one and the same class multiple times to change the layout immediatelly before the test.
However this use case is specific to testing and should not be used anyway.

Fixes ffi#734
This is a follow-up to the previous commit.
The benchmarks also made use of the redefinition feature of struct layouts.
Namespacing avoids redefinition, but uses separate classes for all structs.
Since raising an exception is an API change but it doesn't justify a major version bump, just warn in that case.
@headius
Copy link
Contributor

headius commented Jan 9, 2020

Warning looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow re-layout of existing Struct
2 participants