Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: cd834503730875953e326d54f562db43f1cbdd60
Ticket: 217966ffffffffffffffffffffffffffffffffff
patch to provide 'namespace exists' subcommand
User & Date: nobody on 2000-10-26 00:46:54
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 4666 RFE
    Version: 8.3
    SubmitDate: '2000-03-28'
    LastModified: '2000-03-28'
    Severity: LOW
    Status: Closed
    Submitter: techsupp
    ChangedBy: ericm
    RelatedBugIDs: 4665
    OS: Windows NT
    OSVersion: 4.0sp5
    FixedDate: '2000-10-25'
    ClosedDate: '2000-03-28'
    
    
    Name:
    
    Vince Darley
    
    
    CVS:
    
    Tues March 28 2000
    
    
    Comments:
    
    Compiles and runs fine on WinNT, since it's a simple generic patch, I
    
        assume it will work on Unix/MacOS too.
    
    
    DesiredBehavior:
    
    simple addition of 'namespace exists' so we can quickly and easily test if a namespace exists without special-casing children ns/with or without leading ::/...
    
    
    Patch:
    
    Index: tclNamesp.c
    
    ===================================================================
    
    RCS file: /cvsroot/tcl/generic/tclNamesp.c,v
    
    retrieving revision 1.17
    
    diff -C3 -r1.17 tclNamesp.c
    
    *** tclNamesp.c2000/03/27 22:18:561.17
    
    --- tclNamesp.c2000/03/29 00:01:43
    
    ***************
    
    *** 104,109 ****
    
    --- 104,112 ----
    
      static intNamespaceEvalCmd _ANSI_ARGS_((
    
          ClientData dummy, Tcl_Interp *interp,
    
          int objc, Tcl_Obj *CONST objv[]));
    
    + static intNamespaceExistsCmd _ANSI_ARGS_((
    
    +     ClientData dummy, Tcl_Interp *interp,
    
    +     int objc, Tcl_Obj *CONST objv[]));
    
      static intNamespaceExportCmd _ANSI_ARGS_((
    
          ClientData dummy, Tcl_Interp *interp,
    
          int objc, Tcl_Obj *CONST objv[]));
    
    ***************
    
    *** 2409,2414 ****
    
    --- 2412,2418 ----
    
       *    namespace current
    
       *    namespace delete ?name name...?
    
       *    namespace eval name arg ?arg...?
    
    +  *    namespace exists name
    
       *    namespace export ?-clear? ?pattern pattern...?
    
       *    namespace forget ?pattern pattern...?
    
       *    namespace import ?-force? ?pattern pattern...?
    
    ***************
    
    *** 2444,2455 ****
    
      {
    
          static char *subCmds[] = {
    
                  "children", "code", "current", "delete",
    
    !     "eval", "export", "forget", "import",
    
          "inscope", "origin", "parent", "qualifiers",
    
          "tail", "which", (char *) NULL};
    
          enum NSSubCmdIdx {
    
          NSChildrenIdx, NSCodeIdx, NSCurrentIdx, NSDeleteIdx,
    
    !     NSEvalIdx, NSExportIdx, NSForgetIdx, NSImportIdx,
    
          NSInscopeIdx, NSOriginIdx, NSParentIdx, NSQualifiersIdx,
    
          NSTailIdx, NSWhichIdx
    
          };
    
    --- 2448,2459 ----
    
      {
    
          static char *subCmds[] = {
    
                  "children", "code", "current", "delete",
    
    !     "eval", "exists", "export", "forget", "import",
    
          "inscope", "origin", "parent", "qualifiers",
    
          "tail", "which", (char *) NULL};
    
          enum NSSubCmdIdx {
    
          NSChildrenIdx, NSCodeIdx, NSCurrentIdx, NSDeleteIdx,
    
    !     NSEvalIdx, NSExistsIdx, NSExportIdx, NSForgetIdx, NSImportIdx,
    
          NSInscopeIdx, NSOriginIdx, NSParentIdx, NSQualifiersIdx,
    
          NSTailIdx, NSWhichIdx
    
          };
    
    ***************
    
    *** 2486,2491 ****
    
    --- 2490,2498 ----
    
              case NSEvalIdx:
    
          result = NamespaceEvalCmd(clientData, interp, objc, objv);
    
                  break;
    
    + case NSExistsIdx:
    
    +     result = NamespaceExistsCmd(clientData, interp, objc, objv);
    
    +     break;
    
              case NSExportIdx:
    
          result = NamespaceExportCmd(clientData, interp, objc, objv);
    
                  break;
    
    ***************
    
    *** 2946,2951 ****
    
    --- 2953,3006 ----
    
    
          Tcl_PopCallFrame(interp);
    
          return result;
    
    + }
    
    +  
    
    + /*
    
    +  *----------------------------------------------------------------------
    
    +  *
    
    +  * NamespaceExistsCmd --
    
    +  *
    
    +  *Invoked to implement the "namespace exists" command that returns 
    
    +  *true if the given namespace currently exists, and false otherwise.
    
    +  *Handles the following syntax:
    
    +  *
    
    +  *    namespace exists name
    
    +  *
    
    +  * Results:
    
    +  *Returns TCL_OK if successful, and TCL_ERROR if anything goes wrong.
    
    +  *
    
    +  * Side effects:
    
    +  *Returns a result in the interpreter's result object. If anything
    
    +  *goes wrong, the result is an error message.
    
    +  *
    
    +  *----------------------------------------------------------------------
    
    +  */
    
    + 
    
    + static int
    
    + NamespaceExistsCmd(dummy, interp, objc, objv)
    
    +     ClientData dummy;/* Not used. */
    
    +     Tcl_Interp *interp;/* Current interpreter. */
    
    +     int objc;/* Number of arguments. */
    
    +     Tcl_Obj *CONST objv[];/* Argument objects. */
    
    + {
    
    +     Tcl_Namespace *namespacePtr;
    
    +     Tcl_Obj *resultPtr;
    
    + 
    
    +     if (objc != 3) {
    
    + Tcl_WrongNumArgs(interp, 2, objv, "name");
    
    + return TCL_ERROR;
    
    +     }
    
    + 
    
    +     /*
    
    +      * Check whether the given namespace exists
    
    +      */
    
    + 
    
    +     resultPtr = Tcl_GetObjResult(interp);
    
    +     if (GetNamespaceFromObj(interp, objv[2], &namespacePtr) != TCL_OK) {
    
    + return TCL_ERROR;
    
    +     }
    
    +     Tcl_SetBooleanObj(resultPtr, (namespacePtr == NULL) ? 0 : 1);
    
    +     return TCL_OK;
    
      }
    
    
      /*
    
    
    PatchFiles:
    
    tclNamesp.c
    
    
    
    
    
    
  4. foundin changed to: "obsolete: 8.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to: "patch to provide 'namespace exists' subcommand"
  11. type changed to: "RFE"