-
Notifications
You must be signed in to change notification settings - Fork 45
Add support for nested structs #27
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
lib/fiddle/struct.rb
Outdated
| case ty[0] | ||
| when TYPE_VOIDP | ||
| val = val.collect{|v| Pointer.new(v)} | ||
| val = val.collect{|v| v = Pointer.new(v); v.size = SIZEOF_VOIDP; v } |
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.
Pointer#size is not the size of address. It's the size of area that is pointed by the address.
|
Thanks! And sorry for changing implementation details without asking you.
We can restore your change from your commits in this branch. I'll merge this. If you find any problems, we can work on them as follow-up tasks. |
This pull request was split from #14 as requested by @nobu . It depends on #26 because without that a struct which contains an array of structs would not work properly.
This pull request adds support for nested structs, unions containing structs, and nested arrays of structs/unions, to arbitrary depth.
Here are some examples:
It is also possible to specify the nested struct in-line, by replacing
StudentCollegeDetailwithstruct([...]), like so:Additionally, an array of structs within a parent struct can be specified like so:
The position of the hash in the list of members determines the offset into the parent struct at which the nested struct appears. For example:
There can be multiple hashes, or a single hash with multiple keys/values, or any combination of these. Since Ruby maintains hash order, the offsets will be as expected. The following examples are also valid syntax, but will result in the struct members being laid out at different offsets within the outer struct's memory: