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

munmap_chunk(): invalid pointer in jlcxx::FunctionWrapper destructor after moving to new finalizer policy #407

Open
Clemapfel opened this issue Feb 22, 2024 · 2 comments

Comments

@Clemapfel
Copy link

Clemapfel commented Feb 22, 2024

I had to recompile and refactor my project because the argument for constructor was changed to require a finalizer policy instead of a boolean. I replaced every true with jlcxx::finalize_policy::yes, otherwise it would fail to compile, see below for the compiler error.

After recompiling the project, it now crashes without an error message on exit:

julia> module M
       using CxxWrap
       function get_jlcxx_path()
                   return "/home/clem/.julia/artifacts/42fc212dda5ff3f17a7d8a45995284884e117c63/lib/libmousetrap_julia_binding.so"
               end
       @wrapmodule(get_jlcxx_path)
       end
julia> exit()
munmap_chunk(): invalid pointer

[23705] signal (6.-6): Aborted
in expression starting at REPL[3]:1
__pthread_kill_implementation at /lib64/libc.so.6 (unknown line)
gsignal at /lib64/libc.so.6 (unknown line)
abort at /lib64/libc.so.6 (unknown line)
__libc_message.cold at /lib64/libc.so.6 (unknown line)
malloc_printerr at /lib64/libc.so.6 (unknown line)
munmap_chunk at /lib64/libc.so.6 (unknown line)
__libc_free at /lib64/libc.so.6 (unknown line)
deallocate at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/new_allocator.h:158
deallocate at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/alloc_traits.h:496
_M_deallocate at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/stl_vector.h:387
~_Vector_base at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/stl_vector.h:366
~vector at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/stl_vector.h:733
~FunctionWrapperBase at /opt/x86_64-linux-gnu/bin/../x86_64-linux-gnu/sys-root/usr/local/include/jlcxx/module.hpp:159
~FunctionWrapper at /opt/x86_64-linux-gnu/bin/../x86_64-linux-gnu/sys-root/usr/local/include/jlcxx/module.hpp:234
~FunctionWrapper at /opt/x86_64-linux-gnu/bin/../x86_64-linux-gnu/sys-root/usr/local/include/jlcxx/module.hpp:234
_M_dispose at /opt/x86_64-linux-gnu/x86_64-linux-gnu/include/c++/12.1.0/bits/shared_ptr_base.h:428
_ZNSt15_Sp_counted_ptrIPN5jlcxx6ModuleELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv at /home/clem/.julia/artifacts/1a6c47b18178e0a823eb0b74a7ec857769c26937/lib/libcxxwrap_julia.so (unknown line)
_ZNSt8_Rb_treeIP12_jl_module_tSt4pairIKS1_St10shared_ptrIN5jlcxx6ModuleEEESt10_Select1stIS8_ESt4lessIS1_ESaIS8_EE8_M_eraseEPSt13_Rb_tree_nodeIS8_E at /home/clem/.julia/artifacts/1a6c47b18178e0a823eb0b74a7ec857769c26937/lib/libcxxwrap_julia.so (unknown line)
_ZNSt8_Rb_treeIP12_jl_module_tSt4pairIKS1_St10shared_ptrIN5jlcxx6ModuleEEESt10_Select1stIS8_ESt4lessIS1_ESaIS8_EE8_M_eraseEPSt13_Rb_tree_nodeIS8_E at /home/clem/.julia/artifacts/1a6c47b18178e0a823eb0b74a7ec857769c26937/lib/libcxxwrap_julia.so (unknown line)
__run_exit_handlers at /lib64/libc.so.6 (unknown line)
exit at /lib64/libc.so.6 (unknown line)
ijl_exit at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/init.c:208
exit at ./initdefs.jl:28 [inlined]
exit at ./initdefs.jl:29
jfptr_exit_46108.clone_1 at /home/clem/Applications/julia-1.9.3/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
do_call at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:126
eval_value at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:226
eval_stmt_value at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:177 [inlined]
eval_body at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:624
jl_interpret_toplevel_thunk at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:762
jl_toplevel_eval_flex at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:912
jl_toplevel_eval_flex at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:856
ijl_toplevel_eval_in at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:971
eval at ./boot.jl:370 [inlined]
eval_user_input at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:153
repl_backend_loop at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:249
#start_repl_backend#46 at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:234
start_repl_backend at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:231
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
#run_repl#59 at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:379
run_repl at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:365
jfptr_run_repl_60908.clone_1 at /home/clem/Applications/julia-1.9.3/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
#1017 at ./client.jl:421
jfptr_YY.1017_36106.clone_1 at /home/clem/Applications/julia-1.9.3/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
jl_f__call_latest at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/builtins.c:774
#invokelatest#2 at ./essentials.jl:819 [inlined]
invokelatest at ./essentials.jl:816 [inlined]
run_main_repl at ./client.jl:405
exec_options at ./client.jl:322
_start at ./client.jl:522
jfptr__start_40034.clone_1 at /home/clem/Applications/julia-1.9.3/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
true_main at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:573
jl_repl_entrypoint at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:717
main at julia (unknown line)
__libc_start_call_main at /lib64/libc.so.6 (unknown line)
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 6048328 (Pool: 6046658; Big: 1670); GC: 8
Aborted (core dumped)

