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

fix julia_type<void> #178

Closed
wants to merge 1 commit into from
Closed

fix julia_type<void> #178

wants to merge 1 commit into from

Conversation

mofeing
Copy link

@mofeing mofeing commented Dec 17, 2024

fixes JuliaInterop/CxxWrap.jl#463

the erroring tests seem to be unrelated to the changed code

@mofeing mofeing changed the title fix julia_type<void> #463 fix julia_type<void> Dec 17, 2024
@barche
Copy link
Contributor

barche commented Dec 18, 2024

Type void is already mapped here:

set_julia_type<void>((jl_datatype_t*)julia_type("Cvoid", jl_base_module),false);

So the first thing to find out is why this fails in your setup.

With regards to this PR, the error on e.g. Ubuntu is:

/home/runner/work/libcxxwrap-julia/libcxxwrap-julia/include/jlcxx/type_conversion.hpp:502:8: error: extra qualification not allowed [-fpermissive]
  502 | struct jlcxx::julia_type_factory<void>
      |        ^~~~~

So there is a syntax error. But adding a separate julia_type_factory for void is not the correct way to solve this, it just fights the symptom of a deeper problem.

@mofeing
Copy link
Author

mofeing commented Dec 19, 2024

With regards to this PR, the error on e.g. Ubuntu is:

/home/runner/work/libcxxwrap-julia/libcxxwrap-julia/include/jlcxx/type_conversion.hpp:502:8: error: extra qualification not allowed [-fpermissive]
  502 | struct jlcxx::julia_type_factory<void>
      |        ^~~~~

So there is a syntax error. But adding a separate julia_type_factory for void is not the correct way to solve this, it just fights the symptom of a deeper problem.

ah right, that is a typo sorry

Type void is already mapped here:

set_julia_type<void>((jl_datatype_t*)julia_type("Cvoid", jl_base_module),false);

So the first thing to find out is why this fails in your setup.

yeah, that's weird. i even tried calling register_core_types and register_core_cxxwrap_type by myself inside the define_module_julia but doesn't work. 🫠

one annotation: we are using bazel as build system, and due to a symbol conflict between Julia's LLVM and our LLVM, we only export some C-API symbols marked manually. AFAIK only define_module_julia is required right?

@mofeing
Copy link
Author

mofeing commented Dec 19, 2024

okay, so i run this inside the function definining the module

std::cout << "has_julia_type<void>() = " << jlcxx::has_julia_type<void>() << std::endl;

jlcxx::register_core_types();
jlcxx::register_core_cxxwrap_types();

std::cout << "has_julia_type<void>() = " << jlcxx::has_julia_type<void>() << std::endl;

and it returns this during Julia precompilation

has_julia_type<void>() = 0
has_julia_type<void>() = 0

checking register_core_type, the only thing that i can imagine it might be happening is that for some weird problem the static bool registered might default to true?

if i take the inner code from ..., and i put it in my code...

jlcxx::set_julia_type<void>((jl_datatype_t*)jlcxx::julia_type("Cvoid", jl_base_module),false);
jlcxx::set_julia_type<void*>(jl_voidpointer_type,false);
jlcxx::set_julia_type<float>(jl_float32_type,false);
jlcxx::set_julia_type<double>(jl_float64_type,false);

jlcxx::set_julia_type<jl_datatype_t*>(jl_any_type,false);
jlcxx::set_julia_type<jl_value_t*>(jl_any_type,false);

std::cout << "has_julia_type<void>() = " << jlcxx::has_julia_type<void>() << std::endl;

i get

has_julia_type<void>() = 1

@barche
Copy link
Contributor

barche commented Dec 19, 2024

I am not able to reproduce this, what kind of system are you running all this on, exactly?

@mofeing
Copy link
Author

mofeing commented Dec 19, 2024

i managed to reproduce the error with a MWE and packaged everything here https://github.com/mofeing/ReproducerCxxWrapVoidBug

if you activate the package's env and call ]build you will get the error when the package is precompiling. if you then comment this line, https://github.com/mofeing/ReproducerCxxWrapVoidBug/blob/299185e0aa5b9d6655c396dfbf89617b8b9e4329/deps/CMakeLists.txt#L18, the one adding the -fvisibility=hidden (but exporting define_julia_module), the error will disappear (i believe -fvisibility is just for clang so for gcc, you need to use the equivalent flag).

AFAIK only the julia module defining function is ccalled, but it seems like the addresses of the C++ function stored there are not correct or directly skipped. not sure about how this last part happens.

tldr: the problem is that we are filtering all symbols by default except some in a passlist, and the C++ symbols are not exported.

i'm closing because my problem is solved, but might be good to record this somewhere in the docs?

@mofeing mofeing closed this Dec 20, 2024
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

Successfully merging this pull request may close these issues.

No appropriate factory for type v
2 participants