Skip to content

Commit

Permalink
fix #42411, restore export of jl_options (#42416)
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <[email protected]>
(cherry picked from commit c5cb029)
  • Loading branch information
JeffBezanson authored and KristofferC committed Oct 5, 2021
1 parent 388f5df commit d42ae5a
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 99 deletions.
4 changes: 4 additions & 0 deletions cli/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define realloc loader_realloc
#endif

#include <stdint.h>

#ifdef _OS_WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Expand Down Expand Up @@ -91,3 +93,5 @@ int wchar_to_utf8(const wchar_t * wstr, char *str, size_t maxlen);
int utf8_to_wchar(const char * str, wchar_t *wstr, size_t maxlen);
void setup_stdio(void);
#endif

#include "../src/jloptions.h"
4 changes: 4 additions & 0 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
}
(*jl_exported_func_addrs[symbol_idx]) = addr;
}

// jl_options must be initialized very early, in case an embedder sets some
// values there before calling jl_init
((void (*)(void))jl_init_options_addr)();
}

// Load libjulia and run the REPL with the given arguments (in UTF-8 format)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SRCS += $(RUNTIME_SRCS)
# headers are used for dependency tracking, while public headers will be part of the dist
UV_HEADERS :=
HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h locks.h atomics.h julia_internal.h options.h timing.h)
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h locks.h atomics.h julia_gcext.h)
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h locks.h atomics.h julia_gcext.h jloptions.h)
ifeq ($(USE_SYSTEM_LIBUV),0)
UV_HEADERS += uv.h
UV_HEADERS += uv/*.h
Expand Down
3 changes: 2 additions & 1 deletion src/jl_exported_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@

// Data symbols that are defined inside the public libjulia
#define JL_EXPORTED_DATA_SYMBOLS(XX) \
XX(jl_n_threads, int)
XX(jl_n_threads, int) \
XX(jl_options, jl_options_t)
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
XX(jl_init_with_image) \
XX(jl_init__threading) \
XX(jl_init_with_image__threading) \
XX(jl_init_options) \
XX(jl_install_sigint_handler) \
XX(jl_instantiate_type_in_env) \
XX(jl_instantiate_unionall) \
Expand Down
103 changes: 56 additions & 47 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,65 @@ JL_DLLEXPORT const char *jl_get_default_sysimg_path(void)
}


jl_options_t jl_options = { 0, // quiet
-1, // banner
NULL, // julia_bindir
NULL, // julia_bin
NULL, // cmds
NULL, // image_file (will be filled in below)
NULL, // cpu_target ("native", "core2", etc...)
0, // nthreads
0, // nprocs
NULL, // machine_file
NULL, // project
0, // isinteractive
0, // color
JL_OPTIONS_HISTORYFILE_ON, // history file
0, // startup file
JL_OPTIONS_COMPILE_DEFAULT, // compile_enabled
0, // code_coverage
0, // malloc_log
2, // opt_level
0, // opt_level_min
static int jl_options_initialized = 0;

JL_DLLEXPORT void jl_init_options(void)
{
if (jl_options_initialized)
return;
jl_options =
(jl_options_t){ 0, // quiet
-1, // banner
NULL, // julia_bindir
NULL, // julia_bin
NULL, // cmds
NULL, // image_file (will be filled in below)
NULL, // cpu_target ("native", "core2", etc...)
0, // nthreads
0, // nprocs
NULL, // machine_file
NULL, // project
0, // isinteractive
0, // color
JL_OPTIONS_HISTORYFILE_ON, // history file
0, // startup file
JL_OPTIONS_COMPILE_DEFAULT, // compile_enabled
0, // code_coverage
0, // malloc_log
2, // opt_level
0, // opt_level_min
#ifdef JL_DEBUG_BUILD
2, // debug_level [debug build]
2, // debug_level [debug build]
#else
1, // debug_level [release build]
1, // debug_level [release build]
#endif
JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds
JL_OPTIONS_DEPWARN_OFF, // deprecation warning
0, // method overwrite warning
1, // can_inline
JL_OPTIONS_POLLY_ON, // polly
NULL, // trace_compile
JL_OPTIONS_FAST_MATH_DEFAULT,
0, // worker
NULL, // cookie
JL_OPTIONS_HANDLE_SIGNALS_ON,
JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES,
JL_OPTIONS_USE_COMPILED_MODULES_YES,
NULL, // bind-to
NULL, // output-bc
NULL, // output-unopt-bc
NULL, // output-o
NULL, // output-asm
NULL, // output-ji
NULL, // output-code_coverage
0, // incremental
0, // image_file_specified
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
0, // image-codegen
0, // rr-detach
};
JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds
JL_OPTIONS_DEPWARN_OFF, // deprecation warning
0, // method overwrite warning
1, // can_inline
JL_OPTIONS_POLLY_ON, // polly
NULL, // trace_compile
JL_OPTIONS_FAST_MATH_DEFAULT,
0, // worker
NULL, // cookie
JL_OPTIONS_HANDLE_SIGNALS_ON,
JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES,
JL_OPTIONS_USE_COMPILED_MODULES_YES,
NULL, // bind-to
NULL, // output-bc
NULL, // output-unopt-bc
NULL, // output-o
NULL, // output-asm
NULL, // output-ji
NULL, // output-code_coverage
0, // incremental
0, // image_file_specified
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
0, // image-codegen
0, // rr-detach
};
jl_options_initialized = 1;
}

static const char usage[] = "julia [switches] -- [programfile] [args...]\n";
static const char opts[] =
Expand Down
56 changes: 56 additions & 0 deletions src/jloptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#ifndef JL_JLOPTIONS_H
#define JL_JLOPTIONS_H

// NOTE: This struct needs to be kept in sync with JLOptions type in base/options.jl

typedef struct {
int8_t quiet;
int8_t banner;
const char *julia_bindir;
const char *julia_bin;
const char **cmds;
const char *image_file;
const char *cpu_target;
int32_t nthreads;
int32_t nprocs;
const char *machine_file;
const char *project;
int8_t isinteractive;
int8_t color;
int8_t historyfile;
int8_t startupfile;
int8_t compile_enabled;
int8_t code_coverage;
int8_t malloc_log;
int8_t opt_level;
int8_t opt_level_min;
int8_t debug_level;
int8_t check_bounds;
int8_t depwarn;
int8_t warn_overwrite;
int8_t can_inline;
int8_t polly;
const char *trace_compile;
int8_t fast_math;
int8_t worker;
const char *cookie;
int8_t handle_signals;
int8_t use_sysimage_native_code;
int8_t use_compiled_modules;
const char *bindto;
const char *outputbc;
const char *outputunoptbc;
const char *outputo;
const char *outputasm;
const char *outputji;
const char *output_code_coverage;
int8_t incremental;
int8_t image_file_specified;
int8_t warn_scope;
int8_t image_codegen;
int8_t rr_detach;
} jl_options_t;

#endif
55 changes: 5 additions & 50 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2006,56 +2006,11 @@ JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT; // deprecated
JL_DLLEXPORT void jl_(void *jl_value) JL_NOTSAFEPOINT;

// julia options -----------------------------------------------------------
// NOTE: This struct needs to be kept in sync with JLOptions type in base/options.jl
typedef struct {
int8_t quiet;
int8_t banner;
const char *julia_bindir;
const char *julia_bin;
const char **cmds;
const char *image_file;
const char *cpu_target;
int32_t nthreads;
int32_t nprocs;
const char *machine_file;
const char *project;
int8_t isinteractive;
int8_t color;
int8_t historyfile;
int8_t startupfile;
int8_t compile_enabled;
int8_t code_coverage;
int8_t malloc_log;
int8_t opt_level;
int8_t opt_level_min;
int8_t debug_level;
int8_t check_bounds;
int8_t depwarn;
int8_t warn_overwrite;
int8_t can_inline;
int8_t polly;
const char *trace_compile;
int8_t fast_math;
int8_t worker;
const char *cookie;
int8_t handle_signals;
int8_t use_sysimage_native_code;
int8_t use_compiled_modules;
const char *bindto;
const char *outputbc;
const char *outputunoptbc;
const char *outputo;
const char *outputasm;
const char *outputji;
const char *output_code_coverage;
int8_t incremental;
int8_t image_file_specified;
int8_t warn_scope;
int8_t image_codegen;
int8_t rr_detach;
} jl_options_t;

extern JL_DLLEXPORT jl_options_t jl_options;

#include "jloptions.h"

extern JL_DLLIMPORT jl_options_t jl_options;

JL_DLLEXPORT ssize_t jl_sizeof_jl_options(void);

// Parse an argc/argv pair to extract general julia options, passing back out
Expand Down
9 changes: 9 additions & 0 deletions test/embedding/embedding.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jl_value_t *checked_eval_string(const char* code)

int main()
{
// check that setting options works
jl_options.opt_level = 1;

jl_init();

{
Expand All @@ -40,6 +43,12 @@ int main()
checked_eval_string("println(sqrt(2.0))");
}

if (jl_options.opt_level != 1) {
jl_printf(jl_stderr_stream(), "setting jl_options didn't work\n");
jl_atexit_hook(1);
exit(1);
}

{
// Accessing the return value

Expand Down

0 comments on commit d42ae5a

Please sign in to comment.