-
Notifications
You must be signed in to change notification settings - Fork 19
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
Anonymous fields not used #160
Comments
Hey @Larkooo, could you provide an example? |
Yes, our union C structs look like typedef struct {
enum tag;
union {
struct struct_;
enum enum_;
...
}
} ty; first of all, it seems like the field offsets are wrong, they are all 0 when for eg. struct_ and enum_ should be of fieldoffset(8) and the generated fields dont use the anonymous fields - which seems to be the issue for why the offsets are wrong i believe. (the generated metadata from castffi seems to be ok tho) |
dojo.h if you were wondering, this is the header file we're having an issue with. i have a scoped fork of c2cs so i fixed it for our use case but best would be to look into the anonymous fields issue |
When looking into it, with the new version of
Other than that I'm looking at C# code:
C code:
I would expect it to be like:
|
I think there are improvements to be made for both |
Yes, as I said I have fixed that issue in my fork of c2cs so I would be open to contributing to castffi/c2cs if I know where to look at and if there are written tests for those use cases, as it is quite difficult to get through the C parsing part of the code. As for the FieldOffset(s) I think that it should be 8 as the struct packing is set to 8 bytes. |
Yeah I suppose so. If you put up a MR that be great. The code was basically manually tested against versus C libraries that I come across. Your C code is interesting because I have seen anonymous unions being used as such but never have I seen someone use anonymous structs like that. I have added tests but they don't cover anonymous structs and anonymous unions like this yet.
The related C code that "handles" a struct would be here for What the harder part is determining how to identify a cursor so it can be "handled". Basically how it works for Anonymous fields have a type and that anonymous type is given a name. The code is here https://github.com/bottlenoselabs/CAstFfi/blob/main/src/cs/production/CAstFfi.Tool/Features/Extract/Domain/Explore/ExploreContext.cs#L73 then here https://github.com/bottlenoselabs/CAstFfi/blob/main/src/cs/production/CAstFfi.Tool/Features/Extract/Domain/Explore/ExploreContext.cs#L196. This happens so the name can be later looked up for the extracted data. Expected test data would be added to https://github.com/bottlenoselabs/CAstFfi/tree/main/src/cs/tests/CAstFfi.Tests/Data/Values with a new folder for |
Fixed in #171 |
the anonymous field dont seem to be used when generating a union struct
The text was updated successfully, but these errors were encountered: