Skip to content

Commit c5cb029

Browse files
fix JuliaLang#42411, restore export of jl_options (JuliaLang#42416)
Co-authored-by: Jameson Nash <[email protected]>
1 parent 203d234 commit c5cb029

File tree

9 files changed

+138
-99
lines changed

9 files changed

+138
-99
lines changed

cli/loader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define realloc loader_realloc
2323
#endif
2424

25+
#include <stdint.h>
26+
2527
#ifdef _OS_WINDOWS_
2628
#define WIN32_LEAN_AND_MEAN
2729
#include <windows.h>
@@ -91,3 +93,5 @@ int wchar_to_utf8(const wchar_t * wstr, char *str, size_t maxlen);
9193
int utf8_to_wchar(const char * str, wchar_t *wstr, size_t maxlen);
9294
void setup_stdio(void);
9395
#endif
96+
97+
#include "../src/jloptions.h"

cli/loader_lib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
183183
}
184184
(*jl_exported_func_addrs[symbol_idx]) = addr;
185185
}
186+
187+
// jl_options must be initialized very early, in case an embedder sets some
188+
// values there before calling jl_init
189+
((void (*)(void))jl_init_options_addr)();
186190
}
187191

188192
// Load libjulia and run the REPL with the given arguments (in UTF-8 format)

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ifeq ($(USE_SYSTEM_LIBUV),0)
9999
UV_HEADERS += uv.h
100100
UV_HEADERS += uv/*.h
101101
endif
102-
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h)
102+
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h jloptions.h)
103103
HEADERS := $(PUBLIC_HEADERS) $(addprefix $(SRCDIR)/,julia_internal.h options.h timing.h) $(addprefix $(BUILDDIR)/,$(DTRACE_HEADERS) jl_internal_funcs.inc)
104104
PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,julia_gcext.h)
105105
PUBLIC_HEADER_TARGETS := $(addprefix $(build_includedir)/julia/,$(notdir $(PUBLIC_HEADERS)) $(UV_HEADERS))

src/jl_exported_data.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,5 @@
127127

128128
// Data symbols that are defined inside the public libjulia
129129
#define JL_EXPORTED_DATA_SYMBOLS(XX) \
130-
XX(jl_n_threads, int)
130+
XX(jl_n_threads, int) \
131+
XX(jl_options, jl_options_t)

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
XX(jl_init_restored_modules) \
273273
XX(jl_init_with_image) \
274274
XX(jl_init_with_image__threading) \
275+
XX(jl_init_options) \
275276
XX(jl_install_sigint_handler) \
276277
XX(jl_instantiate_type_in_env) \
277278
XX(jl_instantiate_unionall) \

src/jloptions.c

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,56 +28,65 @@ JL_DLLEXPORT const char *jl_get_default_sysimg_path(void)
2828
}
2929

3030

31-
jl_options_t jl_options = { 0, // quiet
32-
-1, // banner
33-
NULL, // julia_bindir
34-
NULL, // julia_bin
35-
NULL, // cmds
36-
NULL, // image_file (will be filled in below)
37-
NULL, // cpu_target ("native", "core2", etc...)
38-
0, // nthreads
39-
0, // nprocs
40-
NULL, // machine_file
41-
NULL, // project
42-
0, // isinteractive
43-
0, // color
44-
JL_OPTIONS_HISTORYFILE_ON, // history file
45-
0, // startup file
46-
JL_OPTIONS_COMPILE_DEFAULT, // compile_enabled
47-
0, // code_coverage
48-
0, // malloc_log
49-
2, // opt_level
50-
0, // opt_level_min
31+
static int jl_options_initialized = 0;
32+
33+
JL_DLLEXPORT void jl_init_options(void)
34+
{
35+
if (jl_options_initialized)
36+
return;
37+
jl_options =
38+
(jl_options_t){ 0, // quiet
39+
-1, // banner
40+
NULL, // julia_bindir
41+
NULL, // julia_bin
42+
NULL, // cmds
43+
NULL, // image_file (will be filled in below)
44+
NULL, // cpu_target ("native", "core2", etc...)
45+
0, // nthreads
46+
0, // nprocs
47+
NULL, // machine_file
48+
NULL, // project
49+
0, // isinteractive
50+
0, // color
51+
JL_OPTIONS_HISTORYFILE_ON, // history file
52+
0, // startup file
53+
JL_OPTIONS_COMPILE_DEFAULT, // compile_enabled
54+
0, // code_coverage
55+
0, // malloc_log
56+
2, // opt_level
57+
0, // opt_level_min
5158
#ifdef JL_DEBUG_BUILD
52-
2, // debug_level [debug build]
59+
2, // debug_level [debug build]
5360
#else
54-
1, // debug_level [release build]
61+
1, // debug_level [release build]
5562
#endif
56-
JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds
57-
JL_OPTIONS_DEPWARN_OFF, // deprecation warning
58-
0, // method overwrite warning
59-
1, // can_inline
60-
JL_OPTIONS_POLLY_ON, // polly
61-
NULL, // trace_compile
62-
JL_OPTIONS_FAST_MATH_DEFAULT,
63-
0, // worker
64-
NULL, // cookie
65-
JL_OPTIONS_HANDLE_SIGNALS_ON,
66-
JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES,
67-
JL_OPTIONS_USE_COMPILED_MODULES_YES,
68-
NULL, // bind-to
69-
NULL, // output-bc
70-
NULL, // output-unopt-bc
71-
NULL, // output-o
72-
NULL, // output-asm
73-
NULL, // output-ji
74-
NULL, // output-code_coverage
75-
0, // incremental
76-
0, // image_file_specified
77-
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
78-
0, // image-codegen
79-
0, // rr-detach
80-
};
63+
JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds
64+
JL_OPTIONS_DEPWARN_OFF, // deprecation warning
65+
0, // method overwrite warning
66+
1, // can_inline
67+
JL_OPTIONS_POLLY_ON, // polly
68+
NULL, // trace_compile
69+
JL_OPTIONS_FAST_MATH_DEFAULT,
70+
0, // worker
71+
NULL, // cookie
72+
JL_OPTIONS_HANDLE_SIGNALS_ON,
73+
JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES,
74+
JL_OPTIONS_USE_COMPILED_MODULES_YES,
75+
NULL, // bind-to
76+
NULL, // output-bc
77+
NULL, // output-unopt-bc
78+
NULL, // output-o
79+
NULL, // output-asm
80+
NULL, // output-ji
81+
NULL, // output-code_coverage
82+
0, // incremental
83+
0, // image_file_specified
84+
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
85+
0, // image-codegen
86+
0, // rr-detach
87+
};
88+
jl_options_initialized = 1;
89+
}
8190

8291
static const char usage[] = "julia [switches] -- [programfile] [args...]\n";
8392
static const char opts[] =

src/jloptions.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
#ifndef JL_JLOPTIONS_H
4+
#define JL_JLOPTIONS_H
5+
6+
// NOTE: This struct needs to be kept in sync with JLOptions type in base/options.jl
7+
8+
typedef struct {
9+
int8_t quiet;
10+
int8_t banner;
11+
const char *julia_bindir;
12+
const char *julia_bin;
13+
const char **cmds;
14+
const char *image_file;
15+
const char *cpu_target;
16+
int32_t nthreads;
17+
int32_t nprocs;
18+
const char *machine_file;
19+
const char *project;
20+
int8_t isinteractive;
21+
int8_t color;
22+
int8_t historyfile;
23+
int8_t startupfile;
24+
int8_t compile_enabled;
25+
int8_t code_coverage;
26+
int8_t malloc_log;
27+
int8_t opt_level;
28+
int8_t opt_level_min;
29+
int8_t debug_level;
30+
int8_t check_bounds;
31+
int8_t depwarn;
32+
int8_t warn_overwrite;
33+
int8_t can_inline;
34+
int8_t polly;
35+
const char *trace_compile;
36+
int8_t fast_math;
37+
int8_t worker;
38+
const char *cookie;
39+
int8_t handle_signals;
40+
int8_t use_sysimage_native_code;
41+
int8_t use_compiled_modules;
42+
const char *bindto;
43+
const char *outputbc;
44+
const char *outputunoptbc;
45+
const char *outputo;
46+
const char *outputasm;
47+
const char *outputji;
48+
const char *output_code_coverage;
49+
int8_t incremental;
50+
int8_t image_file_specified;
51+
int8_t warn_scope;
52+
int8_t image_codegen;
53+
int8_t rr_detach;
54+
} jl_options_t;
55+
56+
#endif

src/julia.h

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,56 +2005,11 @@ JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT; // deprecated
20052005
JL_DLLEXPORT void jl_(void *jl_value) JL_NOTSAFEPOINT;
20062006

20072007
// julia options -----------------------------------------------------------
2008-
// NOTE: This struct needs to be kept in sync with JLOptions type in base/options.jl
2009-
typedef struct {
2010-
int8_t quiet;
2011-
int8_t banner;
2012-
const char *julia_bindir;
2013-
const char *julia_bin;
2014-
const char **cmds;
2015-
const char *image_file;
2016-
const char *cpu_target;
2017-
int32_t nthreads;
2018-
int32_t nprocs;
2019-
const char *machine_file;
2020-
const char *project;
2021-
int8_t isinteractive;
2022-
int8_t color;
2023-
int8_t historyfile;
2024-
int8_t startupfile;
2025-
int8_t compile_enabled;
2026-
int8_t code_coverage;
2027-
int8_t malloc_log;
2028-
int8_t opt_level;
2029-
int8_t opt_level_min;
2030-
int8_t debug_level;
2031-
int8_t check_bounds;
2032-
int8_t depwarn;
2033-
int8_t warn_overwrite;
2034-
int8_t can_inline;
2035-
int8_t polly;
2036-
const char *trace_compile;
2037-
int8_t fast_math;
2038-
int8_t worker;
2039-
const char *cookie;
2040-
int8_t handle_signals;
2041-
int8_t use_sysimage_native_code;
2042-
int8_t use_compiled_modules;
2043-
const char *bindto;
2044-
const char *outputbc;
2045-
const char *outputunoptbc;
2046-
const char *outputo;
2047-
const char *outputasm;
2048-
const char *outputji;
2049-
const char *output_code_coverage;
2050-
int8_t incremental;
2051-
int8_t image_file_specified;
2052-
int8_t warn_scope;
2053-
int8_t image_codegen;
2054-
int8_t rr_detach;
2055-
} jl_options_t;
2056-
2057-
extern JL_DLLEXPORT jl_options_t jl_options;
2008+
2009+
#include "jloptions.h"
2010+
2011+
extern JL_DLLIMPORT jl_options_t jl_options;
2012+
20582013
JL_DLLEXPORT ssize_t jl_sizeof_jl_options(void);
20592014

20602015
// Parse an argc/argv pair to extract general julia options, passing back out

test/embedding/embedding.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jl_value_t *checked_eval_string(const char* code)
3232

3333
int main()
3434
{
35+
// check that setting options works
36+
jl_options.opt_level = 1;
37+
3538
jl_init();
3639

3740
{
@@ -40,6 +43,12 @@ int main()
4043
checked_eval_string("println(sqrt(2.0))");
4144
}
4245

46+
if (jl_options.opt_level != 1) {
47+
jl_printf(jl_stderr_stream(), "setting jl_options didn't work\n");
48+
jl_atexit_hook(1);
49+
exit(1);
50+
}
51+
4352
{
4453
// Accessing the return value
4554

0 commit comments

Comments
 (0)