Skip to content
Tcl Source Code History Of Ticket 218279
Login

History Of Ticket 218279

Artifacts Associated With Ticket 218279

  1. Ticket change [3d7dd17b10] (rid 121100) by nobody on 2000-10-26 00:55:26:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 3398 RFE
      Version: 8.2.1
      SubmitDate: '1999-11-05'
      LastModified: '1999-11-17'
      Severity: LOW
      Status: Closed
      Submitter: techsupp
      ChangedBy: hobbs
      OS: Other
      FixedDate: '2000-10-25'
      ClosedDate: '1999-11-17'
      
      
      Name:
      
      Eric Boudaillier
      
      
      CustomShell:
      
      array command modified (function Tcl_ArrayObjCmd())
      
      
      Comments:
      
      This patch is not usable as is.
      
          array foreach make tcl crash if array is unset inside body
      
          Can something be done to avoid this ?
      
      
      DesiredBehavior:
      
      new array command:
      
            array foreach arrayName keyVarName ?pattern? body
      
      
          array foreach can be an alternative of array
      
          startsearch/nextelement/donesearch
      
          for large array, with the gain of a pattern.
      
          Syntax is cleaner.
      
          Better performance ?
      
      
      Patch:
      
      *** tclVar.orig.cThu Oct 21 08:36:25 1999
      
      --- tclVar.cThu Oct 21 09:23:45 1999
      
      ***************
      
      *** 2843,2852 ****
      
             * below.
      
             */
      
      
      !     enum {ARRAY_ANYMORE, ARRAY_DONESEARCH,  ARRAY_EXISTS, ARRAY_GET,
      
          ARRAY_NAMES, ARRAY_NEXTELEMENT, ARRAY_SET, ARRAY_SIZE,
      
          ARRAY_STARTSEARCH}; 
      
      !     static char *arrayOptions[] = {"anymore", "donesearch", "exists",
      
           "get", "names", "nextelement", "set",
      
           "size", "startsearch", (char *) NULL};
      
      
      --- 2843,2852 ----
      
             * below.
      
             */
      
      
      !     enum {ARRAY_ANYMORE, ARRAY_DONESEARCH,  ARRAY_EXISTS, ARRAY_FOREACH, ARRAY_GET,
      
          ARRAY_NAMES, ARRAY_NEXTELEMENT, ARRAY_SET, ARRAY_SIZE,
      
          ARRAY_STARTSEARCH}; 
      
      !     static char *arrayOptions[] = {"anymore", "donesearch", "exists", "foreach",
      
           "get", "names", "nextelement", "set",
      
           "size", "startsearch", (char *) NULL};
      
      
      ***************
      
      *** 2973,2978 ****
      
      --- 2973,3045 ----
      
            Tcl_SetIntObj(resultPtr, !notArray);
      
            break;
      
        }
      
      +         case ARRAY_FOREACH: {
      
      +     Tcl_HashSearch search;
      
      +     Var *varPtr2;
      
      +             Tcl_Obj *nameVar;
      
      +             Tcl_Obj *bodyPtr;
      
      +             Tcl_Obj *namePtr;
      
      +             Tcl_Obj *resPtr;
      
      +             char *name;
      
      +             char *pattern;
      
      + 
      
      +             if ((objc != 5) && (objc != 6)) {
      
      +                 Tcl_WrongNumArgs(interp, 2, objv,
      
      +                                  "arrayName nameVar ?pattern? body");
      
      +                 return TCL_ERROR;
      
      +             }
      
      +             if (notArray) {
      
      +                 return TCL_OK;
      
      +             }
      
      +             nameVar  = objv[3];
      
      +             if (objc == 5) {
      
      +                 pattern = NULL;
      
      +                 bodyPtr = objv[4];
      
      +             } else {
      
      +                 pattern = TclGetString(objv[4]);
      
      +                 bodyPtr = objv[5];
      
      +             }
      
      +     for (hPtr = Tcl_FirstHashEntry(varPtr->value.tablePtr, &search);
      
      +  hPtr != NULL;  hPtr = Tcl_NextHashEntry(&search)) {
      
      +         varPtr2 = (Var *) Tcl_GetHashValue(hPtr);
      
      + if (TclIsVarUndefined(varPtr2)) {
      
      +     continue;
      
      + }
      
      + name = Tcl_GetHashKey(varPtr->value.tablePtr, hPtr);
      
      + if ((pattern != NULL) && !Tcl_StringMatch(name, pattern)) {
      
      +     continue;/* element name doesn't match pattern */
      
      + }
      
      +                 /* name variable assignment */
      
      + namePtr = Tcl_NewStringObj(name, -1);
      
      +                 resPtr = Tcl_ObjSetVar2(interp, nameVar, (Tcl_Obj*) NULL, namePtr,
      
      +                                         TCL_PARSE_PART1 | TCL_LEAVE_ERR_MSG);
      
      +                 if (resPtr == NULL) {
      
      +                     return TCL_ERROR;
      
      +                 }
      
      + 
      
      +                 result = Tcl_EvalObjEx(interp, bodyPtr, 0);
      
      +                 if (result != TCL_OK) {
      
      +                     if (result == TCL_CONTINUE) {
      
      +                         result = TCL_OK;
      
      +                     } else if (result == TCL_BREAK) {
      
      +                         result = TCL_OK;
      
      +                         break;
      
      +                     } else if (result == TCL_ERROR) {
      
      +                         char msg[64];
      
      + 
      
      +                         sprintf(msg, "\n    (\"array foreach\" body line %d)",
      
      +                                 interp->errorLine);
      
      +                         Tcl_AddObjErrorInfo(interp, msg, -1);
      
      +                         break;
      
      +                     }
      
      +                 }
      
      +             }
      
      +             if (result != TCL_OK) {
      
      +                 return result;
      
      +             }
      
      +             Tcl_ResetResult(interp);
      
      +     break;
      
      + }
      
                case ARRAY_GET: {
      
            Tcl_HashSearch search;
      
            Var *varPtr2;
      
      
      PatchFiles:
      
      generic/tclVar.c
      
      
      
      
      This is already quite simple with
         foreach name [array names] ...
      and is thus more efficient as the foreach is optimized for this. 
      -- 11/17/1999 hobbs
      
    4. foundin initialized to: "obsolete: 8.2.1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to: "array foreach"
    11. type initialized to: "RFE"
  2. Ticket change [43a2ee7863] (rid 116596) by welch on 2000-10-26 08:18:57:

    1. closedate changed to: "2000-10-26T01:18:57"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [22b125e641] (rid 130797) by dgp on 2001-04-19 03:44:27:

    1. foundin changed to: "None"
    2. status changed to: "Open"
    3. subsystem changed to: "None"
  4. Ticket change [8f8eb04d1b] (rid 120290) by dgp on 2001-04-19 03:45:15:

    1. closedate changed to: "2001-04-18T20:45:15"
    2. closer changed to: "dgp"
    3. status changed to: "Closed"
    4. subsystem changed to: "07. Variables"