Compare commits

...
Author SHA1 Message Date
dgp b8064c3ab3 merge trunk 2012-12-03 21:04:37 +00:00
dgp d1bd703819 Rewrite [::unknown] making use of [tailcall]. Big reduction
in complexity, with minor cosmetic damage to -errorinfo results.
2012-11-30 21:39:48 +00:00
3 changed files with 10 additions and 59 deletions
+3
View File
@@ -8400,8 +8400,11 @@ TailcallCleanup(
Tcl_Interp *interp,
int result)
{
Interp *iPtr = (Interp *) interp;
Tcl_DecrRefCount((Tcl_Obj *) data[0]);
Tcl_DecrRefCount((Tcl_Obj *) data[1]);
iPtr->flags |= ERR_ALREADY_LOGGED;
return result;
}
+5 -57
View File
@@ -243,6 +243,10 @@ proc unknown args {
set savedErrorCode $::errorCode
}
if {[catch {set retry [dict get [info frame -1] cmd]}]} {
set retry $args
}
set name [lindex $args 0]
if {![info exists auto_noload]} {
#
@@ -275,63 +279,7 @@ proc unknown args {
} else {
unset -nocomplain ::errorInfo
}
set code [catch {uplevel 1 $args} msg opts]
if {$code == 1} {
#
# Compute stack trace contribution from the [uplevel].
# Note the dependence on how Tcl_AddErrorInfo, etc.
# construct the stack trace.
#
set errorInfo [dict get $opts -errorinfo]
set errorCode [dict get $opts -errorcode]
set cinfo $args
if {[string bytelength $cinfo] > 150} {
set cinfo [string range $cinfo 0 150]
while {[string bytelength $cinfo] > 150} {
set cinfo [string range $cinfo 0 end-1]
}
append cinfo ...
}
append cinfo "\"\n (\"uplevel\" body line 1)"
append cinfo "\n invoked from within"
append cinfo "\n\"uplevel 1 \$args\""
#
# Try each possible form of the stack trace
# and trim the extra contribution from the matching case
#
set expect "$msg\n while executing\n\"$cinfo"
if {$errorInfo eq $expect} {
#
# The stack has only the eval from the expanded command
# Do not generate any stack trace here.
#
dict unset opts -errorinfo
dict incr opts -level
return -options $opts $msg
}
#
# Stack trace is nested, trim off just the contribution
# from the extra "eval" of $args due to the "catch" above.
#
set expect "\n invoked from within\n\"$cinfo"
set exlen [string length $expect]
set eilen [string length $errorInfo]
set i [expr {$eilen - $exlen - 1}]
set einfo [string range $errorInfo 0 $i]
#
# For now verify that $errorInfo consists of what we are about
# to return plus what we expected to trim off.
#
if {$errorInfo ne "$einfo$expect"} {
error "Tcl bug: unexpected stack trace in \"unknown\"" {} \
[list CORE UNKNOWN BADTRACE $einfo $expect $errorInfo]
}
return -code error -errorcode $errorCode \
-errorinfo $einfo $msg
} else {
dict incr opts -level
return -options $opts $msg
}
tailcall try $retry
}
}
+2 -2
View File
@@ -151,7 +151,7 @@ foreach arg [subst -nocommands -novariables {
catch {parray a b $arg}
set first $::errorInfo
catch {parray a b $arg}
list $first $::errorInfo
list $first "$::errorInfo\n (\"try\" body line 1)"
} -match pairwise -result equal
test init-4.$count.1 {::errorInfo produced by [unknown]} -setup {
auto_reset
@@ -162,7 +162,7 @@ foreach arg [subst -nocommands -novariables {
catch {parray ::junk::$arg}
set first $::errorInfo
catch {parray ::junk::$arg}
list $first $::errorInfo
list $first "$::errorInfo\n (\"try\" body line 1)"
} -match pairwise -result equal
incr count