Skip to content

add raw_field macro to compute raw ptr to field - #40

Merged
Gilnaa merged 3 commits into
Gilnaa:masterfrom
RalfJung:raw_field
Mar 16, 2020
Merged

add raw_field macro to compute raw ptr to field#40
Gilnaa merged 3 commits into
Gilnaa:masterfrom
RalfJung:raw_field

Conversation

@RalfJung

Copy link
Copy Markdown
Collaborator

Expose the part of offset_of! that computes a raw pointer to a field as a separate macro.
@Diggsey expressed that this would be interesting for their crate.

If rust-field-offset could depend on memoffset to use this macro, that would mean there is just one place we have to change once &raw (or an equivalent mechanism) becomes stable, so that everyone uses the blessed way to do this.

@Diggsey does this macro fit the needs of your crate?
@Gilnaa are you okay with adding this to the API surface of memoffset?

@Gilnaa

Gilnaa commented Mar 16, 2020

Copy link
Copy Markdown
Owner

Sure. Has anything changed since this in Feb7?

@RalfJung

Copy link
Copy Markdown
Collaborator Author

That was about using offset_of!, which is not possible with the existing API of rust-field-offset.

This PR is implementing the proposal a bit up that thread:

If there was a crate which implemented this macro: raw_address_of!((*ptr_to_undef).bar) and which guaranteed in the future to compile down to the MIR operator your RFC introduced, whilst for the moment making a "best effort" attempt, then I would be happy to use that to implement (2) in this crate.

@RalfJung RalfJung closed this Mar 16, 2020
@RalfJung RalfJung reopened this Mar 16, 2020
@Gilnaa
Gilnaa merged commit 73f5ddd into Gilnaa:master Mar 16, 2020
@RalfJung

Copy link
Copy Markdown
Collaborator Author

Before making a release, let's see if the API works for @Diggsey

@RalfJung
RalfJung deleted the raw_field branch March 16, 2020 17:05
@Gilnaa

Gilnaa commented Mar 16, 2020

Copy link
Copy Markdown
Owner

Sure

@Diggsey

Diggsey commented Mar 16, 2020

Copy link
Copy Markdown

Yeah, I'd be happy to depend on this crate for the raw_field function.

@Amanieu

Amanieu commented Mar 16, 2020

Copy link
Copy Markdown
Contributor

@RalfJung Does this macro resolve your concern here? #21 (comment)

@RalfJung

Copy link
Copy Markdown
Collaborator Author

@Amanieu this macro has nothing to do with container_of!. It just exposes something that we already did as part of offset_of! before, so there is no change to what happens to provenance.

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.

4 participants