Skip to content
Tcl Source Code View Ticket
Login

View Ticket

unexpected 'result' in trace execution leave

Open2811381fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 47 days ago
Descriptionplain2009-06-24 08:48:13
trace manpage says:
For leave and leavestep operations: command command-string code result op
[...] result [gives] the result string.
When multiple traces are set on name, then [...] for leave and leavestep operations, the traced commands are invoked in the original order of creation.

However, it doesn't say that the 'result' is taken from original command only for first trace. Each following trace takes 'result' from previous traced command. This is not completely unwanted, but rather unexpected. For multiple traces, each of them has to return it's 'result' argument, in other case next trace might fail. Manual should be clearer on that.

Example:
% proc traced {} {return hello}
% proc trace_1st {cmdstr code result op} {puts "first: $result"; return first}
% trace add execution traced leave trace_1st
% traced
first: hello
hello
% proc trace_2nd {cmdstr code result op} {puts "second: $result"; return second}
% trace add execution traced leave trace_2nd
% traced
first: hello
second: first
hello
%
Referenced by1
  • 6fd61eb7c4Fix [2811381fff]: since 8.5 each leave or leavestep trace got the result of the previous trace instead of that of the traced command. Restore the saved interpreter state after each successful trace, as 8.4 did. check-in2026-10-17 06:58:12
anonymous Ticket [2811381fff]: 6 changes [History diff]2014-09-23 11:07:39
serhiy.storchakawiki2026-10-17 06:59:46

8.4 passed the result of the traced command to every leave trace; since 8.5 TclCheckExecutionTraces() and TclCheckInterpTraces() restore the saved result only after the last trace, so each trace gets the result of the previous one. The documentation describes the 8.4 behaviour. Proposed fix in branch leave-trace-own-result: restore the result after each trace. Test trace-40.2.

Log in (anonymous is fine) to add a comment.