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

How to wrap Structs/C-Unions from Julia #1

Open
victorsndvg opened this issue Jun 3, 2020 · 2 comments
Open

How to wrap Structs/C-Unions from Julia #1

victorsndvg opened this issue Jun 3, 2020 · 2 comments

Comments

@victorsndvg
Copy link
Contributor

victorsndvg commented Jun 3, 2020

We are using Clang.jl to automate the conversion of p4est headers to Julia bindings. It wraps functions and structs, but some structs are skipped.

Manually wrapping some complex C-structs and C-unions can be non-straightforward, so we need to investigate how to do it correctly.

I was looking for some information in this direction. Links below can be interesting in order to understand how to deal with this issue:

  1. Packed structs and union declarations are not supported by Julia.
    https://docs.julialang.org/en/latest/manual/calling-c-and-fortran-code/#Struct-Type-Correspondences-1

  2. Dealing with complex C structure [discurse.julialang]
    https://discourse.julialang.org/t/dealing-with-complex-c-structure/9045

  3. Potential wrong alignments and sizes of structs with C Unions
    Potential wrong alignments and sizes of structs with C unions JuliaInterop/Clang.jl#238

  4. Structure padding and packing
    https://stackoverflow.com/questions/4306186/structure-padding-and-packing

  5. Using C Libraries from Julia (interesting blog post from Cbinding.jl developer)
    https://www.analytech-solutions.com/analytech-solutions/blog/cbinding.html

In general, we and these links are in the same direction. But i need a deepest read.

In addition 2 interesting resources to perform alternative implementations:

  1. Use unsafe_convert/unsafe_load instead of reinterpret
    https://github.com/JuliaMultimedia/CSFML.jl/blob/812f21224d683f4119b02c456dda47d4d0a4a471/src/Window/window_common.jl#L272-L314

  2. Improvements for specifying and using C bindings in Julia [CBinding.jl]
    https://github.com/analytech-solutions/CBinding.jl

@krrutkow
Copy link

There is also https://github.com/analytech-solutions/CBindingGen.jl you should check out. It is still somewhat WIP, but would give you another option.

@amartinhuertas
Copy link
Member

There is also https://github.com/analytech-solutions/CBindingGen.jl you should check out. It is still somewhat WIP, but would give you another option.

Thanks @krrutkow !!! We will certainly take a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants