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

Allow custom field offsets to be passed for define-cstruct #876

Closed
wants to merge 1 commit into from

Conversation

BartAdv
Copy link
Contributor

@BartAdv BartAdv commented Feb 10, 2015

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.

@mflatt
Copy link
Member

mflatt commented Feb 11, 2015

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?

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 11, 2015

Indeed it would be more readable. I'll look into it.

On 2/11/15, Matthew Flatt notifications@github.com wrote:

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?


Reply to this email directly or view it on GitHub:
#876 (comment)

@samth
Copy link
Sponsor Member

samth commented Feb 11, 2015

@BartAdv also, if you look at the status checks on GitHub, you'll see that there's a build error with this pull request.

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 11, 2015

Yes, but it doesn't matter, it's gonna be reworked.

On Wed, Feb 11, 2015 at 2:42 PM, Sam Tobin-Hochstadt <
notifications@github.com> wrote:

@BartAdv https://github.com/BartAdv also, if you look at the status
checks on GitHub, you'll see that there's a build error with this pull
request.


Reply to this email directly or view it on GitHub
#876 (comment).

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 11, 2015

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?
Copy link
Sponsor Member

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.

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 12, 2015

OK, found out where's the error, I'm on it

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 12, 2015

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 super-id...

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.
@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 13, 2015

Added syntax test case and rebased + squashed the commits.

I'm unsure if I'm syntax-case'ing idiomatically, previously the [slot slot-type] was at the top level syntax case, I've merged those into single case and I'm pattern matching deeper, after parsing additional options. I've put some comments in the diff @6beb5df.

@mflatt
Copy link
Member

mflatt commented Feb 14, 2015

I'd like to add an #:offset keyword before the offset, in anticipation of handling future options uniformly. I'll make that change, generally take a closer look at the implementation, update the docs, and then merge.

Thanks!

@BartAdv
Copy link
Contributor Author

BartAdv commented Feb 14, 2015

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.

@mflatt
Copy link
Member

mflatt commented Feb 15, 2015

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.

@mflatt
Copy link
Member

mflatt commented Feb 15, 2015

Merged - thanks!

@mflatt mflatt closed this Feb 15, 2015
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.

None yet

3 participants