diff options
author | sebres <sebres@users.sourceforge.net> | 2019-09-06 20:22:30 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2019-09-06 20:22:30 (GMT) |
commit | d0f808008dd96dd8b4ba1988087dbb644ac63283 (patch) | |
tree | a64cb5bd017baed0526b8a24a160c60dcf8f68f7 | |
parent | 5ed9c57d7a6452cb9bb3ae0c72953cbbf7b81c24 (diff) | |
download | tcl-d0f808008dd96dd8b4ba1988087dbb644ac63283.zip tcl-d0f808008dd96dd8b4ba1988087dbb644ac63283.tar.gz tcl-d0f808008dd96dd8b4ba1988087dbb644ac63283.tar.bz2 |
if frameName (actual level) does not contain a real level (#0 or 1) historically TclGetFrame and Tcl_UpVar2 uses current level - 1, so to put supplied name in case of bad level (error at top - 1) is wrong;
be more consistent with TclObjGetFrame (at least in error case if relative level used).
-rw-r--r-- | generic/tclProc.c | 11 | ||||
-rw-r--r-- | tests/upvar.test | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/generic/tclProc.c b/generic/tclProc.c index f1e0148..2ee2456 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -713,17 +713,22 @@ TclGetFrame( result = 1; curLevel = iPtr->varFramePtr->level; if (*name== '#') { - if (Tcl_GetInt(interp, name+1, &level) != TCL_OK || level < 0) { + if (Tcl_GetInt(NULL, name+1, &level) != TCL_OK || level < 0) { goto levelError; } } else if (isdigit(UCHAR(*name))) { /* INTL: digit */ - if (Tcl_GetInt(interp, name, &level) != TCL_OK) { + if (Tcl_GetInt(NULL, name, &level) != TCL_OK) { goto levelError; } level = curLevel - level; } else { + /* + * (historical, TODO) If name does not contain a level (#0 or 1), + * TclGetFrame and Tcl_UpVar2 uses current level - 1 + */ level = curLevel - 1; result = 0; + name = "1"; /* be more consistent with TclObjGetFrame (error at top - 1) */ } /* @@ -812,7 +817,7 @@ TclObjGetFrame( } level = curLevel - level; } else if (*name == '#') { - if (Tcl_GetInt(interp, name+1, &level) != TCL_OK || level < 0) { + if (Tcl_GetInt(NULL, name+1, &level) != TCL_OK || level < 0) { goto levelError; } diff --git a/tests/upvar.test b/tests/upvar.test index f41fe1b..cba2fb9 100644 --- a/tests/upvar.test +++ b/tests/upvar.test @@ -357,7 +357,7 @@ test upvar-8.11 {upvar will not create a variable that looks like an array} -bod test upvar-9.1 {Tcl_UpVar2 procedure} testupvar { list [catch {testupvar xyz a {} x global} msg] $msg -} {1 {bad level "xyz"}} +} {1 {bad level "1"}} test upvar-9.2 {Tcl_UpVar2 procedure} testupvar { catch {unset a} catch {unset x} |