diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2006-10-20 14:04:00 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2006-10-20 14:04:00 (GMT) |
commit | 667340e02adf467adc84a317f84580be29dc5c71 (patch) | |
tree | 87fbdfd7e8dccb4c52676aa6746ada3820599088 /generic/tclVar.c | |
parent | e2b1c1973457dd38516163bd35af69fd75d9ec0f (diff) | |
download | tcl-667340e02adf467adc84a317f84580be29dc5c71.zip tcl-667340e02adf467adc84a317f84580be29dc5c71.tar.gz tcl-667340e02adf467adc84a317f84580be29dc5c71.tar.bz2 |
Consolidated TIP#257 patch applied to HEAD to allow for experimentation by
other developers
Diffstat (limited to 'generic/tclVar.c')
-rw-r--r-- | generic/tclVar.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c index 0576114..6e515d2 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclVar.c,v 1.122 2006/10/05 11:38:50 msofer Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.123 2006/10/20 14:04:01 dkf Exp $ */ #include "tclInt.h" @@ -39,6 +39,14 @@ static CONST char *isArrayElement = "name refers to an element in an array"; /* + * A test to see if we are in a call frame that has local variables. This is + * true if we are inside a procedure body or an object method body. + */ + +#define IsLocal(framePtr) \ + ((framePtr)->isProcCallFrame & (FRAME_IS_PROC | FRAME_IS_METHOD)) + +/* * Forward references to functions defined later in this file: */ @@ -399,7 +407,7 @@ TclObjLookupVar( int localIndex = (int) part1Ptr->internalRep.longValue; if ((varFramePtr != NULL) - && (varFramePtr->isProcCallFrame & FRAME_IS_PROC) + && IsLocal(varFramePtr) && !(flags & (TCL_GLOBAL_ONLY | TCL_NAMESPACE_ONLY)) && (localIndex < varFramePtr->numCompiledLocals)) { /* @@ -423,13 +431,12 @@ TclObjLookupVar( (flags & TCL_GLOBAL_ONLY) || (*part1==':' && *(part1+1)==':') || (varFramePtr == NULL) || - (!(varFramePtr->isProcCallFrame & FRAME_IS_PROC) - && (nsPtr == iPtr->globalNsPtr))); + (!IsLocal(varFramePtr) && (nsPtr == iPtr->globalNsPtr))); useReference = useGlobal || ((cachedNsPtr == nsPtr) && ( (flags & TCL_NAMESPACE_ONLY) || (varFramePtr && - !(varFramePtr->isProcCallFrame & FRAME_IS_PROC) && + !IsLocal(varFramePtr) && !(flags & TCL_GLOBAL_ONLY) && /* * Careful: an undefined ns variable could be hiding a valid @@ -745,7 +752,7 @@ TclLookupSimpleVar( if (((flags & (TCL_GLOBAL_ONLY | TCL_NAMESPACE_ONLY)) != 0) || (varFramePtr == NULL) - || !(varFramePtr->isProcCallFrame & FRAME_IS_PROC) + || !IsLocal(varFramePtr) || (strstr(varName, "::") != NULL)) { CONST char *tail; int lookGlobal; @@ -3239,7 +3246,7 @@ ObjMakeUpvar( if (((otherP2 ? arrayPtr->nsPtr : otherPtr->nsPtr) == NULL) && ((myFlags & (TCL_GLOBAL_ONLY | TCL_NAMESPACE_ONLY)) || (varFramePtr == NULL) - || !(varFramePtr->isProcCallFrame & FRAME_IS_PROC) + || !IsLocal(varFramePtr) || (strstr(myName, "::") != NULL))) { Tcl_AppendResult((Tcl_Interp *) iPtr, "bad variable name \"", myName, "\": upvar won't create namespace variable that ", @@ -3290,7 +3297,7 @@ TclPtrMakeUpvar( CONST char *p; if (index >= 0) { - if (!(varFramePtr->isProcCallFrame & FRAME_IS_PROC)) { + if (!IsLocal(varFramePtr)) { Tcl_Panic("ObjMakeUpvar called with an index outside from a proc"); } varPtr = &(varFramePtr->compiledLocals[index]); @@ -3553,8 +3560,7 @@ Tcl_GlobalObjCmd( * If we are not executing inside a Tcl procedure, just return. */ - if ((iPtr->varFramePtr == NULL) - || !(iPtr->varFramePtr->isProcCallFrame & FRAME_IS_PROC)) { + if ((iPtr->varFramePtr == NULL) || !IsLocal(iPtr->varFramePtr)) { return TCL_OK; } @@ -3705,8 +3711,7 @@ Tcl_VariableObjCmd( * linked to the new namespace variable "varName". */ - if ((iPtr->varFramePtr != NULL) - && (iPtr->varFramePtr->isProcCallFrame & FRAME_IS_PROC)) { + if ((iPtr->varFramePtr != NULL) && IsLocal(iPtr->varFramePtr)) { /* * varName might have a scope qualifier, but the name for the * local "link" variable must be the simple name at the tail. |