diff options
| author | sebres <sebres@users.sourceforge.net> | 2024-03-08 13:30:18 (GMT) |
|---|---|---|
| committer | sebres <sebres@users.sourceforge.net> | 2024-03-08 13:30:18 (GMT) |
| commit | 49f6fe769712854083c260db59905a5ba7a3152d (patch) | |
| tree | 2ae1090041e08180e8078702368a8354459d1ef3 | |
| parent | a902a4808e1202d7a59cacf78a902068c8ae9689 (diff) | |
| download | tcl-49f6fe769712854083c260db59905a5ba7a3152d.zip tcl-49f6fe769712854083c260db59905a5ba7a3152d.tar.gz tcl-49f6fe769712854083c260db59905a5ba7a3152d.tar.bz2 | |
TclGetNamespaceForQualName: TCL_FIND_IF_NOT_SIMPLE considers alternate search path too
| -rw-r--r-- | generic/tclNamesp.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 099e29f..f7d1a7d 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -2189,7 +2189,7 @@ TclGetNamespaceForQualName( * TCL_FIND_ONLY_NS was specified. */ { Interp *iPtr = (Interp *) interp; - Namespace *nsPtr = cxtNsPtr; + Namespace *nsPtr = cxtNsPtr, *lastNsPtr = NULL, *lastAltNsPtr = NULL; Namespace *altNsPtr; Namespace *globalNsPtr = iPtr->globalNsPtr; const char *start, *end; @@ -2330,17 +2330,12 @@ TclGetNamespaceForQualName( if (nsPtr == NULL) { Tcl_Panic("Could not create namespace '%s'", nsName); } - } else { /* Namespace not found and was not - * created. */ - if (flags & TCL_FIND_IF_NOT_SIMPLE) { - /* - * return last found NS and not simple name relative it, - * e. g. ::A::B::C::D -> ::A::B and C::D, if - * namespace C cannot be found in ::A::B - */ - *simpleNamePtr = start; - goto done; - } + } else { + /* + * Namespace not found and was not created. + * Remember last found namespace for TCL_FIND_IF_NOT_SIMPLE. + */ + lastNsPtr = nsPtr; nsPtr = NULL; } } @@ -2362,6 +2357,8 @@ TclGetNamespaceForQualName( if (entryPtr != NULL) { altNsPtr = (Namespace *)Tcl_GetHashValue(entryPtr); } else { + /* Remember last found in alternate path */ + lastAltNsPtr = altNsPtr; altNsPtr = NULL; } } @@ -2371,6 +2368,17 @@ TclGetNamespaceForQualName( */ if ((nsPtr == NULL) && (altNsPtr == NULL)) { + if (flags & TCL_FIND_IF_NOT_SIMPLE) { + /* + * return last found NS, regardless simple name or not, + * e. g. ::A::B::C::D -> ::A::B and C::D, if namespace C + * cannot be found in ::A::B + */ + nsPtr = lastNsPtr; + altNsPtr = lastAltNsPtr; + *simpleNamePtr = start; + goto done; + } *simpleNamePtr = NULL; goto done; } |
