Skip to content

Commit

Permalink
retain compatibility with code that assumes `importall Base.Operators…
Browse files Browse the repository at this point in the history
…`, but

give warnings
  • Loading branch information
JeffBezanson committed Jul 28, 2015
1 parent 3bb7e2f commit 1dde6e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module CHOLMOD

import Base: (*), convert, copy, eltype, getindex, show, showarray, size,
linearindexing, LinearFast, LinearSlow
linearindexing, LinearFast, LinearSlow, ctranspose

import Base.LinAlg: (\), A_mul_Bc, A_mul_Bt, Ac_ldiv_B, Ac_mul_B, At_ldiv_B, At_mul_B,
cholfact, det, diag, ishermitian, isposdef,
Expand Down
2 changes: 2 additions & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ static void jl_serialize_module(ios_t *s, jl_module_t *m)
}
jl_serialize_value(s, m->constant_table);
write_uint8(s, m->istopmod);
write_uint8(s, m->std_imports);
write_uint64(s, m->uuid);
}

Expand Down Expand Up @@ -1336,6 +1337,7 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
m->constant_table = (jl_array_t*)jl_deserialize_value(s, (jl_value_t**)&m->constant_table);
if (m->constant_table != NULL) jl_gc_wb(m, m->constant_table);
m->istopmod = read_uint8(s);
m->std_imports = read_uint8(s);
m->uuid = read_uint64(s);
return (jl_value_t*)m;
}
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ typedef struct _jl_module_t {
jl_array_t *constant_table;
jl_function_t *call_func; // cached lookup of `call` within this module
uint8_t istopmod;
uint8_t std_imports; // only for temporarily deprecating `importall Base.Operators`
uint64_t uuid;
} jl_module_t;

Expand Down
20 changes: 20 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jl_module_t *jl_new_module(jl_sym_t *name)
m->constant_table = NULL;
m->call_func = NULL;
m->istopmod = 0;
m->std_imports = 0;
m->uuid = uv_now(uv_default_loop());
htable_new(&m->bindings, 0);
arraylist_new(&m->usings, 0);
Expand Down Expand Up @@ -120,6 +121,16 @@ DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var)
// and overwriting.
DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var)
{
if (jl_base_module && m->std_imports && !jl_binding_resolved_p(m,var)) {
jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators"));
if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) {
jl_printf(JL_STDERR,
"WARNING: module %s should explicitly import %s from %s\n",
m->name->name, var->name, jl_base_module->name->name);
jl_module_import(m, opmod, var);
}
}

jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var);
jl_binding_t *b = *bp;

Expand All @@ -133,6 +144,15 @@ DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *
jl_errorf("error in method definition: %s.%s cannot be extended", b->owner->name->name, var->name);
}
else {
if (jl_base_module && b->owner == jl_base_module) {
jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators"));
if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) {
jl_printf(JL_STDERR,
"WARNING: module %s should explicitly import %s from %s\n",
m->name->name, var->name, b->owner->name->name);
return b2;
}
}
jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", b->owner->name->name, var->name);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void jl_add_standard_imports(jl_module_t *m)
jl_module_using(m, jl_base_module);
// import Base.call
jl_module_import(m, jl_base_module, jl_symbol("call"));
m->std_imports = 1;
}

jl_module_t *jl_new_main_module(void)
Expand Down

0 comments on commit 1dde6e1

Please sign in to comment.