Skip to content

Commit

Permalink
Merge pull request #11311 from yuyichao/warning-bt
Browse files Browse the repository at this point in the history
Print filename and line number for deprecation warnings
  • Loading branch information
timholy committed May 17, 2015
2 parents c039cf2 + 96fe11c commit 937f79e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ macro deprecate(old,new)
end

function depwarn(msg, funcsym)
if JLOptions().depwarn!=0
if JLOptions().depwarn != 0
ln = unsafe_load(cglobal(:jl_lineno, Int))
fn = bytestring(unsafe_load(cglobal(:jl_filename, Ptr{Cchar})))
bt = backtrace()
caller = firstcaller(bt, funcsym)
warn(msg, once=(caller!=C_NULL), key=caller, bt=bt)
warn(msg, once=(caller != C_NULL), key=caller, bt=bt,
filename=fn, lineno=ln)
end
end

Expand Down
8 changes: 6 additions & 2 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ const have_warned = Set()
warn_once(io::IO, msg...) = warn(io, msg..., once=true)
warn_once(msg...) = warn(STDERR, msg..., once=true)

function warn(io::IO, msg...; prefix="WARNING: ", once=false, key=nothing, bt=nothing)
function warn(io::IO, msg...;
prefix="WARNING: ", once=false, key=nothing, bt=nothing,
filename=nothing, lineno::Int=0)
str = chomp(string(msg...))
if once
if key === nothing
Expand All @@ -365,6 +367,9 @@ function warn(io::IO, msg...; prefix="WARNING: ", once=false, key=nothing, bt=no
if bt !== nothing
show_backtrace(io, bt)
end
if filename !== nothing
print(io, "\nwhile loading $filename, in expression starting on line $lineno")
end
println(io)
return
end
Expand All @@ -384,4 +389,3 @@ function julia_cmd(julia=joinpath(JULIA_HOME, julia_exename()))
end

julia_exename() = ccall(:jl_is_debugbuild,Cint,())==0 ? "julia" : "julia-debug"

10 changes: 8 additions & 2 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extern "C" {
#endif

// current line number in a file
int jl_lineno = 0;
DLLEXPORT int jl_lineno = 0;
// current file name
DLLEXPORT const char *jl_filename = "no file";

jl_module_t *jl_old_base_module = NULL;
// the Main we started with, in case it is switched
Expand Down Expand Up @@ -535,7 +537,9 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len)
{
//jl_printf(JL_STDERR, "***** loading %s\n", fname);
int last_lineno = jl_lineno;
jl_lineno=0;
const char *last_filename = jl_filename;
jl_lineno = 0;
jl_filename = fname;
jl_value_t *fn=NULL, *ln=NULL, *form=NULL, *result=jl_nothing;
JL_GC_PUSH4(&fn, &ln, &form, &result);
JL_TRY {
Expand All @@ -560,6 +564,7 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len)
fn = jl_pchar_to_string(fname, strlen(fname));
ln = jl_box_long(jl_lineno);
jl_lineno = last_lineno;
jl_filename = last_filename;
if (jl_loaderror_type == NULL) {
jl_rethrow();
}
Expand All @@ -570,6 +575,7 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len)
}
jl_stop_parsing();
jl_lineno = last_lineno;
jl_filename = last_filename;
JL_GC_POP();
return result;
}
Expand Down

0 comments on commit 937f79e

Please sign in to comment.