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

Wrong order of generated structs for generation of structs containing anonymous unions #325

Closed
martinkosch opened this issue Aug 22, 2021 · 3 comments · Fixed by #331
Closed
Labels

Comments

@martinkosch
Copy link

martinkosch commented Aug 22, 2021

Hi everyone,
thank you for the amazing package so far!

I think I encountered a small (but annoying) bug in the current master branch: the generation of structs containing anonymous unions prints the corresponding Julia union wrapper struct after the original struct definition.

In my case, the C struct

typedef struct {
      enum NodeIdType id_type;
      union {
          UInt32     numeric;
          Guid       guid;
      } id;
  } NodeId;

results in the generated code

mutable struct NodeId
    id_type::NodeIdType
    id::__JL_Ctag_295
    NodeId() = new()
end
...
struct __JL_Ctag_295
    data::NTuple{16, UInt8}
end

leading to

ERROR: LoadError: LoadError: UndefVarError: __JL_Ctag_295 not defined

If I am not missing something, the problem can be solved by changing the order of the generated structs.

@Gnimuc
Copy link
Member

Gnimuc commented Aug 22, 2021

This can be fixed by storing the indices of those nested records in the option Dict and then add a pass to print them right after the prologue printer pass.

@Gnimuc Gnimuc added bug good first issue Good for newcomers labels Aug 22, 2021
@martinkosch
Copy link
Author

martinkosch commented Aug 22, 2021

Printing the nested records right after the prologue does not solve the problem though if the nested records themselves or their generated getproperty/setproperty! functions depend on other structs that are defined after the prologue. The best guess for a suitable position is probably right before the struct that contains the anonymous union.

@Gnimuc
Copy link
Member

Gnimuc commented Aug 23, 2021

You're right. A better way is to add the indices of those inner nested structs to the nested struct. In this way, the order will be sorted automatically in the toposort pass.

melonedo added a commit to melonedo/Clang.jl that referenced this issue Aug 24, 2021
* all `gensym` calls are recorded.
* Fix JuliaInterop#325.
melonedo added a commit to melonedo/Clang.jl that referenced this issue Sep 9, 2021
* all `gensym` calls are recorded.
* Fix JuliaInterop#325.
@Gnimuc Gnimuc removed the good first issue Good for newcomers label Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants