diff --git a/src/c_interface.cpp b/src/c_interface.cpp index e10f479..e4f3111 100644 --- a/src/c_interface.cpp +++ b/src/c_interface.cpp @@ -140,45 +140,52 @@ JLCXX_API jl_array_t* get_module_functions(jl_module_t* jlmod) Array arg_types_array; jl_value_t* boxed_f = nullptr; jl_value_t* boxed_thunk = nullptr; - Array arg_names_array; - Array arg_default_values_array; - jl_value_t* boxed_n_kwargs; - JL_GC_PUSH6(arg_types_array.gc_pointer(), &boxed_f, &boxed_thunk, arg_names_array.gc_pointer(), arg_default_values_array.gc_pointer(), &boxed_n_kwargs); - - fill_types_vec(arg_types_array, f.argument_types()); - - boxed_f = jlcxx::box(f.pointer()); - boxed_thunk = jlcxx::box(f.thunk()); - - fill_values_vec(arg_names_array, f.argument_names()); - fill_values_vec(arg_default_values_array, f.argument_default_values()); - - boxed_n_kwargs = jlcxx::box(f.number_of_keyword_arguments()); - - auto returntypes = f.return_type(); - - jl_datatype_t* ccall_return_type = returntypes.first; - jl_datatype_t* julia_return_type = returntypes.second; - if(ccall_return_type == nullptr) + JL_GC_PUSH3(arg_types_array.gc_pointer(), &boxed_f, &boxed_thunk); { - ccall_return_type = julia_type(); - julia_return_type = ccall_return_type; + Array arg_names_array; + JL_GC_PUSH1(arg_names_array.gc_pointer()); + { + Array arg_default_values_array; + jl_value_t* boxed_n_kwargs = nullptr; + JL_GC_PUSH2(arg_default_values_array.gc_pointer(), &boxed_n_kwargs); + + fill_types_vec(arg_types_array, f.argument_types()); + + boxed_f = jlcxx::box(f.pointer()); + boxed_thunk = jlcxx::box(f.thunk()); + + fill_values_vec(arg_names_array, f.argument_names()); + fill_values_vec(arg_default_values_array, f.argument_default_values()); + + boxed_n_kwargs = jlcxx::box(f.number_of_keyword_arguments()); + + auto returntypes = f.return_type(); + + jl_datatype_t* ccall_return_type = returntypes.first; + jl_datatype_t* julia_return_type = returntypes.second; + if(ccall_return_type == nullptr) + { + ccall_return_type = julia_type(); + julia_return_type = ccall_return_type; + } + + function_array.push_back(jl_new_struct(g_cppfunctioninfo_type, + f.name(), + arg_types_array.wrapped(), + ccall_return_type, + julia_return_type, + boxed_f, + boxed_thunk, + f.override_module(), + f.doc(), + arg_names_array.wrapped(), + arg_default_values_array.wrapped(), + boxed_n_kwargs + )); + JL_GC_POP(); + } + JL_GC_POP(); } - - function_array.push_back(jl_new_struct(g_cppfunctioninfo_type, - f.name(), - arg_types_array.wrapped(), - ccall_return_type, - julia_return_type, - boxed_f, - boxed_thunk, - f.override_module(), - f.doc(), - arg_names_array.wrapped(), - arg_default_values_array.wrapped(), - boxed_n_kwargs - )); - JL_GC_POP(); }); JL_GC_POP();