-
-
Notifications
You must be signed in to change notification settings - Fork 447
Declare structs as anonymous within anonymous unions #329
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
Under which conditions does this fail to build? It's compiling perfectly fine with gcc both on my local box and the CI. Removing the names will break the code-generation of various bindings -- that's why the structs are named in the first place. |
Are you building it as C11? The issue is including it from a cpp compilation unit. You'll run into |
I can keep the struct names but that would require to move them out of the union. |
Ah. Yeah, we switched to C11 to permit anonymous unions. Looks like this is an incompatibility between C++ and C11 then, meh. I think we might have to keep the structs named, but move them out of the nesting then instead of removing the names. |
Also you mentioned of possibly breaking bindings, how do you bind a type that comes from an anonymous struct/union, is it in C11 accessible from the global scope? I'm not that good with C but I would imagine the type can't be accessed, at least not in Cpp. |
I don't think it's possible in C11 either, but bindgens often essentially flatten nested types into global scope, so it works there. If the structs are unnamed, they'll essentially get something like a SHA1 hash as their name. Thinking about it again, however, I remembered that we actually stopped using bindgens for the languages where it mattered, switching to hand-crafted struct types instead. Having these fields named thus doesn't actually matter too much anymore. While I do like having them named, I feel that unnesting them kind of makes discoverability of the struct a lot worse -- you have to follow all the "links" to find the fields you're interested in, so I guess your proposed solution here is preferable. |
I'm glad you commented before I pushed onto this branch, the alternative would be: https://github.com/ZehMatt/zydis/tree/fix-anonymous-types-2 |
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.
I'll say it's probably the lesser evil this way, but I'll wait for @flobernd to take a look as well before merging. Either way, thanks for bringing this to our attention and proposing the fix!
I can either open a new PR or push it onto this one, as you wish. |
Hmm, yeah, it's fine with me. I feel like the struct is easier to navigate when nested as-is, but if there are still bindings that depend on this, let's do it as suggested. I think it will also result in better documentation in doxygen, since it otherwise also generates hashed struct names. |
a6159b2
to
7109f84
Compare
Alright pushed the other branch onto this one, the CI unfortunately won't run since this is my first PR. |
Thanks! I started the CI. |
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.
LGTM. Just a minor style issue, but we can as well solve later.
*/ | ||
ZydisRegister value; | ||
} ZydisDecodedOperandReg; | ||
/** |
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.
We should add some linebreaks (before all the struct comments).
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.
I agree, I wasn't sure if I should do it or not since I copied it out as is, I addressed that.
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.
Thanks a lot!
7109f84
to
1f1c826
Compare
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.
LGTM!
Declaring named types within anonymous unions is not allowed, GCC fails to build the code otherwise.