Skip to content

Commit 50a32d3

Browse files
author
Patrick Häcker
committed
Initialize global PROGRAM_FILE correctly
Julia 1.12 does not allow setting the global Base.PROGRAM_FILE from another module (probably Main) at program startup with the existing logic. There probably is a reason why the logic is so complicated. But I currently can't see it. Therefore, just use the already initialized Julia to simply do the work in Julia for all Julia versions instead of hand-crafting solutions which adapt to the evolving C API in different Julia versions. Fixes #1066
1 parent a9af8ed commit 50a32d3

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

src/embedding_wrapper.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,8 @@ int main(int argc, char *argv[]) {
140140

141141
// Update ARGS and PROGRAM_FILE
142142
checked_eval_string("append!(empty!(Base.ARGS), Core.ARGS)");
143-
jl_value_t *firstarg = checked_eval_string("popfirst!(ARGS)");
144-
JL_GC_PUSH1(&firstarg);
145-
jl_sym_t *var = jl_symbol("PROGRAM_FILE");
146-
#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR >= 12
147-
jl_binding_t *bp = jl_get_binding_wr(jl_base_module, var);
148-
jl_checked_assignment(bp, jl_base_module, var, firstarg);
149-
#elif JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR >= 11
150-
jl_binding_t *bp = jl_get_binding_wr(jl_base_module, var, /* alloc */ 1);
151-
jl_checked_assignment(bp, jl_base_module, var, firstarg);
152-
#elif JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR >= 10
153-
jl_binding_t *bp = jl_get_binding_wr(jl_base_module, var);
154-
jl_checked_assignment(bp, jl_base_module, var, firstarg);
155-
#elif JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR >= 9
156-
jl_binding_t *bp = jl_get_binding_wr(jl_base_module, var, 1);
157-
jl_checked_assignment(bp, firstarg);
158-
#else
159-
jl_set_global(jl_base_module, jl_symbol("PROGRAM_FILE"), firstarg);
160-
#endif
161-
JL_GC_POP();
143+
checked_eval_string("Core.eval(Base, :(global PROGRAM_FILE))");
144+
checked_eval_string("Base.PROGRAM_FILE = popfirst!(ARGS)");
162145

163146
// call the work function, and get back a value
164147
jl_value_t *jl_retcode = checked_eval_string(JULIA_MAIN "()");

0 commit comments

Comments
 (0)