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

Difficulty using Cxx inside a module #424

Closed
goretkin opened this issue Jun 3, 2019 · 3 comments
Closed

Difficulty using Cxx inside a module #424

goretkin opened this issue Jun 3, 2019 · 3 comments

Comments

@goretkin
Copy link
Contributor

goretkin commented Jun 3, 2019

I had done import Cxx twice in a project, and due to the line

__init__()

this resets the active instances. I personally found this behavior surprising, since all the translation units I had previously loaded were loaded into a different instance.

I thought I could keep a handle to the Cxx.CxxCore.ClangCompiler instance, so I could use it later. It seems that this definition

instance(C::ClangCompiler) = C

exists for that use.

So I tried
my_cxx_compiler_instance = Cxx.instance(Cxx.__current_compiler__) right after all of my addHeaderDir and cxxinclude calls. And then later
__current_compiler__ = my_cxx_compiler_instance

However the definitions at

Cxx.jl/src/codegen.jl

Lines 840 to 853 in 93359f1

@generated function cppcall(CT::CxxInstance, expr, args...)
_cppcall(CT, expr, false, false, args)
end
@generated function cppcall_member(CT::CxxInstance, expr, args...)
_cppcall(CT, expr, true, false, args)
end
@generated function cxxnewcall(CT::CxxInstance, expr, args...)
_cppcall(CT, expr, false, true, args)
end
# Memory management
@generated function destruct(CT::CxxInstance, x)
seem to restrict the type of the first argument to be CxxInstance unnecessarily.

@goretkin
Copy link
Contributor Author

goretkin commented Jun 3, 2019

Actually, I'm not sure exactly what's happening. In the simple MWE below, I see __init__ called exactly once. reset_init! isn't called. In my larger project, I do see these functions called multiple times. In any case, I expect the test below to pass, but it does not.

https://github.com/goretkin/CxxInitMWE/blob/8c56237274d0668bcd1c3051c969387259c2e20f/test/runtests.jl#L7

MWE at https://github.com/goretkin/CxxInitMWE (archive attached for posterity)
CxxInitMWE-master.zip

@goretkin goretkin changed the title Explicit call to __init__ causes surprise Difficulty using Cxx inside a module Jun 3, 2019
@goretkin
Copy link
Contributor Author

goretkin commented Jun 3, 2019

My difficulties seem to have been related to precompilation and initialization. Adding __precompile__(false) to my module fixed my issue.

@goretkin goretkin closed this as completed Jun 3, 2019
@cdsousa
Copy link

cdsousa commented Jun 3, 2019

Related to #343

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

2 participants