The stacktrace doesn't point to any line of my own code, as far as I can see, how would I go about finding out how to fix this?

@Clemapfel
Copy link
Author

Clemapfel commented Feb 22, 2024

Compiler error that necessitated the change:

/// `Action` is a complex C++ class in another library that I'm trying to wrap for Julia

auto action = module.add_type(Action)
    .constructor([](const std::string& id, void* app_ptr){
        return new Action(id, *((Application*) app_ptr));
    }, true); // use boolean
FAILED: libmousetrap_julia_binding.so.0.3.0.p/cpp_action.cpp.o 
ccache c++ -Ilibmousetrap_julia_binding.so.0.3.0.p -I. -I.. -I../cpp -I/home/clem/Applications/julia-1.9.3/julia-1.9.3/include/julia -I/usr/local/include -I/usr/local/include/include/mousetrap -I/usr/include/libadwaita-1 -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/graphene-1.0 -I/usr/lib64/graphene-1.0/include -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++17 -O0 -g -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -fPIC -mfpmath=sse -msse -msse2 -pthread -DJULIA_ENABLE_THREADING -mfpmath=sse -msse -msse2 -MD -MQ libmousetrap_julia_binding.so.0.3.0.p/cpp_action.cpp.o -MF libmousetrap_julia_binding.so.0.3.0.p/cpp_action.cpp.o.d -o libmousetrap_julia_binding.so.0.3.0.p/cpp_action.cpp.o -c ../cpp/action.cpp
In file included from /usr/local/include/jlcxx/module.hpp:14,
                 from /usr/local/include/jlcxx/jlcxx.hpp:15,
                 from ../cpp/../mousetrap_julia_binding.hpp:7,
                 from ../cpp/action.cpp:1:
/usr/local/include/jlcxx/attr.hpp: In instantiation of ‘void jlcxx::detail::parse_attributes_helper(ExtraFunctionData&, T) [with T = bool]’:
/usr/local/include/jlcxx/attr.hpp:156:29:   required from ‘jlcxx::detail::ExtraFunctionData jlcxx::detail::parse_attributes(Extra ...) [with bool AllowCallingPolicy = false; bool AllowFinalizePolicy = true; Extra = {bool}]’
/usr/local/include/jlcxx/module.hpp:625:79:   required from ‘void jlcxx::Module::constructor(jl_datatype_t*, LambdaT&&, R (LambdaT::*)(ArgsT ...) const, Extra ...) [with T = mousetrap::Action; R = mousetrap::Action*; LambdaT = implement_action(jlcxx::Module&)::<lambda(const std::string&, void*)>; ArgsT = {const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, void*}; Extra = {bool}; jl_datatype_t = _jl_datatype_t]’
/usr/local/include/jlcxx/module.hpp:1076:28:   required from ‘jlcxx::TypeWrapper<T>& jlcxx::TypeWrapper<T>::constructor(LambdaT&&, Extra ...) [with LambdaT = implement_action(jlcxx::Module&)::<lambda(const std::string&, void*)>; Extra = {bool}; typename std::enable_if<jlcxx::detail::has_call_operator<LambdaT>::value, bool>::type <anonymous> = true; T = mousetrap::Action]’
../cpp/action.cpp:8:17:   required from here
/usr/local/include/jlcxx/attr.hpp:139:31: error: incomplete type ‘jlcxx::detail::process_attribute<bool, void>’ used in nested name specifier
  139 |     process_attribute<T>::init(std::forward<T_>(argi), f);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

The same code as:

auto action = module.add_type(Action)
    .constructor([](const std::string& id, void* app_ptr){
        return new Action(id, *((Application*) app_ptr));
    }, jlcxx::finalize_policy::yes); // use policy

compiles fine, meaning the change from boolean was a breaking change for my project

@barche
Copy link
Collaborator

barche commented Feb 27, 2024

Is this using the master branch of CxxWrap? libcxxwrap_julia 0.12 needs CxxWrap 0.15, which is currently unreleased but installable via CxxWrap#main or CxxWrap#testjll.

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