Skip to content

Allow direct access to unnamed union fields on perf_event_attr#48

Merged
Phantomical merged 6 commits intojimblandy:masterfrom
Phantomical:upstream-sys-attr-deref
May 7, 2025
Merged

Allow direct access to unnamed union fields on perf_event_attr#48
Phantomical merged 6 commits intojimblandy:masterfrom
Phantomical:upstream-sys-attr-deref

Conversation

@Phantomical
Copy link
Collaborator

I've pulled this out of #42. It allows users to directly access fields in the various unnamed unions within perf_event_attr directly, like they would in C. This has two main advantages:

  1. It's a lot more convenient to just type, for example, attr.bp_len rather than attr.__bindgen_anon_1.bp_len.
  2. When combined with #[non_exhaustive], it makes pretty much all binding updates non-breaking changes.

The real benefit is 1, since it makes a whole bunch of code a little bit nicer. 2 is quite nice as well, but I think this is worth doing just for 1. The downside to this is that it's a giant hack, and requires some care to maintain when updates happen. I have included tests and static checks to verify that things work as expected, and in practice I haven't found it to be too much of a challenge keeping things up to date. IMO the upsides to this for users of the crate have been somewhat cursed code that is required to implement it.

I'd like to either get this merged or NACKed before I go upstreaming changes from perf-event2 itself.

…ndy#46)

This means that future changes made to the C perf_event_attr struct
which replace existing fields with inline unions can continue to be
non-breaking changes to the crate.

Furthermore, it is generally much more convenient to directly access the
relevant fields instead of needing to go through the __bindgen_anon_x
field first.
std::mem::offset_of! has been stable for long enough that memoffset is
no longer necessary.
@jimblandy
Copy link
Owner

I haven't looked at the implementation here, but overall I'm less concerned about this change than #49, since it doesn't seem to restrict what people can do. I'll try to take a look at the code tomorrow.

@Phantomical Phantomical mentioned this pull request Apr 28, 2025
@Phantomical
Copy link
Collaborator Author

I'm going to go ahead and merge this as it seems to be uncontroversial and it has been a month. I would like to move forward with changes to perf-event itself and this change is blocking that.

@Phantomical Phantomical merged commit 4825bda into jimblandy:master May 7, 2025
5 checks passed
@Phantomical Phantomical deleted the upstream-sys-attr-deref branch May 8, 2025 02:17
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.

2 participants