Skip to content

Commit

Permalink
Disallow struct layout changes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
larskanis committed Jan 8, 2020
1 parent 7896c53 commit 0be72ee
Show file tree
Hide file tree
Showing 6 changed files with 1,161 additions and 1,130 deletions.
2 changes: 1 addition & 1 deletion lib/ffi/struct.rb
Expand Up @@ -204,7 +204,7 @@ class << self
# end
# @note Creating a layout from a hash +spec+ is supported only for Ruby 1.9.
def layout(*spec)
#raise RuntimeError, "struct layout already defined for #{self.inspect}" if defined?(@layout)
raise RuntimeError, "struct layout already defined for #{self.inspect}" if defined?(@layout)
return @layout if spec.size == 0

builder = StructLayoutBuilder.new
Expand Down

0 comments on commit 0be72ee

Please sign in to comment.