Skip to content

Commit

Permalink
init: keep argv C-array alive (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz authored Jan 1, 2025
1 parent 53cb9c3 commit f306981
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/GAP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ end
# path to JuliaInterface.so
const real_JuliaInterface_path = Ref{String}()
JuliaInterface_path() = real_JuliaInterface_path[]
const _saved_argv = Ref{Ref{Ptr{UInt8}}}()

function initialize(argv::Vector{String})
if use_jl_reinit_foreign_type()
Expand All @@ -127,12 +128,16 @@ function initialize(argv::Vector{String})
# TODO: turn this into a proper libgap API
unsafe_store!(cglobal((:SyLoadSystemInitFile, libgap), Int64), 0)

# the C data corresponding to argv needs to live forever
# as this is kept in the global SyOriginalArgv pointer in GAP
_saved_argv[] = Base.cconvert(Ptr{Ptr{UInt8}}, argv)

ccall(
(:GAP_Initialize, libgap),
Cvoid,
(Int32, Ptr{Ptr{UInt8}}, Ptr{Cvoid}, Ptr{Cvoid}, Cuint),
length(argv),
argv,
_saved_argv[],
C_NULL,
error_handler_func,
handle_signals,
Expand Down

0 comments on commit f306981

Please sign in to comment.