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
Allow custom field offsets to be passed for define-cstruct #876
Conversation
Thanks for the patch. Would it be more convenient or less convenient if offsets were attached to individual fields, instead of having a list for all fields? |
Indeed it would be more readable. I'll look into it. On 2/11/15, Matthew Flatt notifications@github.com wrote:
|
@BartAdv also, if you look at the status checks on GitHub, you'll see that there's a build error with this pull request. |
Yes, but it doesn't matter, it's gonna be reworked. On Wed, Feb 11, 2015 at 2:42 PM, Sam Tobin-Hochstadt <
|
I have modified it to include offsets along with field specification, but don't treat it like finished patch - I must say I struggled a bit with this (basically, I needed to learn macros basics), and I don't like the way I'm extracting optional values. I'd very much appreciate just some review. Thanks |
(or (stx-pair? #'type) | ||
(stx-pair? #'(slot ...))) | ||
(stx-pair? #'(slot-def ...))) ; is this check still correct after the change? |
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.
This is still checking the same thing it was before.
9fd0ace
to
b2a31e4
Compare
OK, found out where's the error, I'm on it |
OK, looks like the tests are passing now - I wonder, what are the edge cases to consider, the previous error was caused by not checking the case with |
This allows to define the offsets for each field instead of relying on the calculated ones - useful when struct might be defined differently across platforms.
5bc3c96
to
6beb5df
Compare
Added syntax test case and rebased + squashed the commits. I'm unsure if I'm syntax-case'ing idiomatically, previously the |
I'd like to add an Thanks! |
One more thing occured to me - if we allow custom offsets, shouldn't we allow specifying custom size? The scenario for which I needed this change was just about shuffling the order of the fields, so the size stays the same. However, it's easy to imagine one could do more crazy things with it. |
I think that custom sizes are handled well enough through the field's type. It would also be possible to set offsets by playing games with field types, but it would be tricky, and that's not how ctypes are intended to work. Specifying a representation size, through, is properly a job of a ctype. |
Merged - thanks! |
This should be useful when dealing with structures whose layout is not standardized across implementation. It simply allows to pass a list of integers which is then used as offsets instead of the ones computed from field types and alignment.