From 17b2152b59677828539fa420e11f2b11e79450f9 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 8 Mar 2024 13:30:18 +0000 Subject: TclGetNamespaceForQualName: TCL_FIND_IF_NOT_SIMPLE considers alternate search path too --- generic/tclNamesp.c | 32 ++++++++++++++++++++------------ 1 file 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; } -- cgit v0.12