Tcl Source Code

Check-in [736d436f40]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:tip-421: array for: a) Fix bug starting search (name not set). b) Fix error message for array change on iteration.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-421
Files: files | file ages | folders
SHA3-256:736d436f406596749e402785f5ca97143abfd106efca005781df4fb2e0f23319
User & Date: bll 2018-03-06 17:19:40
Context
2018-03-06
18:21
array for: updated documentation: value variable is not optional, add specifics about when array for... check-in: 694b8c4633 user: bll tags: tip-421
17:19
tip-421: array for: a) Fix bug starting search (name not set). b) Fix error message for array ch... check-in: 736d436f40 user: bll tags: tip-421
13:46
merge 8.7 check-in: 1982d6e284 user: dgp tags: tip-421
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclVar.c.

3070
3071
3072
3073
3074
3075
3076


3077
3078
3079
3080
3081
3082
3083
....
3086
3087
3088
3089
3090
3091
3092

3093
3094
3095
3096
3097
3098
3099
....
3303
3304
3305
3306
3307
3308
3309



3310
3311
3312
3313
3314
3315
3316
3317
3318
    Var *varPtr,
    ArraySearch *searchPtr)
{
    Interp *iPtr = (Interp *) interp;
    Tcl_HashEntry   *hPtr;
    int             isNew;



    searchPtr->varPtr = varPtr;
    searchPtr->arrayNameObj = arrayNameObj;

    /* add the search to the search table */
    hPtr = Tcl_CreateHashEntry(&iPtr->varSearches, varPtr, &isNew);
    if (isNew) {
	searchPtr->id = 1;
................................................................................
    } else {
	searchPtr->id = ((ArraySearch *) Tcl_GetHashValue(hPtr))->id + 1;
	searchPtr->nextPtr = Tcl_GetHashValue(hPtr);
    }
    searchPtr->nextEntry = VarHashFirstEntry(varPtr->value.tablePtr,
	    &searchPtr->search);
    Tcl_SetHashValue(hPtr, searchPtr);

}

int
ArrayObjNext(
    Tcl_Interp *interp,
    Var *varPtr,                /* array */
    ArraySearch *searchPtr,
................................................................................
    valueObj = NULL;
    done = ArrayObjNext (interp, varPtr, searchPtr, &keyObj, &valueObj);

    result = TCL_OK;
    if (done != TCL_CONTINUE) {
	Tcl_ResetResult(interp);
        if (done == TCL_ERROR) {



          varPtr->flags |= TCL_LEAVE_ERR_MSG;
          Tcl_AddErrorInfo(interp, "array changed during iteration");
          result = done;
        }
	goto arrayfordone;
    }
    if (Tcl_ObjSetVar2(interp, keyVarObj, NULL, keyObj, TCL_LEAVE_ERR_MSG) == NULL) {
      result = TCL_ERROR;
      goto arrayfordone;







>
>







 







>







 







>
>
>
|
<







3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
....
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
....
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316

3317
3318
3319
3320
3321
3322
3323
    Var *varPtr,
    ArraySearch *searchPtr)
{
    Interp *iPtr = (Interp *) interp;
    Tcl_HashEntry   *hPtr;
    int             isNew;

    /* this code is duplicated from arraystartsearchcmd,
       excepting that arrayNameObj is set */
    searchPtr->varPtr = varPtr;
    searchPtr->arrayNameObj = arrayNameObj;

    /* add the search to the search table */
    hPtr = Tcl_CreateHashEntry(&iPtr->varSearches, varPtr, &isNew);
    if (isNew) {
	searchPtr->id = 1;
................................................................................
    } else {
	searchPtr->id = ((ArraySearch *) Tcl_GetHashValue(hPtr))->id + 1;
	searchPtr->nextPtr = Tcl_GetHashValue(hPtr);
    }
    searchPtr->nextEntry = VarHashFirstEntry(varPtr->value.tablePtr,
	    &searchPtr->search);
    Tcl_SetHashValue(hPtr, searchPtr);
    searchPtr->name = Tcl_ObjPrintf("s-%d-%s", searchPtr->id, TclGetString(arrayNameObj));
}

int
ArrayObjNext(
    Tcl_Interp *interp,
    Var *varPtr,                /* array */
    ArraySearch *searchPtr,
................................................................................
    valueObj = NULL;
    done = ArrayObjNext (interp, varPtr, searchPtr, &keyObj, &valueObj);

    result = TCL_OK;
    if (done != TCL_CONTINUE) {
	Tcl_ResetResult(interp);
        if (done == TCL_ERROR) {
	  Tcl_SetObjResult(interp, Tcl_NewStringObj(
	      "array changed during iteration", -1));
	  Tcl_SetErrorCode(interp, "TCL", "READ", "array", "for", NULL);
	  varPtr->flags |= TCL_LEAVE_ERR_MSG;

          result = done;
        }
	goto arrayfordone;
    }
    if (Tcl_ObjSetVar2(interp, keyVarObj, NULL, keyObj, TCL_LEAVE_ERR_MSG) == NULL) {
      result = TCL_ERROR;
      goto arrayfordone;