summaryrefslogtreecommitdiffstats
path: root/share/txr/stdlib/trace.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-03-17 06:47:48 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-03-17 06:47:48 -0700
commitdb2d654347e06fe7e40a498eee02e523936f4a53 (patch)
tree0da95354c8786d5d75299dd63a1c62a64b32c04c /share/txr/stdlib/trace.tl
parent047647e0896f5b8b7d08df0c34c18c224b7fa2eb (diff)
downloadtxr-db2d654347e06fe7e40a498eee02e523936f4a53.tar.gz
txr-db2d654347e06fe7e40a498eee02e523936f4a53.tar.bz2
txr-db2d654347e06fe7e40a498eee02e523936f4a53.zip
trace: implement redefinition checks.
The tracing module should warn when traced functions or methods are being redefined, and stop tracing the original methods. * eval.c (trace_check): New function. Calls sys:trace-redefined-check if the trace module has been loaded, otherwise does nothing. (op_defun, op_defmacro): Call trace_check to have a warning issued for a redefined traced function or macro. * eval.h (trace_check): Declared. * lisplib.c (trace_loaded): New global variable. (trace_instantiate): Flip trace_loaded to t. * lisplib.h (trace_loaded): Declared. * share/txr/stdlib/trace.tl (sys:trace-redefine-check): New function. Checks two situations: traced function or method is redefined (neither old nor new is traced any longer), and traced method is overridden (base method continues to be traced, override is not traced). * struct.c (static_slot_ensure): Do a trace check here, taking care of defmeth.
Diffstat (limited to 'share/txr/stdlib/trace.tl')
-rw-r--r--share/txr/stdlib/trace.tl15
1 files changed, 15 insertions, 0 deletions
diff --git a/share/txr/stdlib/trace.tl b/share/txr/stdlib/trace.tl
index a184dbc8..940425c2 100644
--- a/share/txr/stdlib/trace.tl
+++ b/share/txr/stdlib/trace.tl
@@ -67,6 +67,21 @@
(dohash (n v sys:*trace-hash*)
(disable n n)))))
+(defun sys:trace-redefine-check (orig-name)
+ (let ((name (sys:trace-canonicalize-name orig-name)))
+ (when [sys:*trace-hash* name]
+ (catch
+ (cond
+ ((neq name orig-name)
+ (throwf 'warning "~!~s won't be traced, though it overrides\n\
+ ~s which is currently traced"
+ name orig-name))
+ (t (throwf 'warning "previously traced ~s is redefined and no\ \
+ longer traced"
+ name)
+ (sys:untrace (list name))))
+ (continue ())))))
+
(defmacro trace (. names)
^(sys:trace ',names))