Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

call _init() in modules at init time. closes #1268

  • Loading branch information...
commit 2044a41dafa6fbabc0b8ff2cadd104f8fb018d19 1 parent fffd879
@JeffBezanson JeffBezanson authored
View
17 base/client.jl
@@ -336,11 +336,6 @@ function init_head_sched()
register_worker(LPROC)
end
-function init_profiler()
- # Use a max size of 1M profile samples, and fire timer every 1ms
- Profile.init(1_000_000, 0.001)
-end
-
function load_juliarc()
# If the user built us with a specific Base.SYSCONFDIR, check that location first for a juliarc.jl file
# If it is not found, then continue on to the relative path based on JULIA_HOME
@@ -354,25 +349,13 @@ end
function _start()
- # set up standard streams
- reinit_stdio()
- fdwatcher_reinit()
- # Initialize RNG
- Random.librandom_init()
- Sys.init()
global const CPU_CORES = Sys.CPU_CORES
if CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
# Prevent openblas from stating to many threads, unless/until specifically requested
ENV["OPENBLAS_NUM_THREADS"] = 8
end
- # Check that BLAS is correctly built
- check_blas()
- LinAlg.init()
- GMP.gmp_init()
- init_profiler()
start_gc_msgs_task()
- #atexit(()->flush(STDOUT))
try
any(a->(a=="--worker"), ARGS) || init_head_sched()
init_load_path()
View
2  base/gmp.jl
@@ -24,7 +24,7 @@ end
_gmp_clear_func = C_NULL
_mpfr_clear_func = C_NULL
-function gmp_init()
+function _init()
global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp))
global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr))
ccall((:__gmp_set_memory_functions, :libgmp), Void,
View
4 base/linalg.jl
@@ -38,7 +38,6 @@ export
axpy!,
bkfact,
bkfact!,
- check_blas,
chol,
cholfact,
cholfact!,
@@ -214,7 +213,8 @@ include("linalg/cholmod.jl")
include("linalg/arpack.jl")
include("linalg/arnoldi.jl")
-function init()
+function _init()
+ Base.check_blas()
if Base.blas_vendor() == :mkl
ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Void, (Cint,), USE_BLAS64 ? 1 : 0)
end
View
2  base/multimedia.jl
@@ -2,7 +2,7 @@ module Multimedia
export Display, display, pushdisplay, popdisplay, displayable, redisplay,
MIME, @MIME, @MIME_str, writemime, reprmime, stringmime, istext,
- mimewritable, TextDisplay, reinit_displays
+ mimewritable, TextDisplay
###########################################################################
# We define a singleton type MIME{mime symbol} for each MIME type, so
View
14 base/poll.jl
@@ -171,10 +171,10 @@ end
# on unix
let
- global fdwatcher_reinit
+ global fdwatcher_init
@unix_only begin
- local fdwatcher_array = Array(FDWatcher,0)
- function fdwatcher_reinit()
+ local fdwatcher_array
+ function fdwatcher_init()
fdwatcher_array = Array(FDWatcher,0)
end
@@ -190,8 +190,8 @@ let
end
end
@windows_only begin
- local fdwatcher_array = Dict{WindowsRawSocket,FDWatcher}()
- function fdwatcher_reinit()
+ local fdwatcher_array
+ function fdwatcher_init()
fdwatcher_array = Dict{WindowsRawSocket,FDWatcher}()
end
@@ -208,6 +208,10 @@ let
end
end
+module _FDWatcherInitializer
+_init() = Base.fdwatcher_init()
+end
+
function pfw_wait_cb(pfw::PollingFileWatcher, prev, cur, status)
if status < 0
notify_error(pfw.notify,UVError("PollingFileWatcher",status))
View
2  base/precompile.jl
@@ -23,7 +23,7 @@ precompile(cmp, (Int32, Int32))
precompile(min, (Int32, Int32))
precompile(==, (ASCIIString, ASCIIString))
precompile(arg_gen, (ASCIIString,))
-precompile(Random.librandom_init, ())
+precompile(Random._init, ())
precompile(Random.srand, (ASCIIString, Int))
precompile(Random.srand, (Uint64,))
precompile(open, (ASCIIString, Bool, Bool, Bool, Bool))
View
4 base/profile.jl
@@ -28,6 +28,10 @@ function init(n::Integer, delay::Float64)
end
end
+# init with default values
+# Use a max size of 1M profile samples, and fire timer every 1ms
+_init() = init(1_000_000, 0.001)
+
clear() = ccall(:jl_profile_clear_data, Void, ())
function print{T<:Unsigned}(io::IO = STDOUT, data::Vector{T} = fetch(); format = :tree, C = false, combine = true, cols = Base.tty_cols())
View
2  base/random.jl
@@ -44,7 +44,7 @@ end
## initialization
-function librandom_init()
+function _init()
@unix_only begin
try
View
1  base/stream.jl
@@ -241,7 +241,6 @@ function reinit_stdio()
global STDIN = init_stdio(ccall(:jl_stdin_stream ,Ptr{Void},()))
global STDOUT = init_stdio(ccall(:jl_stdout_stream,Ptr{Void},()))
global STDERR = init_stdio(ccall(:jl_stderr_stream,Ptr{Void},()))
- reinit_displays() # since Multimedia.displays uses STDOUT as fallback
end
flush(::AsyncStream) = nothing
View
8 base/sysimg.jl
@@ -105,7 +105,13 @@ importall .FS
include("process.jl")
include("multimedia.jl")
importall .Multimedia
-reinit_stdio()
+module _IOInitializer
+function _init()
+ Base.reinit_stdio()
+ Base.Multimedia.reinit_displays() # since Multimedia.displays uses STDOUT as fallback
+end
+end
+# TODO: should put this in _init, but need to handle its boolean argument correctly
ccall(:jl_get_uv_hooks, Void, (Cint,), 0)
include("grisu.jl")
import .Grisu.print_shortest
View
2  base/sysinfo.jl
@@ -19,7 +19,7 @@ export CPU_CORES,
import ..Base: WORD_SIZE, OS_NAME, ARCH, MACHINE
import ..Base: show, uv_error
-function init()
+function _init()
# set CPU core count
global const CPU_CORES = int(
haskey(ENV,"JULIA_CPU_CORES") ?
View
14 src/dump.c
@@ -39,6 +39,9 @@ static jl_value_t *jl_idtable_type=NULL;
// queue of types to cache
static jl_array_t *datatype_list=NULL;
+// queue of modules to initialize
+static arraylist_t modules_to_init;
+
#define write_uint8(s, n) ios_putc((n), (s))
#define read_uint8(s) ((uint8_t)ios_getc(s))
#define write_int8(s, n) write_uint8(s, n)
@@ -833,6 +836,8 @@ static jl_value_t *jl_deserialize_value_internal(ios_t *s)
arraylist_push(&m->usings, jl_deserialize_value(s));
}
m->constant_table = (jl_array_t*)jl_deserialize_value(s);
+ if (jl_module_has_initializer(m))
+ arraylist_push(&modules_to_init, m);
return (jl_value_t*)m;
}
else if (vtag == (jl_value_t*)SmallInt64_tag) {
@@ -1073,6 +1078,14 @@ void jl_restore_system_image(char *fname)
jl_update_all_fptrs();
}
+void jl_init_restored_modules()
+{
+ while (modules_to_init.len > 0) {
+ jl_module_t *m = arraylist_pop(&modules_to_init);
+ jl_module_run_initializer(m);
+ }
+}
+
DLLEXPORT
jl_value_t *jl_ast_rettype(jl_lambda_info_t *li, jl_value_t *ast)
{
@@ -1153,6 +1166,7 @@ void jl_init_serializer(void)
htable_new(&fptr_to_id, 0);
htable_new(&id_to_fptr, 0);
htable_new(&backref_table, 50000);
+ arraylist_new(&modules_to_init, 0);
void *tags[] = { jl_symbol_type, jl_datatype_type,
jl_function_type, jl_tuple_type, jl_array_type,
View
3  src/init.c
@@ -816,6 +816,9 @@ void julia_init(char *imageFile)
#ifdef JL_GC_MARKSWEEP
jl_gc_enable();
#endif
+
+ if (imageFile)
+ jl_init_restored_modules();
}
DLLEXPORT void jl_install_sigint_handler()
View
3  src/julia.h
@@ -797,6 +797,8 @@ STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name)
{
return (jl_function_t*) jl_get_global(m, jl_symbol(name));
}
+DLLEXPORT int jl_module_has_initializer(jl_module_t *m);
+DLLEXPORT void jl_module_run_initializer(jl_module_t *m);
// eq hash tables
DLLEXPORT jl_array_t *jl_eqtable_put(jl_array_t *h, void *key, void *val);
@@ -860,6 +862,7 @@ DLLEXPORT extern char *julia_home;
DLLEXPORT void jl_save_system_image(char *fname);
DLLEXPORT void jl_restore_system_image(char *fname);
+void jl_init_restored_modules();
// front end interface
DLLEXPORT jl_value_t *jl_parse_input_line(const char *str);
View
20 src/module.c
@@ -418,3 +418,23 @@ DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported)
DLLEXPORT jl_sym_t *jl_module_name(jl_module_t *m) { return m->name; }
DLLEXPORT jl_module_t *jl_module_parent(jl_module_t *m) { return m->parent; }
+
+int jl_module_has_initializer(jl_module_t *m)
+{
+ return jl_get_global(m, jl_symbol("_init")) != NULL;
+}
+
+void jl_module_run_initializer(jl_module_t *m)
+{
+ jl_value_t *f = jl_get_global(m, jl_symbol("_init"));
+ if (f == NULL || !jl_is_function(f))
+ return;
+ JL_TRY {
+ jl_apply((jl_function_t*)f, NULL, 0);
+ }
+ JL_CATCH {
+ JL_PRINTF(JL_STDERR, "Warning: error initializing module %s:\n", m->name->name);
+ jl_static_show(JL_STDERR, jl_exception_in_transit);
+ JL_PRINTF(JL_STDERR, "\n");
+ }
+}
View
3  src/toplevel.c
@@ -150,6 +150,9 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
}
}
#endif
+
+ jl_module_run_initializer(newm);
+
return jl_nothing;
}
Please sign in to comment.
Something went wrong with that request. Please try again.