-
Notifications
You must be signed in to change notification settings - Fork 45
Add new pointer memory management interfaces to structs and unions #41
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
kou
left a comment
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.
Thanks.
I'll review this deeply later.
lib/fiddle/struct.rb
Outdated
| addr = Fiddle.malloc(CStructEntity.size(types)) | ||
| CStructEntity.new(addr, types, func) | ||
| addr = Fiddle.malloc(self.size(types)) | ||
| struct = new(addr, types, func) |
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.
If an exception is raised in here, addr isn't freed.
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.
Yeah maybe I should use the pointer constructor rather than using malloc directly as it used to.
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.
Fixed.
kou
left a comment
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 understand that we need reconstruct Fiddle::Pointer and lib/fiddle/struct.rb.
It may be better that we merge this as-is and work on it as a follow-up task.
test/fiddle/test_c_struct_entry.rb
Outdated
| end | ||
| end | ||
|
|
||
| def test_new_double_free |
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.
Duplicated.
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.
Fixed.
|
This is the end of this series of PRs tweaking the API. I do have some ideas about how to improve the implementation. I've got some goals to be able to share code between Fiddle and FFI, in order to make it easier for alternative implementations of Ruby which don't want to have to implement both interfaces. And I've got some goals to allow pointer operations to optimise much better in optimising implementations of Ruby. |
lib/fiddle/struct.rb
Outdated
| end | ||
| } | ||
| size = klass.entity_class.size(types) | ||
| # we use eval here make size into a literal, for performance |
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.
We can use define_singleton_method for size here because this method will not be called too much.
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.
Done.
lib/fiddle/struct.rb
Outdated
| addr = Fiddle.malloc(CUnionEntity.size(types)) | ||
| CUnionEntity.new(addr, types, func) | ||
| super | ||
| end |
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.
Could you remove this method?
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 didn't add it - but removed as you've asked.
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
|
Thanks! |
* ruby/fiddle#41 This syntax is a pain. Fix #35
* ruby/fiddle#41 This syntax is a pain. Fix #35
Allows you to go from
to
and from
to
Both are safer, have better temporal and spatial locality for the memory manager, and reduce the working set size.