Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-10-09
14:51 • Ticket [477c24cb39] rename ::set and lose custom return options status still... artifact: 4351a960d3 user: dkf
2016-09-02
08:06 • Ticket [477c24cb39]: 3 changes artifact: 004f9305e9 user: pooryorick
2016-09-01
17:35 • Ticket [477c24cb39]: 3 changes artifact: cb4fc19f21 user: dgp
17:31 • Ticket [477c24cb39]: 3 changes artifact: be1a192f33 user: dgp
17:05 • Ticket [477c24cb39]: 3 changes artifact: 32273ff810 user: dgp
13:24 • Ticket [477c24cb39]: 3 changes artifact: 3a7097884b user: aspect
13:04 • Ticket [477c24cb39]: 3 changes artifact: d35c9e82db user: aspect
2016-08-31
11:17 • New ticket [477c24cb39]. artifact: 6791daeac0 user: pooryorick

rename ::set and lose custom return options

Open477c24cb39e3c502dec0329583256072211ea4d3Created 10 years agoUpdated 10 years ago
Descriptionwiki2016-08-31 11:17:04
In the following example, -custom1 1 is missing from $options in p2

namespace eval ns1 {
	rename ::set [namespace current]::set
	interp alias {} ::set {} [namespace current]::set
}

proc p1 {} {
	return -options {-custom1 1} {result 1} 
}

proc p2 {} {
	catch {set status [p1]} result options
	puts $options
} 

p2
aspectplain2016-09-01 13:04:34
This thread seems to go deep:

proc p0 {} {
	list result 0
}
proc p1 {} {
	return -options {-custom1 1} {result 1}
}

proc t0 {} {
	list [catch {p1; p0} r o] $r $o
}

proc t1 {} {
	list [catch {p1} r o] $r $o
}

proc t2 {} {
	list [catch {p1; list result 2} r o] $r $o
}

puts [t0]
puts [t1]
puts [t2]
# 0 {result 0} {-code 0 -level 0}
# 0 {result 1} {-custom1 1 -code 0 -level 0}
# 0 {result 2} {-custom1 1 -code 0 -level 0}
</verbatim></code>

It looks on first glance like bytecode instructions are not resetting returnOpts.  Or are t1 and t2 expected?
aspectplain2016-09-01 13:24:02
Related?

% list [catch {unset -nocomplain t} r o] $r $o
0 {} {-code 0 -level 0}
% list [catch {incr t} r o] $r $o
0 1 {-code 0 -level 0 -errorcode {TCL READ VARNAME}}
% list [catch {incr t} r o] $r $o
0 2 {-code 0 -level 0}
dgpplain2016-09-01 17:05:38
Some of the comments here are Dups of

http://core.tcl.tk/tcl/tktview?name=2433843

Not sure about the original report yet.
dgpplain2016-09-01 17:31:00
Here's another demo, that I find more focused:

proc p1 {} {return -custom1 1 1}
proc p2 {b} {
    if {$b} {
        catch {set status [p1]} m o
    } else {
        set set set
        catch {$set status [p1]} m o
    }
    return $o
}
puts [p2 0]
puts [p2 1]

Demonstrates a clear difference in bytecode
execution compared to non-bytecode script evaluation.
They ought to be the same and they are not, so yes
there's a bug.

This leads to an unsettling debate over which
is correct.  How long should a return
option survive when return code is TCL_OK ?
dgpplain2016-09-01 17:35:49
Change p1 to:

proc p1 {} {return -custom 1 -code 10 1}

so that a custom code is used along with
a custom option (which was the use case)
and see that that case preserves the option
in both branches.
pooryorickplain2016-09-02 08:06:24
So the bug is the inverse of what I originally reported.  It's not that <code>-custom1 1</code> is missing from <code>$options</code>, but that it's present if the example doesn't rename the "::set" command.  Thank you for the analysis.
dkfwiki2016-10-09 14:51:26

Tempted to suggest not fixing given the performance impact it would have, but dgp invented the custom return option machinery so he can worry about the impact.

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