Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-07-31
18:45 • Closed ticket [63449c0514]: namespace children doesn't match non-glob patt... artifact: 51e89941a9 user: dgp
2024-12-16
09:59
Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace. check-in: 9f26385a03 user: jan.nijtmans tags: core-8-6-branch
2024-12-15
18:27
(backport): Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global ... check-in: da751091af user: jan.nijtmans tags: core-8-branch
17:57
Add explanation for fix for ticket [63449c0514] check-in: d39828737c user: oehhar tags: trunk, main
10:04 • Ticket [63449c0514] namespace children doesn't match non-glob patterns bel... artifact: ca69ae2676 user: oehhar
2024-12-14
23:40 • Ticket [63449c0514]: 3 changes artifact: 7026cc66a6 user: jan.nijtmans
23:38
Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace. ... check-in: b6ae5707d9 user: jan.nijtmans tags: trunk, main
2024-12-13
15:06 • Ticket [63449c0514] namespace children doesn't match non-glob patterns bel... artifact: 07b1d44ba1 user: jan.nijtmans
14:53
Proposed fix for [63449c0514]: [namespace children] doesn't match non-glob patterns below the global... closed check-in: ee821ec00f user: jan.nijtmans tags: bug-63449c0514
2024-12-02
15:02 • Ticket [63449c0514] namespace children doesn't match non-glob patterns bel... artifact: 2ffc6e8088 user: stu
2024-06-11
20:42 • Ticket [63449c0514]: 3 changes artifact: eb081ed907 user: stu
2024-02-22
07:33 • Ticket [63449c0514]: 3 changes artifact: 8554d6b183 user: stu
07:32 • Ticket [63449c0514]: 3 changes artifact: 57bdb05e85 user: stu
07:18 • Ticket [63449c0514]: 4 changes artifact: 8a9ab92662 user: stu
07:17 • New ticket [63449c0514]. artifact: 9d6c5d541b user: stu

[namespace children] doesn't match non-glob patterns below the global namespace

Closed / Fixed63449c05144fa85be0217ee3f82a78c6605bbdd3Created 3 years agoUpdated 1 year ago
Descriptionplain2024-02-22 07:17:55
# Create namespaces
namespace eval a { namespace eval b {} }

# Good result with non-glob pattern, and global namespace
namespace children :: a  ;# => ::a

# Good result with single-char glob pattern, and other namespace
namespace children a {[b]}  ;# => ::a::b

# Good result because of glob char in pattern, and other namespace
namespace children a b*  ;# => ::a::b

# Bad result with non-glob pattern, and other namespace
namespace children a b  ;# => {}


In generic/tclNamespace.c, function NamespaceChildrenCmd (lines 2988-3108), Tcl_StringMatch will be called if a glob char is present in the pattern, otherwise the matching will be performed with a combination of strncmp() and Tcl_FindHashEntry:
line 3067:  if ((pattern != NULL) && TclMatchIsTrivial(pattern)) {

The hash table lookup:
line 3075 or 3078:  Tcl_FindHashEntry(&nsPtr->childTable, pattern+length) != NULL

These two chars might be added but they won't be taken into account when matching: lines 3053-3055:
if (nsPtr != globalNsPtr) {
    TclDStringAppendLiteral(&buffer, "::");
}


With a quick hack patch:
-Tcl_FindHashEntry(&nsPtr->childTable, pattern+length) != NULL
+Tcl_FindHashEntry(&nsPtr->childTable, 2+pattern+length) != NULL

The child namespace can now be found:
namespace children a b  ;# => ::a::b

However namespace ::a can no longer be found in the global namespace!
namespace children :: a  ;# => {}


The two namespace separator ("::") chars are not being accounted for properly.
Referenced by5
  • 9f26385a03Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace. check-in2024-12-16 09:59:12
  • da751091af(backport): Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace. Also backport some formatting changes check-in2024-12-15 18:27:44
  • d39828737cAdd explanation for fix for ticket [63449c0514] check-in2024-12-15 17:57:10
  • b6ae5707d9Fix [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace. Candidate for inclusion in Tcl 9.0.1 (to be discussed) check-in2024-12-14 23:38:22
  • ee821ec00fProposed fix for [63449c0514]: [namespace children] doesn't match non-glob patterns below the global namespace check-in2024-12-13 14:53:09
stu Ticket [63449c0514]: 4 changes [History diff]2024-02-22 07:18:54
stuplain2024-02-22 07:32:03
This patch handles global and non-global. q&d poc

-Tcl_FindHashEntry(&nsPtr->childTable, 2+pattern+length) != NULL
+Tcl_FindHashEntry(&nsPtr->childTable, (nsPtr != globalNsPtr ? 2 : 0)+pattern+length) != NULL
stuplain2024-02-22 07:33:25
Correction:
-Tcl_FindHashEntry(&nsPtr->childTable, pattern+length) != NULL
+Tcl_FindHashEntry(&nsPtr->childTable, (nsPtr != globalNsPtr ? 2 : 0)+pattern+length) != NULL
stu Ticket [63449c0514]: 3 changes [History diff]2024-06-11 20:42:31
stuplain2024-12-02 15:02:07
The patch is just a suggestion.
The problem is an offset of 2 is not added when it should be.
I'm not familiar enough with the code to pick the best place to do this.
jan.nijtmanswiki2024-12-13 15:06:13

Proposed fix [here]

jan.nijtmanswiki2024-12-14 23:40:59

The CI build shows no regressions. So, Yes I think this should be included into Tcl 9.0.2 (to be discussed within the TTT).

Was this problem introduced in Tcl 8.7 or 9.0, or was it always there? Should it be backported to 8.7 and/or 8.6? Therefore, leaving this ticket open. No hurry to decide that.

oehhar (claiming to be oehar)wiki2024-12-15 10:04:56

Great ! I would love some explanatory text around the fix source. Maybe, I care tomorrow !

And it is 9.0.1, not 9.0.2, right ?

Take care, Harald

dgpplain2025-07-31 18:45:11
Backport landed on the 8.6 branch last December, so I guess
the decision got made.  Closing.
Log in (anonymous is fine) to add a comment.