JuliaInterop / Clang.jl

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

Definitions of function pointer types should appear before their first use #410

Closed marcom closed 1 year ago

marcom commented 1 year ago

Clang.jl 0.17.0 makes nice type definitions for function pointers instead of Ptr{Cvoid}, which is much appreciated.

These definitions in the generated julia code can appear after their first use in e.g. a struct, causing an error in julia when trying to use the generated wrapper.

Example:

https://github.com/marcom/ViennaRNA.jl

in the gen/ directory, bump Clang.jl compat to 0.17 and julia compat to 1.7 and run

julia --project generator.jl

The generated bindings cannot be loaded anymore:

ERROR: LoadError: UndefVarError: vrna_callback_hc_evaluate not defined
Gnimuc commented 1 year ago

408 is wrong. The original behavior is right.

It looks like the author got confused with a typedef-ed function pointer and a typedef-ed function prototype.

There is another way to fix what #408 is supposed to solve. Sorry, I should have read https://github.com/JuliaParallel/MPI.jl/issues/688 more carefully.

cc @t-bltg

t-bltg commented 1 year ago

Hum sorry about this. Let me have a second look a it.

Gnimuc commented 1 year ago

MPI.jl is a bit more problematic, I will try to submit a PR there after fixing Clang.jl.

https://github.com/JuliaParallel/MPI.jl/issues/694

marcom commented 1 year ago

Many thanks for the quick fix