Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 9d6c5d541b086a28ffe568297581c16d61ce2d0e300ddd90b35e2ffaade7008b
Ticket: 63449c05144fa85be0217ee3f82a78c6605bbdd3
[namespace children] doesn't match non-glob patterns below the global namespace
User & Date: stu on 2024-02-22 07:17:55
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
    # 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.
    
  5. foundin changed to: "Current"
  6. is_private changed to: "0"
  7. login: "stu"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "702b65e835b7b4b4720d6e9d37fc582f82909394"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "stu"
  14. subsystem changed to: "21. [namespace]"
  15. title changed to:
    [namespace children] doesn't match non-glob patterns below the global namespace
    
  16. type changed to: "Bug"