Artifact
df57daf4e1d7561f9b2b8b47a0010ee18af91151:
Attachment "arrayunset.patch" to
ticket [2939073fff]
added by
dkf
2010-02-02 07:09:38.
0000: 49 6e 64 65 78 3a 20 67 65 6e 65 72 69 63 2f 74 Index: generic/t
0010: 63 6c 56 61 72 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d clVar.c.========
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 ===========.RCS
0060: 66 69 6c 65 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 file: /cvsroot/t
0070: 63 6c 2f 74 63 6c 2f 67 65 6e 65 72 69 63 2f 74 cl/tcl/generic/t
0080: 63 6c 56 61 72 2e 63 2c 76 0a 72 65 74 72 69 65 clVar.c,v.retrie
0090: 76 69 6e 67 20 72 65 76 69 73 69 6f 6e 20 31 2e ving revision 1.
00a0: 31 38 36 0a 64 69 66 66 20 2d 75 20 2d 72 31 2e 186.diff -u -r1.
00b0: 31 38 36 20 74 63 6c 56 61 72 2e 63 0a 2d 2d 2d 186 tclVar.c.---
00c0: 20 67 65 6e 65 72 69 63 2f 74 63 6c 56 61 72 2e generic/tclVar.
00d0: 63 09 33 31 20 4a 61 6e 20 32 30 31 30 20 32 32 c.31 Jan 2010 22
00e0: 3a 33 33 3a 30 36 20 2d 30 30 30 30 09 31 2e 31 :33:06 -0000.1.1
00f0: 38 36 0a 2b 2b 2b 20 67 65 6e 65 72 69 63 2f 74 86.+++ generic/t
0100: 63 6c 56 61 72 2e 63 09 31 20 46 65 62 20 32 30 clVar.c.1 Feb 20
0110: 31 30 20 32 33 3a 35 30 3a 30 32 20 2d 30 30 30 10 23:50:02 -000
0120: 30 0a 40 40 20 2d 33 32 31 31 2c 31 31 20 2b 33 0.@@ -3211,11 +3
0130: 32 31 31 2c 37 20 40 40 0a 20 09 20 20 20 20 72 211,7 @@. . r
0140: 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b eturn TCL_ERROR;
0150: 0a 20 09 7d 0a 20 09 72 65 74 75 72 6e 20 54 63 . .}. .return Tc
0160: 6c 41 72 72 61 79 53 65 74 28 69 6e 74 65 72 70 lArraySet(interp
0170: 2c 20 6f 62 6a 76 5b 32 5d 2c 20 6f 62 6a 76 5b , objv[2], objv[
0180: 33 5d 29 3b 0a 2d 20 20 20 20 63 61 73 65 20 41 3]);.- case A
0190: 52 52 41 59 5f 55 4e 53 45 54 3a 20 7b 0a 2d 09 RRAY_UNSET: {.-.
01a0: 54 63 6c 5f 48 61 73 68 53 65 61 72 63 68 20 73 Tcl_HashSearch s
01b0: 65 61 72 63 68 3b 0a 2d 09 56 61 72 20 2a 76 61 earch;.-.Var *va
01c0: 72 50 74 72 32 3b 0a 2d 09 63 6f 6e 73 74 20 63 rPtr2;.-.const c
01d0: 68 61 72 20 2a 70 61 74 74 65 72 6e 20 3d 20 4e har *pattern = N
01e0: 55 4c 4c 3b 0a 2d 0a 2b 20 20 20 20 63 61 73 65 ULL;.-.+ case
01f0: 20 41 52 52 41 59 5f 55 4e 53 45 54 3a 0a 20 09 ARRAY_UNSET:. .
0200: 69 66 20 28 28 6f 62 6a 63 20 21 3d 20 33 29 20 if ((objc != 3)
0210: 26 26 20 28 6f 62 6a 63 20 21 3d 20 34 29 29 20 && (objc != 4))
0220: 7b 0a 20 09 20 20 20 20 54 63 6c 5f 57 72 6f 6e {. . Tcl_Wron
0230: 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c gNumArgs(interp,
0240: 20 32 2c 20 6f 62 6a 76 2c 20 22 61 72 72 61 79 2, objv, "array
0250: 4e 61 6d 65 20 3f 70 61 74 74 65 72 6e 3f 22 29 Name ?pattern?")
0260: 3b 0a 20 09 20 20 20 20 72 65 74 75 72 6e 20 54 ;. . return T
0270: 43 4c 5f 45 52 52 4f 52 3b 0a 40 40 20 2d 33 32 CL_ERROR;.@@ -32
0280: 32 38 2c 31 31 20 2b 33 32 32 34 2c 31 36 20 40 28,11 +3224,16 @
0290: 40 0a 20 09 20 20 20 20 20 2a 20 57 68 65 6e 20 @. . * When
02a0: 6e 6f 20 70 61 74 74 65 72 6e 20 69 73 20 67 69 no pattern is gi
02b0: 76 65 6e 2c 20 6a 75 73 74 20 75 6e 73 65 74 20 ven, just unset
02c0: 74 68 65 20 77 68 6f 6c 65 20 61 72 72 61 79 2e the whole array.
02d0: 0a 20 09 20 20 20 20 20 2a 2f 0a 20 0a 2d 09 20 . . */. .-.
02e0: 20 20 20 69 66 20 28 54 63 6c 4f 62 6a 55 6e 73 if (TclObjUns
02f0: 65 74 56 61 72 32 28 69 6e 74 65 72 70 2c 20 76 etVar2(interp, v
0300: 61 72 4e 61 6d 65 50 74 72 2c 20 4e 55 4c 4c 2c arNamePtr, NULL,
0310: 20 30 29 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0) != TCL_OK) {
0320: 0a 2d 09 09 72 65 74 75 72 6e 20 54 43 4c 5f 45 .-..return TCL_E
0330: 52 52 4f 52 3b 0a 2d 09 20 20 20 20 7d 0a 2b 09 RROR;.-. }.+.
0340: 20 20 20 20 72 65 74 75 72 6e 20 54 63 6c 4f 62 return TclOb
0350: 6a 55 6e 73 65 74 56 61 72 32 28 69 6e 74 65 72 jUnsetVar2(inter
0360: 70 2c 20 76 61 72 4e 61 6d 65 50 74 72 2c 20 4e p, varNamePtr, N
0370: 55 4c 4c 2c 20 30 29 3b 0a 20 09 7d 20 65 6c 73 ULL, 0);. .} els
0380: 65 20 7b 0a 2d 09 20 20 20 20 70 61 74 74 65 72 e {.-. patter
0390: 6e 20 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 n = TclGetString
03a0: 28 6f 62 6a 76 5b 33 5d 29 3b 0a 2b 09 20 20 20 (objv[3]);.+.
03b0: 20 54 63 6c 5f 48 61 73 68 53 65 61 72 63 68 20 Tcl_HashSearch
03c0: 73 65 61 72 63 68 3b 0a 2b 09 20 20 20 20 56 61 search;.+. Va
03d0: 72 20 2a 76 61 72 50 74 72 32 2c 20 2a 70 72 6f r *varPtr2, *pro
03e0: 74 65 63 74 65 64 56 61 72 50 74 72 3b 0a 2b 09 tectedVarPtr;.+.
03f0: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
0400: 70 61 74 74 65 72 6e 20 3d 20 54 63 6c 47 65 74 pattern = TclGet
0410: 53 74 72 69 6e 67 28 6f 62 6a 76 5b 33 5d 29 3b String(objv[3]);
0420: 0a 2b 0a 2b 09 20 20 20 20 2f 2a 0a 2b 09 20 20 .+.+. /*.+.
0430: 20 20 20 2a 20 57 69 74 68 20 61 20 74 72 69 76 * With a triv
0440: 69 61 6c 20 70 61 74 74 65 72 6e 2c 20 77 65 20 ial pattern, we
0450: 63 61 6e 20 6a 75 73 74 20 75 6e 73 65 74 2e 0a can just unset..
0460: 2b 09 20 20 20 20 20 2a 2f 0a 2b 0a 20 09 20 20 +. */.+. .
0470: 20 20 69 66 20 28 54 63 6c 4d 61 74 63 68 49 73 if (TclMatchIs
0480: 54 72 69 76 69 61 6c 28 70 61 74 74 65 72 6e 29 Trivial(pattern)
0490: 29 20 7b 0a 20 09 09 76 61 72 50 74 72 32 20 3d ) {. ..varPtr2 =
04a0: 20 56 61 72 48 61 73 68 46 69 6e 64 56 61 72 28 VarHashFindVar(
04b0: 76 61 72 50 74 72 2d 3e 76 61 6c 75 65 2e 74 61 varPtr->value.ta
04c0: 62 6c 65 50 74 72 2c 20 6f 62 6a 76 5b 33 5d 29 blePtr, objv[3])
04d0: 3b 0a 20 09 09 69 66 20 28 76 61 72 50 74 72 32 ;. ..if (varPtr2
04e0: 20 21 3d 20 4e 55 4c 4c 20 26 26 20 21 54 63 6c != NULL && !Tcl
04f0: 49 73 56 61 72 55 6e 64 65 66 69 6e 65 64 28 76 IsVarUndefined(v
0500: 61 72 50 74 72 32 29 29 20 7b 0a 40 40 20 2d 33 arPtr2)) {.@@ -3
0510: 32 34 30 2c 32 33 20 2b 33 32 34 31 2c 36 31 20 240,23 +3241,61
0520: 40 40 0a 20 09 09 7d 0a 20 09 09 72 65 74 75 72 @@. ..}. ..retur
0530: 6e 20 54 43 4c 5f 4f 4b 3b 0a 20 09 20 20 20 20 n TCL_OK;. .
0540: 7d 0a 2b 0a 2b 09 20 20 20 20 2f 2a 0a 2b 09 20 }.+.+. /*.+.
0550: 20 20 20 20 2a 20 4e 6f 6e 2d 74 72 69 76 69 61 * Non-trivia
0560: 6c 20 63 61 73 65 20 28 77 65 6c 6c 2c 20 64 65 l case (well, de
0570: 65 70 6c 79 20 74 72 69 63 6b 79 20 72 65 61 6c eply tricky real
0580: 6c 79 29 2e 20 57 65 20 70 65 65 6b 20 69 6e 73 ly). We peek ins
0590: 69 64 65 0a 2b 09 20 20 20 20 20 2a 20 74 68 65 ide.+. * the
05a0: 20 68 61 73 68 20 69 74 65 72 61 74 6f 72 20 69 hash iterator i
05b0: 6e 20 6f 72 64 65 72 20 74 6f 20 61 6c 6c 6f 77 n order to allow
05c0: 20 75 73 20 74 6f 20 67 75 61 72 61 6e 74 65 65 us to guarantee
05d0: 20 74 68 61 74 20 74 68 65 0a 2b 09 20 20 20 20 that the.+.
05e0: 20 2a 20 66 6f 6c 6c 6f 77 69 6e 67 20 65 6c 65 * following ele
05f0: 6d 65 6e 74 20 69 6e 20 74 68 65 20 61 72 72 61 ment in the arra
0600: 79 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 73 63 y will not be sc
0610: 72 75 62 62 65 64 20 75 6e 74 69 6c 20 77 65 0a rubbed until we.
0620: 2b 09 20 20 20 20 20 2a 20 68 61 76 65 20 64 65 +. * have de
0630: 61 6c 74 20 77 69 74 68 20 69 74 2e 20 54 68 69 alt with it. Thi
0640: 73 20 73 74 6f 70 73 20 74 68 65 20 6f 76 65 72 s stops the over
0650: 61 6c 6c 20 69 74 65 72 61 74 6f 72 20 66 72 6f all iterator fro
0660: 6d 20 65 6e 64 69 6e 67 0a 2b 09 20 20 20 20 20 m ending.+.
0670: 2a 20 75 70 20 70 6f 69 6e 74 69 6e 67 20 69 6e * up pointing in
0680: 74 6f 20 64 65 61 6c 6c 6f 63 61 74 65 64 20 6d to deallocated m
0690: 65 6d 6f 72 79 2e 20 5b 42 75 67 20 32 39 33 39 emory. [Bug 2939
06a0: 30 37 33 5d 0a 2b 09 20 20 20 20 20 2a 2f 0a 2b 073].+. */.+
06b0: 0a 2b 09 20 20 20 20 70 72 6f 74 65 63 74 65 64 .+. protected
06c0: 56 61 72 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 VarPtr = NULL;.
06d0: 09 20 20 20 20 66 6f 72 20 28 76 61 72 50 74 72 . for (varPtr
06e0: 32 3d 56 61 72 48 61 73 68 46 69 72 73 74 56 61 2=VarHashFirstVa
06f0: 72 28 76 61 72 50 74 72 2d 3e 76 61 6c 75 65 2e r(varPtr->value.
0700: 74 61 62 6c 65 50 74 72 2c 20 26 73 65 61 72 63 tablePtr, &searc
0710: 68 29 3b 0a 20 09 09 20 20 20 20 76 61 72 50 74 h);. .. varPt
0720: 72 32 21 3d 4e 55 4c 4c 20 3b 20 76 61 72 50 74 r2!=NULL ; varPt
0730: 72 32 3d 56 61 72 48 61 73 68 4e 65 78 74 56 61 r2=VarHashNextVa
0740: 72 28 26 73 65 61 72 63 68 29 29 20 7b 0a 2d 09 r(&search)) {.-.
0750: 09 54 63 6c 5f 4f 62 6a 20 2a 6e 61 6d 65 50 74 .Tcl_Obj *namePt
0760: 72 3b 0a 2b 09 09 2f 2a 0a 2b 09 09 20 2a 20 44 r;.+../*.+.. * D
0770: 72 6f 70 20 74 68 65 20 65 78 74 72 61 20 72 65 rop the extra re
0780: 66 20 69 6d 6d 65 64 69 61 74 65 6c 79 2e 20 57 f immediately. W
0790: 65 20 64 6f 6e 27 74 20 6e 65 65 64 20 74 6f 20 e don't need to
07a0: 66 72 65 65 20 69 74 20 61 74 0a 2b 09 09 20 2a free it at.+.. *
07b0: 20 74 68 69 73 20 70 6f 69 6e 74 20 74 68 6f 75 this point thou
07c0: 67 68 3b 20 77 65 27 6c 6c 20 62 65 20 75 6e 73 gh; we'll be uns
07d0: 65 74 74 69 6e 67 20 69 74 20 69 66 20 6e 65 63 etting it if nec
07e0: 65 73 73 61 72 79 20 73 6f 6f 6e 2e 0a 2b 09 09 essary soon..+..
07f0: 20 2a 2f 0a 20 0a 2d 09 09 69 66 20 28 54 63 6c */. .-..if (Tcl
0800: 49 73 56 61 72 55 6e 64 65 66 69 6e 65 64 28 76 IsVarUndefined(v
0810: 61 72 50 74 72 32 29 29 20 7b 0a 2d 09 09 20 20 arPtr2)) {.-..
0820: 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 2b 09 09 69 continue;.+..i
0830: 66 20 28 76 61 72 50 74 72 32 20 3d 3d 20 70 72 f (varPtr2 == pr
0840: 6f 74 65 63 74 65 64 56 61 72 50 74 72 29 20 7b otectedVarPtr) {
0850: 0a 2b 09 09 20 20 20 20 56 61 72 48 61 73 68 52 .+.. VarHashR
0860: 65 66 43 6f 75 6e 74 28 76 61 72 50 74 72 32 29 efCount(varPtr2)
0870: 2d 2d 3b 0a 2b 09 09 7d 0a 2b 0a 2b 09 09 2f 2a --;.+..}.+.+../*
0880: 0a 2b 09 09 20 2a 20 47 75 61 72 64 20 74 68 65 .+.. * Guard the
0890: 20 6e 65 78 74 20 69 74 65 6d 20 69 6e 20 74 68 next item in th
08a0: 65 20 73 65 61 72 63 68 20 63 68 61 69 6e 20 62 e search chain b
08b0: 79 20 69 6e 63 72 65 6d 65 6e 74 69 6e 67 20 69 y incrementing i
08c0: 74 73 0a 2b 09 09 20 2a 20 72 65 66 63 6f 75 6e ts.+.. * refcoun
08d0: 74 2e 20 54 68 69 73 20 67 75 61 72 61 6e 74 65 t. This guarante
08e0: 65 73 20 74 68 61 74 20 74 68 65 20 68 61 73 68 es that the hash
08f0: 20 74 61 62 6c 65 20 69 74 65 72 61 74 6f 72 0a table iterator.
0900: 2b 09 09 20 2a 20 77 6f 6e 27 74 20 62 65 20 64 +.. * won't be d
0910: 61 6e 67 6c 69 6e 67 20 6f 6e 20 74 68 65 20 6e angling on the n
0920: 65 78 74 20 74 69 6d 65 20 74 68 72 6f 75 67 68 ext time through
0930: 20 74 68 65 20 6c 6f 6f 70 2e 0a 2b 09 09 20 2a the loop..+.. *
0940: 2f 0a 2b 0a 2b 09 09 69 66 20 28 73 65 61 72 63 /.+.+..if (searc
0950: 68 2e 6e 65 78 74 45 6e 74 72 79 50 74 72 20 21 h.nextEntryPtr !
0960: 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 09 09 20 20 20 = NULL) {.+..
0970: 20 70 72 6f 74 65 63 74 65 64 56 61 72 50 74 72 protectedVarPtr
0980: 20 3d 20 56 61 72 48 61 73 68 47 65 74 56 61 6c = VarHashGetVal
0990: 75 65 28 73 65 61 72 63 68 2e 6e 65 78 74 45 6e ue(search.nextEn
09a0: 74 72 79 50 74 72 29 3b 0a 2b 09 09 20 20 20 20 tryPtr);.+..
09b0: 56 61 72 48 61 73 68 52 65 66 43 6f 75 6e 74 28 VarHashRefCount(
09c0: 70 72 6f 74 65 63 74 65 64 56 61 72 50 74 72 29 protectedVarPtr)
09d0: 2b 2b 3b 0a 2b 09 09 7d 20 65 6c 73 65 20 7b 0a ++;.+..} else {.
09e0: 2b 09 09 20 20 20 20 70 72 6f 74 65 63 74 65 64 +.. protected
09f0: 56 61 72 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 VarPtr = NULL;.
0a00: 09 09 7d 0a 2d 09 09 6e 61 6d 65 50 74 72 20 3d ..}.-..namePtr =
0a10: 20 56 61 72 48 61 73 68 47 65 74 4b 65 79 28 76 VarHashGetKey(v
0a20: 61 72 50 74 72 32 29 3b 0a 2d 09 09 69 66 20 28 arPtr2);.-..if (
0a30: 54 63 6c 5f 53 74 72 69 6e 67 4d 61 74 63 68 28 Tcl_StringMatch(
0a40: 54 63 6c 47 65 74 53 74 72 69 6e 67 28 6e 61 6d TclGetString(nam
0a50: 65 50 74 72 29 2c 20 70 61 74 74 65 72 6e 29 20 ePtr), pattern)
0a60: 26 26 0a 2d 09 09 09 54 63 6c 4f 62 6a 55 6e 73 &&.-...TclObjUns
0a70: 65 74 56 61 72 32 28 69 6e 74 65 72 70 2c 20 76 etVar2(interp, v
0a80: 61 72 4e 61 6d 65 50 74 72 2c 20 6e 61 6d 65 50 arNamePtr, nameP
0a90: 74 72 2c 0a 2d 09 09 09 09 30 29 20 21 3d 20 54 tr,.-....0) != T
0aa0: 43 4c 5f 4f 4b 29 20 7b 0a 2d 09 09 20 20 20 20 CL_OK) {.-..
0ab0: 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 return TCL_ERROR
0ac0: 3b 0a 2b 0a 2b 09 09 69 66 20 28 21 54 63 6c 49 ;.+.+..if (!TclI
0ad0: 73 56 61 72 55 6e 64 65 66 69 6e 65 64 28 76 61 sVarUndefined(va
0ae0: 72 50 74 72 32 29 29 20 7b 0a 2b 09 09 20 20 20 rPtr2)) {.+..
0af0: 20 54 63 6c 5f 4f 62 6a 20 2a 6e 61 6d 65 50 74 Tcl_Obj *namePt
0b00: 72 20 3d 20 56 61 72 48 61 73 68 47 65 74 4b 65 r = VarHashGetKe
0b10: 79 28 76 61 72 50 74 72 32 29 3b 0a 2b 0a 2b 09 y(varPtr2);.+.+.
0b20: 09 20 20 20 20 69 66 20 28 54 63 6c 5f 53 74 72 . if (Tcl_Str
0b30: 69 6e 67 4d 61 74 63 68 28 54 63 6c 47 65 74 53 ingMatch(TclGetS
0b40: 74 72 69 6e 67 28 6e 61 6d 65 50 74 72 29 2c 20 tring(namePtr),
0b50: 70 61 74 74 65 72 6e 29 0a 2b 09 09 09 20 20 20 pattern).+...
0b60: 20 26 26 20 54 63 6c 4f 62 6a 55 6e 73 65 74 56 && TclObjUnsetV
0b70: 61 72 32 28 69 6e 74 65 72 70 2c 20 76 61 72 4e ar2(interp, varN
0b80: 61 6d 65 50 74 72 2c 20 6e 61 6d 65 50 74 72 2c amePtr, namePtr,
0b90: 0a 2b 09 09 09 09 20 20 20 20 30 29 20 21 3d 20 .+.... 0) !=
0ba0: 54 43 4c 5f 4f 4b 29 20 7b 0a 2b 09 09 09 2f 2a TCL_OK) {.+.../*
0bb0: 0a 2b 09 09 09 20 2a 20 49 66 20 77 65 20 69 6e .+... * If we in
0bc0: 63 72 65 6d 65 6e 74 65 64 20 61 20 72 65 66 63 cremented a refc
0bd0: 6f 75 6e 74 2c 20 77 65 20 6d 75 73 74 20 64 65 ount, we must de
0be0: 63 72 65 6d 65 6e 74 20 69 74 0a 2b 09 09 09 20 crement it.+...
0bf0: 2a 20 68 65 72 65 20 61 73 20 77 65 20 77 69 6c * here as we wil
0c00: 6c 20 6e 6f 74 20 62 65 20 63 6f 6d 69 6e 67 20 l not be coming
0c10: 62 61 63 6b 20 70 72 6f 70 65 72 6c 79 20 64 75 back properly du
0c20: 65 20 74 6f 0a 2b 09 09 09 20 2a 20 74 68 65 20 e to.+... * the
0c30: 65 72 72 6f 72 2e 0a 2b 09 09 09 20 2a 2f 0a 2b error..+... */.+
0c40: 0a 2b 09 09 09 69 66 20 28 70 72 6f 74 65 63 74 .+...if (protect
0c50: 65 64 56 61 72 50 74 72 29 20 7b 0a 2b 09 09 09 edVarPtr) {.+...
0c60: 20 20 20 20 56 61 72 48 61 73 68 52 65 66 43 6f VarHashRefCo
0c70: 75 6e 74 28 70 72 6f 74 65 63 74 65 64 56 61 72 unt(protectedVar
0c80: 50 74 72 29 2d 2d 3b 0a 2b 09 09 09 7d 0a 2b 09 Ptr)--;.+...}.+.
0c90: 09 09 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 ..return TCL_ERR
0ca0: 4f 52 3b 0a 2b 09 09 20 20 20 20 7d 0a 20 09 09 OR;.+.. }. ..
0cb0: 7d 0a 20 09 20 20 20 20 7d 0a 2b 09 20 20 20 20 }. . }.+.
0cc0: 62 72 65 61 6b 3b 0a 20 09 7d 0a 2d 09 62 72 65 break;. .}.-.bre
0cd0: 61 6b 3b 0a 2d 20 20 20 20 7d 0a 20 0a 20 20 20 ak;.- }. .
0ce0: 20 20 63 61 73 65 20 41 52 52 41 59 5f 53 49 5a case ARRAY_SIZ
0cf0: 45 3a 20 7b 0a 20 09 54 63 6c 5f 48 61 73 68 53 E: {. .Tcl_HashS
0d00: 65 61 72 63 68 20 73 65 61 72 63 68 3b 0a 49 6e earch search;.In
0d10: 64 65 78 3a 20 74 65 73 74 73 2f 76 61 72 2e 74 dex: tests/var.t
0d20: 65 73 74 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d est.============
0d30: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0d40: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0d50: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0d60: 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 =======.RCS file
0d70: 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 : /cvsroot/tcl/t
0d80: 63 6c 2f 74 65 73 74 73 2f 76 61 72 2e 74 65 73 cl/tests/var.tes
0d90: 74 2c 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72 t,v.retrieving r
0da0: 65 76 69 73 69 6f 6e 20 31 2e 33 34 0a 64 69 66 evision 1.34.dif
0db0: 66 20 2d 75 20 2d 72 31 2e 33 34 20 76 61 72 2e f -u -r1.34 var.
0dc0: 74 65 73 74 0a 2d 2d 2d 20 74 65 73 74 73 2f 76 test.--- tests/v
0dd0: 61 72 2e 74 65 73 74 09 32 35 20 53 65 70 20 32 ar.test.25 Sep 2
0de0: 30 30 38 20 31 39 3a 35 31 3a 32 39 20 2d 30 30 008 19:51:29 -00
0df0: 30 30 09 31 2e 33 34 0a 2b 2b 2b 20 74 65 73 74 00.1.34.+++ test
0e00: 73 2f 76 61 72 2e 74 65 73 74 09 31 20 46 65 62 s/var.test.1 Feb
0e10: 20 32 30 31 30 20 32 33 3a 35 30 3a 30 33 20 2d 2010 23:50:03 -
0e20: 30 30 30 30 0a 40 40 20 2d 33 34 2c 37 20 2b 33 0000.@@ -34,7 +3
0e30: 34 2c 37 20 40 40 0a 20 63 61 74 63 68 20 7b 75 4,7 @@. catch {u
0e40: 6e 73 65 74 20 69 7d 0a 20 63 61 74 63 68 20 7b nset i}. catch {
0e50: 75 6e 73 65 74 20 61 7d 0a 20 63 61 74 63 68 20 unset a}. catch
0e60: 7b 75 6e 73 65 74 20 61 72 72 7d 0a 2d 0a 2b 0c {unset arr}.-.+.
0e70: 0a 20 74 65 73 74 20 76 61 72 2d 31 2e 31 20 7b . test var-1.1 {
0e80: 54 63 6c 4c 6f 6f 6b 75 70 56 61 72 2c 20 41 72 TclLookupVar, Ar
0e90: 72 61 79 20 68 61 6e 64 6c 69 6e 67 7d 20 7b 0a ray handling} {.
0ea0: 20 20 20 20 20 63 61 74 63 68 20 7b 75 6e 73 65 catch {unse
0eb0: 74 20 61 7d 0a 20 20 20 20 20 73 65 74 20 78 20 t a}. set x
0ec0: 22 69 6e 63 72 22 20 20 3b 23 20 66 6f 72 63 65 "incr" ;# force
0ed0: 20 6e 6f 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 no compilation
0ee0: 61 6e 64 20 72 75 6e 74 69 6d 65 20 63 61 6c 6c and runtime call
0ef0: 20 74 6f 20 54 63 6c 5f 49 6e 63 72 43 6d 64 20 to Tcl_IncrCmd
0f00: 0a 40 40 20 2d 37 32 35 2c 39 20 2b 37 32 35 2c .@@ -725,9 +725,
0f10: 39 20 40 40 0a 20 0a 20 0a 20 74 65 73 74 20 76 9 @@. . . test v
0f20: 61 72 2d 31 36 2e 31 20 7b 43 61 6c 6c 56 61 72 ar-16.1 {CallVar
0f30: 54 72 61 63 65 73 3a 20 73 61 76 65 2f 72 65 73 Traces: save/res
0f40: 74 6f 72 65 20 69 6e 74 65 72 70 20 65 72 72 6f tore interp erro
0f50: 72 20 73 74 61 74 65 7d 20 7b 0a 2d 20 20 20 20 r state} {.-
0f60: 74 72 61 63 65 20 61 64 64 20 76 61 72 69 61 62 trace add variab
0f70: 6c 65 20 3a 3a 65 72 72 6f 72 43 6f 64 65 20 77 le ::errorCode w
0f80: 72 69 74 65 20 7b 20 3b 23 7d 0a 2b 20 20 20 20 rite { ;#}.+
0f90: 74 72 61 63 65 20 61 64 64 20 76 61 72 69 61 62 trace add variab
0fa0: 6c 65 20 3a 3a 65 72 72 6f 72 43 6f 64 65 20 77 le ::errorCode w
0fb0: 72 69 74 65 20 22 20 3b 23 22 0a 20 20 20 20 20 rite " ;#".
0fc0: 63 61 74 63 68 20 7b 65 72 72 6f 72 20 66 6f 6f catch {error foo
0fd0: 20 62 61 72 20 62 61 7a 7d 0a 2d 20 20 20 20 74 bar baz}.- t
0fe0: 72 61 63 65 20 72 65 6d 6f 76 65 20 76 61 72 69 race remove vari
0ff0: 61 62 6c 65 20 3a 3a 65 72 72 6f 72 43 6f 64 65 able ::errorCode
1000: 20 77 72 69 74 65 20 7b 20 3b 23 7d 0a 2b 20 20 write { ;#}.+
1010: 20 20 74 72 61 63 65 20 72 65 6d 6f 76 65 20 76 trace remove v
1020: 61 72 69 61 62 6c 65 20 3a 3a 65 72 72 6f 72 43 ariable ::errorC
1030: 6f 64 65 20 77 72 69 74 65 20 22 20 3b 23 22 0a ode write " ;#".
1040: 20 20 20 20 20 73 65 74 20 3a 3a 65 72 72 6f 72 set ::error
1050: 49 6e 66 6f 0a 20 7d 20 62 61 72 0a 20 0a 40 40 Info. } bar. .@@
1060: 20 2d 37 33 36 2c 31 33 20 2b 37 33 36 2c 33 33 -736,13 +736,33
1070: 20 40 40 0a 20 7d 20 2d 62 6f 64 79 20 7b 0a 20 @@. } -body {.
1080: 20 20 20 20 6e 61 6d 65 73 70 61 63 65 20 65 76 namespace ev
1090: 61 6c 20 3a 3a 20 7b 0a 20 09 73 65 74 20 65 6c al :: {. .set el
10a0: 65 6d 65 6e 74 73 20 7b 31 20 32 20 33 20 34 7d ements {1 2 3 4}
10b0: 0a 2d 09 74 72 61 63 65 20 61 64 64 20 76 61 72 .-.trace add var
10c0: 69 61 62 6c 65 20 61 20 77 72 69 74 65 20 7b 73 iable a write {s
10d0: 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 24 65 6c tring length $el
10e0: 65 6d 65 6e 74 73 20 3b 23 7d 0a 2b 09 74 72 61 ements ;#}.+.tra
10f0: 63 65 20 61 64 64 20 76 61 72 69 61 62 6c 65 20 ce add variable
1100: 61 20 77 72 69 74 65 20 22 73 74 72 69 6e 67 20 a write "string
1110: 6c 65 6e 67 74 68 20 5c 24 65 6c 65 6d 65 6e 74 length \$element
1120: 73 20 3b 23 22 0a 20 09 61 72 72 61 79 20 73 65 s ;#". .array se
1130: 74 20 61 20 24 65 6c 65 6d 65 6e 74 73 0a 20 20 t a $elements.
1140: 20 20 20 7d 0a 20 7d 20 2d 63 6c 65 61 6e 75 70 }. } -cleanup
1150: 20 7b 0a 20 20 20 20 20 75 6e 73 65 74 20 2d 6e {. unset -n
1160: 6f 63 6f 6d 70 6c 61 69 6e 20 3a 3a 61 20 3a 3a ocomplain ::a ::
1170: 65 6c 65 6d 65 6e 74 73 0a 20 7d 20 2d 72 65 73 elements. } -res
1180: 75 6c 74 20 7b 7d 0a 20 0a 2b 74 65 73 74 20 76 ult {}. .+test v
1190: 61 72 2d 31 38 2e 31 20 7b 61 72 72 61 79 20 75 ar-18.1 {array u
11a0: 6e 73 65 74 20 61 6e 64 20 75 6e 73 65 74 20 74 nset and unset t
11b0: 72 61 63 65 73 3a 20 42 75 67 20 32 39 33 39 30 races: Bug 29390
11c0: 37 33 7d 20 2d 73 65 74 75 70 20 7b 0a 2b 20 20 73} -setup {.+
11d0: 20 20 73 65 74 20 61 6c 72 65 61 64 79 20 30 0a set already 0.
11e0: 2b 20 20 20 20 75 6e 73 65 74 20 78 0a 2b 7d 20 + unset x.+}
11f0: 2d 62 6f 64 79 20 7b 0a 2b 20 20 20 20 61 72 72 -body {.+ arr
1200: 61 79 20 73 65 74 20 78 20 7b 65 20 31 20 69 20 ay set x {e 1 i
1210: 31 7d 0a 2b 20 20 20 20 74 72 61 63 65 20 61 64 1}.+ trace ad
1220: 64 20 76 61 72 69 61 62 6c 65 20 78 20 75 6e 73 d variable x uns
1230: 65 74 20 7b 61 70 70 6c 79 20 7b 61 72 67 73 20 et {apply {args
1240: 7b 0a 2b 09 67 6c 6f 62 61 6c 20 61 6c 72 65 61 {.+.global alrea
1250: 64 79 20 78 0a 2b 09 69 66 20 7b 21 24 61 6c 72 dy x.+.if {!$alr
1260: 65 61 64 79 7d 20 7b 0a 2b 09 20 20 20 20 73 65 eady} {.+. se
1270: 74 20 61 6c 72 65 61 64 79 20 31 0a 2b 09 20 20 t already 1.+.
1280: 20 20 75 6e 73 65 74 20 78 28 69 29 0a 2b 09 7d unset x(i).+.}
1290: 0a 2b 20 20 20 20 7d 7d 7d 0a 2b 20 20 20 20 23 .+ }}}.+ #
12a0: 20 54 68 65 20 6e 65 78 74 20 63 6f 6d 6d 61 6e The next comman
12b0: 64 20 77 6f 75 6c 64 20 63 72 61 73 68 20 72 65 d would crash re
12c0: 6c 69 61 62 6c 79 20 77 69 74 68 20 6d 65 6d 6f liably with memo
12d0: 72 79 20 64 65 62 75 67 67 69 6e 67 20 70 72 69 ry debugging pri
12e0: 6f 72 20 74 6f 20 74 68 65 0a 2b 20 20 20 20 23 or to the.+ #
12f0: 20 62 75 67 20 66 69 78 2e 0a 2b 20 20 20 20 61 bug fix..+ a
1300: 72 72 61 79 20 75 6e 73 65 74 20 78 20 2a 0a 2b rray unset x *.+
1310: 20 20 20 20 61 72 72 61 79 20 73 69 7a 65 20 78 array size x
1320: 0a 2b 7d 20 2d 63 6c 65 61 6e 75 70 20 7b 0a 2b .+} -cleanup {.+
1330: 20 20 20 20 75 6e 73 65 74 20 78 20 61 6c 72 65 unset x alre
1340: 61 64 79 0a 2b 7d 20 2d 72 65 73 75 6c 74 20 30 ady.+} -result 0
1350: 0a 2b 0c 0a 20 63 61 74 63 68 20 7b 6e 61 6d 65 .+.. catch {name
1360: 73 70 61 63 65 20 64 65 6c 65 74 65 20 6e 73 7d space delete ns}
1370: 0a 20 63 61 74 63 68 20 7b 75 6e 73 65 74 20 61 . catch {unset a
1380: 72 72 7d 0a 20 63 61 74 63 68 20 7b 75 6e 73 65 rr}. catch {unse
1390: 74 20 76 7d 0a 40 40 20 2d 37 36 31 2c 33 20 2b t v}.@@ -761,3 +
13a0: 37 38 31 2c 37 20 40 40 0a 20 23 20 63 6c 65 61 781,7 @@. # clea
13b0: 6e 75 70 0a 20 3a 3a 74 63 6c 74 65 73 74 3a 3a nup. ::tcltest::
13c0: 63 6c 65 61 6e 75 70 54 65 73 74 73 0a 20 72 65 cleanupTests. re
13d0: 74 75 72 6e 0a 2b 0a 2b 23 20 4c 6f 63 61 6c 20 turn.+.+# Local
13e0: 56 61 72 69 61 62 6c 65 73 3a 0a 2b 23 20 6d 6f Variables:.+# mo
13f0: 64 65 3a 20 74 63 6c 0a 2b 23 20 45 6e 64 3a 0a de: tcl.+# End:.