119
119
# In case the line numbers in the source code have changed since the code was compiled,
120
120
# allow packages to set a callback function that corrects them.
121
121
# (Used by Revise and perhaps other packages.)
122
- default_methodloc (method:: Method ) = method. file, method. line
123
- const methodloc_callback = Ref {Function} (default_methodloc)
122
+ const methodloc_callback = Ref {Union{Function, Nothing}} (nothing )
123
+
124
+ # This function does the method location updating
125
+ function updated_methodloc (m:: Method ):: Tuple{String, Int32}
126
+ file, line = m. file, m. line
127
+ if methodloc_callback[] != = nothing
128
+ try
129
+ file, line = invokelatest (methodloc_callback[], m)
130
+ catch
131
+ end
132
+ end
133
+ # The file defining Base.Sys gets included after this file is included so make sure
134
+ # this function is valid even in this intermediary state
135
+ if isdefined (@__MODULE__ , :Sys ) && Sys. BUILD_STDLIB_PATH != Sys. STDLIB
136
+ # BUILD_STDLIB_PATH gets defined in sysinfo.jl
137
+ file = replace (string (file), normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
138
+ end
139
+ return string (file), line
140
+ end
124
141
125
142
functionloc (m:: Core.MethodInstance ) = functionloc (m. def)
126
143
@@ -130,7 +147,7 @@ functionloc(m::Core.MethodInstance) = functionloc(m.def)
130
147
Returns a tuple `(filename,line)` giving the location of a `Method` definition.
131
148
"""
132
149
function functionloc (m:: Method )
133
- file, ln = invokelatest (methodloc_callback[], m)
150
+ file, ln = updated_methodloc ( m)
134
151
if ln <= 0
135
152
error (" could not determine location of method definition" )
136
153
end
@@ -195,10 +212,7 @@ function show(io::IO, m::Method)
195
212
show_method_params (io, tv)
196
213
print (io, " in " , m. module)
197
214
if line > 0
198
- try
199
- file, line = invokelatest (methodloc_callback[], m)
200
- catch
201
- end
215
+ file, line = updated_methodloc (m)
202
216
print (io, " at " , file, " :" , line)
203
217
end
204
218
end
@@ -247,11 +261,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
247
261
println (io)
248
262
print (io, " [$(n) ] " )
249
263
show (io, meth)
250
- file, line = meth. file, meth. line
251
- try
252
- file, line = invokelatest (methodloc_callback[], meth)
253
- catch
254
- end
264
+ file, line = updated_methodloc (meth)
255
265
push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
256
266
else
257
267
rest += 1
@@ -361,10 +371,7 @@ function show(io::IO, ::MIME"text/html", m::Method)
361
371
end
362
372
print (io, " in " , m. module)
363
373
if line > 0
364
- try
365
- file, line = invokelatest (methodloc_callback[], m)
366
- catch
367
- end
374
+ file, line = updated_methodloc (m)
368
375
u = url (m)
369
376
if isempty (u)
370
377
print (io, " at " , file, " :" , line)
@@ -398,11 +405,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
398
405
first = false
399
406
print (io, " [$(i) ] " )
400
407
show (io, m)
401
- file, line = m. file, m. line
402
- try
403
- file, line = invokelatest (methodloc_callback[], m)
404
- catch
405
- end
408
+ file, line = updated_methodloc (m)
406
409
push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
407
410
end
408
411
end
0 commit comments