JuliaInterop / Clang.jl

C binding generator and Julia interface to libclang
https://juliainterop.github.io/Clang.jl/
MIT License
220 stars 68 forks source link

Fix #233 #384

Closed Gnimuc closed 2 years ago

Gnimuc commented 2 years ago

cc @cdsousa

Gnimuc commented 2 years ago

https://github.com/JuliaInterop/Clang.jl/runs/7997228799?check_suite_focus=true#step:6:401

I cannot reproduce the issue.

cdsousa commented 2 years ago

Strange, if I checkout that branch and run the tests, that new test will also pass for me.

However, running this simple script in REPL fails:


using Clang
using Clang.Generators

header_content = """
struct Meow {
    int blah;
    union {
        float either1;
        int either2;
    };
    float moo;
};
"""

header_path = tempname()*".h"
write(header_path, header_content)

ctx = create_context(header_path, get_default_args())
build!(ctx)
cdsousa commented 2 years ago

Wow! If I do header_path = "unnamed.h" then it works 😲 Actually, it works if, and only if, the filename starts with includes "unnamed"... What the heck!

cdsousa commented 2 years ago

Alright, it seems it works only if the "unnamed" is present in the filename or in the names of the parent types. Probably that's related to https://github.com/JuliaInterop/Clang.jl/blob/master/src/generator/Generators.jl#L39 Is that by design?

cdsousa commented 2 years ago

Note that (as I edited in https://github.com/JuliaInterop/Clang.jl/pull/384#issuecomment-1225915158) it suffices for the filename to include the string "unammed" somewhere (or that be present on any name of the type hierarchy). So it is expected that "test_unnamed.h" also passes the test.

Gnimuc commented 2 years ago

Alright, it seems it works only if the "unnamed" is present in the filename or in the names of the parent types. Probably that's related to https://github.com/JuliaInterop/Clang.jl/blob/master/src/generator/Generators.jl#L39 Is that by design?

This is just a workaround for detecting anonymous record types. This is a limitation of libclang. I guess the ultimate solution is to rework the generator on top of ClangCompiler.jl.

cdsousa commented 2 years ago

Thank you! Thanks for all your work!