Artifact
7d90f422eae565caff5af3ae3cc636608bc9d37f:
Attachment "transfer.patch" to
ticket [1252107fff]
added by
andreas_kupries
2005-08-05 01:30:19.
0000: 2d 2d 2d 20 74 63 6c 38 2e 35 2d 63 68 61 6e 67 --- tcl8.5-chang
0010: 65 73 2f 67 65 6e 65 72 69 63 2f 74 63 6c 54 65 es/generic/tclTe
0020: 73 74 2e 63 09 32 30 30 35 2d 30 37 2d 32 36 20 st.c.2005-07-26
0030: 31 32 3a 32 34 3a 33 39 2e 30 30 30 30 30 30 30 12:24:39.0000000
0040: 30 30 20 2d 30 37 30 30 0a 2b 2b 2b 20 74 63 6c 00 -0700.+++ tcl
0050: 38 2e 35 2d 74 72 61 6e 73 66 65 72 2f 67 65 6e 8.5-transfer/gen
0060: 65 72 69 63 2f 74 63 6c 54 65 73 74 2e 63 09 32 eric/tclTest.c.2
0070: 30 30 35 2d 30 38 2d 30 34 20 31 31 3a 31 33 3a 005-08-04 11:13:
0080: 30 30 2e 30 30 30 30 30 30 30 30 30 20 2d 30 37 00.000000000 -07
0090: 30 30 0a 40 40 20 2d 31 32 32 2c 36 20 2b 31 32 00.@@ -122,6 +12
00a0: 32 2c 32 33 20 40 40 0a 20 7d 20 54 65 73 74 45 2,23 @@. } TestE
00b0: 76 65 6e 74 3b 0a 20 0a 20 2f 2a 0a 2b 20 2a 20 vent;. . /*.+ *
00c0: 53 69 6d 70 6c 65 20 64 65 74 61 63 68 2f 61 74 Simple detach/at
00d0: 74 61 63 68 20 66 61 63 69 6c 69 74 79 20 66 6f tach facility fo
00e0: 72 20 74 65 73 74 63 68 61 6e 6e 65 6c 20 63 75 r testchannel cu
00f0: 74 7c 73 70 6c 69 63 65 2e 0a 2b 20 2a 20 45 6e t|splice..+ * En
0100: 61 62 6c 65 73 20 74 68 65 20 74 65 73 74 69 6e ables the testin
0110: 67 20 6f 66 20 63 68 61 6e 6e 65 6c 20 74 72 61 g of channel tra
0120: 6e 73 66 65 72 73 20 69 6e 20 63 6f 72 65 20 74 nsfers in core t
0130: 65 73 74 73 75 69 74 65 2e 0a 2b 20 2a 0a 2b 20 estsuite..+ *.+
0140: 2a 20 4e 4f 54 45 3a 20 4e 6f 20 73 61 66 65 67 * NOTE: No safeg
0150: 75 61 72 64 73 2c 20 69 2e 65 2e 20 6e 6f 20 6d uards, i.e. no m
0160: 75 74 65 78 65 73 20 66 6f 72 20 66 75 6c 6c 20 utexes for full
0170: 74 68 72 65 61 64 2d 73 61 66 65 74 79 2c 0a 2b thread-safety,.+
0180: 20 2a 20 6e 6f 20 63 68 65 63 6b 73 20 74 68 61 * no checks tha
0190: 74 20 74 68 65 20 63 68 61 6e 6e 65 6c 20 69 73 t the channel is
01a0: 20 74 72 75 6c 79 20 74 72 61 6e 73 66 65 72 61 truly transfera
01b0: 62 6c 65 2c 20 6e 6f 20 63 6c 65 61 72 61 6e 63 ble, no clearanc
01c0: 65 0a 2b 20 2a 20 6f 66 20 61 63 74 69 76 65 20 e.+ * of active
01d0: 65 76 65 6e 74 20 68 61 6e 64 6c 65 72 73 2e 20 event handlers.
01e0: 57 65 20 6d 61 79 20 68 61 76 65 20 74 6f 20 61 We may have to a
01f0: 64 64 20 73 6f 6d 65 20 6f 66 20 74 68 65 73 65 dd some of these
0200: 0a 2b 20 2a 20 69 6e 20 74 68 65 20 66 75 74 75 .+ * in the futu
0210: 72 65 20 66 6f 72 20 6d 6f 72 65 20 63 6f 6d 70 re for more comp
0220: 6c 65 78 20 74 65 73 74 2d 73 63 65 6e 61 72 69 lex test-scenari
0230: 6f 73 2e 0a 2b 20 2a 2f 0a 2b 0a 2b 74 79 70 65 os..+ */.+.+type
0240: 64 65 66 20 73 74 72 75 63 74 20 54 65 73 74 43 def struct TestC
0250: 68 61 6e 6e 65 6c 20 7b 0a 2b 20 20 20 20 54 63 hannel {.+ Tc
0260: 6c 5f 43 68 61 6e 6e 65 6c 20 20 20 20 20 20 20 l_Channel
0270: 20 20 63 68 61 6e 3b 20 20 20 20 2f 2a 20 44 65 chan; /* De
0280: 74 61 63 68 65 64 20 63 68 61 6e 6e 65 6c 20 2a tached channel *
0290: 2f 0a 2b 20 20 20 20 73 74 72 75 63 74 20 54 65 /.+ struct Te
02a0: 73 74 43 68 61 6e 6e 65 6c 2a 20 6e 65 78 74 50 stChannel* nextP
02b0: 74 72 3b 20 2f 2a 20 4e 65 78 74 20 69 6e 20 70 tr; /* Next in p
02c0: 6f 6f 6c 20 6f 66 20 64 65 74 61 63 68 65 64 20 ool of detached
02d0: 63 68 61 6e 6e 65 6c 73 20 2a 2f 0a 2b 7d 20 54 channels */.+} T
02e0: 65 73 74 43 68 61 6e 6e 65 6c 3b 0a 2b 0a 2b 73 estChannel;.+.+s
02f0: 74 61 74 69 63 20 54 65 73 74 43 68 61 6e 6e 65 tatic TestChanne
0300: 6c 2a 20 66 69 72 73 74 44 65 74 61 63 68 65 64 l* firstDetached
0310: 3b 0a 2b 0a 2b 2f 2a 0a 20 20 2a 20 46 6f 72 77 ;.+.+/*. * Forw
0320: 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 ard declarations
0330: 20 66 6f 72 20 70 72 6f 63 65 64 75 72 65 73 20 for procedures
0340: 64 65 66 69 6e 65 64 20 6c 61 74 65 72 20 69 6e defined later in
0350: 20 74 68 69 73 20 66 69 6c 65 3a 0a 20 20 2a 2f this file:. */
0360: 0a 20 0a 40 40 20 2d 35 33 35 32 2c 31 30 20 2b . .@@ -5352,10 +
0370: 35 33 36 39 2c 33 33 20 40 40 0a 20 20 20 20 20 5369,33 @@.
0380: 63 68 61 6e 50 74 72 20 3d 20 28 43 68 61 6e 6e chanPtr = (Chann
0390: 65 6c 20 2a 29 20 4e 55 4c 4c 3b 0a 20 0a 20 20 el *) NULL;. .
03a0: 20 20 20 69 66 20 28 61 72 67 63 20 3e 20 32 29 if (argc > 2)
03b0: 20 7b 0a 2d 20 20 20 20 20 20 20 20 63 68 61 6e {.- chan
03c0: 20 3d 20 54 63 6c 5f 47 65 74 43 68 61 6e 6e 65 = Tcl_GetChanne
03d0: 6c 28 69 6e 74 65 72 70 2c 20 61 72 67 76 5b 32 l(interp, argv[2
03e0: 5d 2c 20 26 6d 6f 64 65 29 3b 0a 2d 20 20 20 20 ], &mode);.-
03f0: 20 20 20 20 69 66 20 28 63 68 61 6e 20 3d 3d 20 if (chan ==
0400: 28 54 63 6c 5f 43 68 61 6e 6e 65 6c 29 20 4e 55 (Tcl_Channel) NU
0410: 4c 4c 29 20 7b 0a 2d 20 20 20 20 20 20 20 20 20 LL) {.-
0420: 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 return TCL_ER
0430: 52 4f 52 3b 0a 2d 20 20 20 20 20 20 20 20 7d 0a ROR;.- }.
0440: 2b 20 20 20 20 20 20 20 20 69 66 20 28 28 63 6d + if ((cm
0450: 64 4e 61 6d 65 5b 30 5d 20 3d 3d 20 27 73 27 29 dName[0] == 's')
0460: 20 26 26 20 28 73 74 72 6e 63 6d 70 28 63 6d 64 && (strncmp(cmd
0470: 4e 61 6d 65 2c 20 22 73 70 6c 69 63 65 22 2c 20 Name, "splice",
0480: 6c 65 6e 29 20 3d 3d 20 30 29 29 20 7b 0a 2b 09 len) == 0)) {.+.
0490: 20 20 20 20 2f 2a 20 46 6f 72 20 73 70 6c 69 63 /* For splic
04a0: 65 20 61 63 63 65 73 73 20 74 68 65 20 70 6f 6f e access the poo
04b0: 6c 20 6f 66 20 64 65 74 61 63 68 65 64 20 63 68 l of detached ch
04c0: 61 6e 6e 65 6c 73 2e 0a 2b 09 20 20 20 20 20 2a annels..+. *
04d0: 20 4c 6f 63 61 74 65 20 63 68 61 6e 6e 65 6c 2c Locate channel,
04e0: 20 72 65 6d 6f 76 65 20 66 72 6f 6d 20 74 68 65 remove from the
04f0: 20 6c 69 73 74 2e 0a 2b 09 20 20 20 20 20 2a 2f list..+. */
0500: 0a 2b 0a 2b 09 20 20 20 20 54 65 73 74 43 68 61 .+.+. TestCha
0510: 6e 6e 65 6c 2a 2a 20 6e 65 78 74 50 74 72 50 74 nnel** nextPtrPt
0520: 72 3b 0a 2b 09 20 20 20 20 54 65 73 74 43 68 61 r;.+. TestCha
0530: 6e 6e 65 6c 2a 20 20 63 75 72 50 74 72 3b 0a 2b nnel* curPtr;.+
0540: 0a 2b 09 20 20 20 20 63 68 61 6e 20 3d 20 28 54 .+. chan = (T
0550: 63 6c 5f 43 68 61 6e 6e 65 6c 29 20 4e 55 4c 4c cl_Channel) NULL
0560: 3b 0a 2b 09 20 20 20 20 66 6f 72 20 28 6e 65 78 ;.+. for (nex
0570: 74 50 74 72 50 74 72 20 3d 20 26 66 69 72 73 74 tPtrPtr = &first
0580: 44 65 74 61 63 68 65 64 2c 20 63 75 72 50 74 72 Detached, curPtr
0590: 20 3d 20 66 69 72 73 74 44 65 74 61 63 68 65 64 = firstDetached
05a0: 3b 0a 2b 09 09 20 63 75 72 50 74 72 20 21 3d 20 ;.+.. curPtr !=
05b0: 4e 55 4c 4c 3b 0a 2b 09 09 20 6e 65 78 74 50 74 NULL;.+.. nextPt
05c0: 72 50 74 72 20 3d 20 26 28 63 75 72 50 74 72 2d rPtr = &(curPtr-
05d0: 3e 6e 65 78 74 50 74 72 29 2c 20 63 75 72 50 74 >nextPtr), curPt
05e0: 72 20 3d 20 63 75 72 50 74 72 2d 3e 6e 65 78 74 r = curPtr->next
05f0: 50 74 72 29 20 7b 0a 2b 0a 2b 09 20 20 20 20 20 Ptr) {.+.+.
0600: 20 20 20 69 66 20 28 73 74 72 63 6d 70 20 28 61 if (strcmp (a
0610: 72 67 76 5b 32 5d 2c 20 54 63 6c 5f 47 65 74 43 rgv[2], Tcl_GetC
0620: 68 61 6e 6e 65 6c 4e 61 6d 65 20 28 63 75 72 50 hannelName (curP
0630: 74 72 2d 3e 63 68 61 6e 29 29 20 3d 3d 20 30 29 tr->chan)) == 0)
0640: 20 7b 0a 2b 09 09 20 20 20 20 2a 6e 65 78 74 50 {.+.. *nextP
0650: 74 72 50 74 72 20 20 20 20 3d 20 63 75 72 50 74 trPtr = curPt
0660: 72 2d 3e 6e 65 78 74 50 74 72 3b 0a 2b 09 09 20 r->nextPtr;.+..
0670: 20 20 20 63 75 72 50 74 72 2d 3e 6e 65 78 74 50 curPtr->nextP
0680: 74 72 20 3d 20 4e 55 4c 4c 3b 0a 2b 09 09 20 20 tr = NULL;.+..
0690: 20 20 63 68 61 6e 20 3d 20 63 75 72 50 74 72 2d chan = curPtr-
06a0: 3e 63 68 61 6e 3b 0a 2b 09 09 20 20 20 20 63 6b >chan;.+.. ck
06b0: 66 72 65 65 20 28 28 63 68 61 72 2a 29 20 63 75 free ((char*) cu
06c0: 72 50 74 72 29 3b 0a 2b 09 09 20 20 20 20 62 72 rPtr);.+.. br
06d0: 65 61 6b 3b 0a 2b 09 09 7d 0a 2b 09 20 20 20 20 eak;.+..}.+.
06e0: 7d 0a 2b 09 7d 20 65 6c 73 65 20 7b 0a 2b 09 20 }.+.} else {.+.
06f0: 20 20 20 63 68 61 6e 20 3d 20 54 63 6c 5f 47 65 chan = Tcl_Ge
0700: 74 43 68 61 6e 6e 65 6c 28 69 6e 74 65 72 70 2c tChannel(interp,
0710: 20 61 72 67 76 5b 32 5d 2c 20 26 6d 6f 64 65 29 argv[2], &mode)
0720: 3b 0a 2b 09 7d 0a 2b 09 69 66 20 28 63 68 61 6e ;.+.}.+.if (chan
0730: 20 3d 3d 20 28 54 63 6c 5f 43 68 61 6e 6e 65 6c == (Tcl_Channel
0740: 29 20 4e 55 4c 4c 29 20 7b 0a 2b 09 20 20 20 20 ) NULL) {.+.
0750: 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 return TCL_ERROR
0760: 3b 0a 2b 09 7d 0a 20 20 20 20 20 20 20 20 20 63 ;.+.}. c
0770: 68 61 6e 50 74 72 09 09 3d 20 28 43 68 61 6e 6e hanPtr..= (Chann
0780: 65 6c 20 2a 29 20 63 68 61 6e 3b 0a 20 09 73 74 el *) chan;. .st
0790: 61 74 65 50 74 72 09 3d 20 63 68 61 6e 50 74 72 atePtr.= chanPtr
07a0: 2d 3e 73 74 61 74 65 3b 0a 20 20 20 20 20 20 20 ->state;.
07b0: 20 20 63 68 61 6e 50 74 72 09 09 3d 20 73 74 61 chanPtr..= sta
07c0: 74 65 50 74 72 2d 3e 74 6f 70 43 68 61 6e 50 74 tePtr->topChanPt
07d0: 72 3b 0a 40 40 20 2d 35 33 36 36 2c 31 33 20 2b r;.@@ -5366,13 +
07e0: 35 34 30 36 2c 33 35 20 40 40 0a 20 09 63 68 61 5406,35 @@. .cha
07f0: 6e 09 09 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 20 n..= NULL;.
0800: 7d 0a 20 0a 2b 20 20 20 20 2f 2a 0a 2b 20 20 20 }. .+ /*.+
0810: 20 20 2a 20 22 63 75 74 22 20 69 73 20 61 63 74 * "cut" is act
0820: 75 61 6c 6c 79 20 6d 6f 72 65 20 61 20 73 69 6d ually more a sim
0830: 70 6c 69 66 69 65 64 20 64 65 74 61 63 68 20 66 plified detach f
0840: 61 63 69 6c 69 74 79 20 61 73 20 70 72 6f 76 69 acility as provi
0850: 64 65 64 0a 2b 20 20 20 20 20 2a 20 62 79 20 74 ded.+ * by t
0860: 68 65 20 54 68 72 65 61 64 20 70 61 63 6b 61 67 he Thread packag
0870: 65 2e 20 57 69 74 68 6f 75 74 20 74 68 65 20 73 e. Without the s
0880: 61 66 65 67 75 61 72 64 73 20 6f 66 20 61 20 72 afeguards of a r
0890: 65 67 75 6c 61 72 0a 2b 20 20 20 20 20 2a 20 63 egular.+ * c
08a0: 6f 6d 6d 61 6e 64 20 28 6e 6f 20 63 68 65 63 6b ommand (no check
08b0: 69 6e 67 20 74 68 61 74 20 74 68 65 20 63 6f 6d ing that the com
08c0: 6d 61 6e 64 20 69 73 20 74 72 75 6c 79 20 63 75 mand is truly cu
08d0: 74 27 61 62 6c 65 2c 20 6e 6f 0a 2b 20 20 20 20 t'able, no.+
08e0: 20 2a 20 6d 75 74 65 78 65 73 20 66 6f 72 20 74 * mutexes for t
08f0: 68 72 65 61 64 2d 73 61 66 65 74 79 29 2e 20 49 hread-safety). I
0900: 74 73 20 63 6f 6d 70 6c 65 6d 65 6e 74 61 72 79 ts complementary
0910: 20 63 6f 6d 6d 61 6e 64 20 69 73 0a 2b 20 20 20 command is.+
0920: 20 20 2a 20 22 73 70 6c 69 63 65 22 2c 20 73 65 * "splice", se
0930: 65 20 62 65 6c 6f 77 2e 0a 2b 20 20 20 20 20 2a e below..+ *
0940: 2f 0a 2b 0a 20 20 20 20 20 69 66 20 28 28 63 6d /.+. if ((cm
0950: 64 4e 61 6d 65 5b 30 5d 20 3d 3d 20 27 63 27 29 dName[0] == 'c')
0960: 20 26 26 20 28 73 74 72 6e 63 6d 70 28 63 6d 64 && (strncmp(cmd
0970: 4e 61 6d 65 2c 20 22 63 75 74 22 2c 20 6c 65 6e Name, "cut", len
0980: 29 20 3d 3d 20 30 29 29 20 7b 0a 2b 20 20 20 20 ) == 0)) {.+
0990: 20 20 20 20 54 65 73 74 43 68 61 6e 6e 65 6c 2a TestChannel*
09a0: 20 64 65 74 3b 0a 2b 0a 20 20 20 20 20 20 20 20 det;.+.
09b0: 20 69 66 20 28 61 72 67 63 20 21 3d 20 33 29 20 if (argc != 3)
09c0: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 54 {. T
09d0: 63 6c 5f 41 70 70 65 6e 64 52 65 73 75 6c 74 28 cl_AppendResult(
09e0: 69 6e 74 65 72 70 2c 20 22 77 72 6f 6e 67 20 23 interp, "wrong #
09f0: 20 61 72 67 73 3a 20 73 68 6f 75 6c 64 20 62 65 args: should be
0a00: 20 5c 22 22 2c 20 61 72 67 76 5b 30 5d 2c 0a 20 \"", argv[0],.
0a10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a20: 20 20 20 20 22 20 63 75 74 20 63 68 61 6e 6e 65 " cut channe
0a30: 6c 4e 61 6d 65 5c 22 22 2c 20 28 63 68 61 72 20 lName\"", (char
0a40: 2a 29 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 20 *) NULL);.
0a50: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 54 43 return TC
0a60: 4c 5f 45 52 52 4f 52 3b 0a 20 20 20 20 20 20 20 L_ERROR;.
0a70: 20 20 7d 0a 2b 0a 2b 09 54 63 6c 5f 52 65 67 69 }.+.+.Tcl_Regi
0a80: 73 74 65 72 43 68 61 6e 6e 65 6c 28 28 54 63 6c sterChannel((Tcl
0a90: 5f 49 6e 74 65 72 70 20 2a 29 20 4e 55 4c 4c 2c _Interp *) NULL,
0aa0: 20 63 68 61 6e 29 3b 20 2f 2a 20 70 72 65 76 65 chan); /* preve
0ab0: 6e 74 20 63 6c 6f 73 69 6e 67 20 2a 2f 0a 2b 09 nt closing */.+.
0ac0: 54 63 6c 5f 55 6e 72 65 67 69 73 74 65 72 43 68 Tcl_UnregisterCh
0ad0: 61 6e 6e 65 6c 28 69 6e 74 65 72 70 2c 20 63 68 annel(interp, ch
0ae0: 61 6e 29 3b 0a 2b 0a 20 20 20 20 20 20 20 20 20 an);.+.
0af0: 54 63 6c 5f 43 75 74 43 68 61 6e 6e 65 6c 28 63 Tcl_CutChannel(c
0b00: 68 61 6e 29 3b 0a 2b 0a 2b 09 2f 2a 20 52 65 6d han);.+.+./* Rem
0b10: 65 6d 62 65 72 20 74 68 65 20 63 68 61 6e 6e 65 ember the channe
0b20: 6c 20 69 6e 20 74 68 65 20 70 6f 6f 6c 20 6f 66 l in the pool of
0b30: 20 64 65 74 61 63 68 65 64 20 63 68 61 6e 6e 65 detached channe
0b40: 6c 73 20 2a 2f 0a 2b 0a 2b 09 64 65 74 20 3d 20 ls */.+.+.det =
0b50: 28 54 65 73 74 43 68 61 6e 6e 65 6c 2a 29 20 63 (TestChannel*) c
0b60: 6b 61 6c 6c 6f 63 20 28 73 69 7a 65 6f 66 28 54 kalloc (sizeof(T
0b70: 65 73 74 43 68 61 6e 6e 65 6c 29 29 3b 0a 2b 09 estChannel));.+.
0b80: 64 65 74 2d 3e 63 68 61 6e 20 20 20 20 20 3d 20 det->chan =
0b90: 63 68 61 6e 3b 0a 2b 09 64 65 74 2d 3e 6e 65 78 chan;.+.det->nex
0ba0: 74 50 74 72 20 20 3d 20 66 69 72 73 74 44 65 74 tPtr = firstDet
0bb0: 61 63 68 65 64 3b 0a 2b 09 66 69 72 73 74 44 65 ached;.+.firstDe
0bc0: 74 61 63 68 65 64 20 3d 20 64 65 74 3b 0a 2b 0a tached = det;.+.
0bd0: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
0be0: 54 43 4c 5f 4f 4b 3b 0a 20 20 20 20 20 7d 0a 20 TCL_OK;. }.
0bf0: 0a 40 40 20 2d 35 36 32 36 2c 36 20 2b 35 36 38 .@@ -5626,6 +568
0c00: 38 2c 31 34 20 40 40 0a 20 20 20 20 20 20 20 20 8,14 @@.
0c10: 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a return TCL_OK;.
0c20: 20 20 20 20 20 7d 0a 20 0a 2b 20 20 20 20 2f 2a }. .+ /*
0c30: 0a 2b 20 20 20 20 20 2a 20 22 73 70 6c 69 63 65 .+ * "splice
0c40: 22 20 69 73 20 61 63 74 75 61 6c 6c 79 20 6d 6f " is actually mo
0c50: 72 65 20 61 20 73 69 6d 70 6c 69 66 69 65 64 20 re a simplified
0c60: 61 74 74 61 63 68 20 66 61 63 69 6c 69 74 79 20 attach facility
0c70: 61 73 0a 2b 20 20 20 20 20 2a 20 70 72 6f 76 69 as.+ * provi
0c80: 64 65 64 20 62 79 20 74 68 65 20 54 68 72 65 61 ded by the Threa
0c90: 64 20 70 61 63 6b 61 67 65 2e 20 57 69 74 68 6f d package. Witho
0ca0: 75 74 20 74 68 65 20 73 61 66 65 67 75 61 72 64 ut the safeguard
0cb0: 73 20 6f 66 20 61 0a 2b 20 20 20 20 20 2a 20 72 s of a.+ * r
0cc0: 65 67 75 6c 61 72 20 63 6f 6d 6d 61 6e 64 20 28 egular command (
0cd0: 6e 6f 20 63 68 65 63 6b 69 6e 67 20 74 68 61 74 no checking that
0ce0: 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 69 73 20 the command is
0cf0: 74 72 75 6c 79 0a 2b 20 20 20 20 20 2a 20 63 75 truly.+ * cu
0d00: 74 27 61 62 6c 65 2c 20 6e 6f 20 6d 75 74 65 78 t'able, no mutex
0d10: 65 73 20 66 6f 72 20 74 68 72 65 61 64 2d 73 61 es for thread-sa
0d20: 66 65 74 79 29 2e 20 49 74 73 20 63 6f 6d 70 6c fety). Its compl
0d30: 65 6d 65 6e 74 61 72 79 0a 2b 20 20 20 20 20 2a ementary.+ *
0d40: 20 63 6f 6d 6d 61 6e 64 20 69 73 20 22 63 75 74 command is "cut
0d50: 22 2c 20 73 65 65 20 61 62 6f 76 65 2e 0a 2b 20 ", see above..+
0d60: 20 20 20 20 2a 2f 0a 2b 0a 20 20 20 20 20 69 66 */.+. if
0d70: 20 28 28 63 6d 64 4e 61 6d 65 5b 30 5d 20 3d 3d ((cmdName[0] ==
0d80: 20 27 73 27 29 20 26 26 20 28 73 74 72 6e 63 6d 's') && (strncm
0d90: 70 28 63 6d 64 4e 61 6d 65 2c 20 22 73 70 6c 69 p(cmdName, "spli
0da0: 63 65 22 2c 20 6c 65 6e 29 20 3d 3d 20 30 29 29 ce", len) == 0))
0db0: 20 7b 0a 20 20 20 20 20 20 20 20 20 69 66 20 28 {. if (
0dc0: 61 72 67 63 20 21 3d 20 33 29 20 7b 0a 20 20 20 argc != 3) {.
0dd0: 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f 41 70 Tcl_Ap
0de0: 70 65 6e 64 52 65 73 75 6c 74 28 69 6e 74 65 72 pendResult(inter
0df0: 70 2c 20 22 63 68 61 6e 6e 65 6c 20 6e 61 6d 65 p, "channel name
0e00: 20 72 65 71 75 69 72 65 64 22 2c 20 28 63 68 61 required", (cha
0e10: 72 20 2a 29 20 4e 55 4c 4c 29 3b 0a 40 40 20 2d r *) NULL);.@@ -
0e20: 35 36 33 33 2c 36 20 2b 35 37 30 33 2c 31 30 20 5633,6 +5703,10
0e30: 40 40 0a 20 20 20 20 20 20 20 20 20 7d 0a 20 0a @@. }. .
0e40: 20 20 20 20 20 20 20 20 20 54 63 6c 5f 53 70 6c Tcl_Spl
0e50: 69 63 65 43 68 61 6e 6e 65 6c 28 63 68 61 6e 29 iceChannel(chan)
0e60: 3b 0a 2b 0a 2b 09 54 63 6c 5f 52 65 67 69 73 74 ;.+.+.Tcl_Regist
0e70: 65 72 43 68 61 6e 6e 65 6c 28 69 6e 74 65 72 70 erChannel(interp
0e80: 2c 20 63 68 61 6e 29 3b 0a 2b 09 54 63 6c 5f 55 , chan);.+.Tcl_U
0e90: 6e 72 65 67 69 73 74 65 72 43 68 61 6e 6e 65 6c nregisterChannel
0ea0: 28 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 29 4e ((Tcl_Interp *)N
0eb0: 55 4c 4c 2c 20 63 68 61 6e 29 3b 0a 2b 0a 20 20 ULL, chan);.+.
0ec0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 54 43 return TC
0ed0: 4c 5f 4f 4b 3b 0a 20 20 20 20 20 7d 0a 20 0a 2d L_OK;. }. .-
0ee0: 2d 2d 20 74 63 6c 38 2e 35 2d 63 68 61 6e 67 65 -- tcl8.5-change
0ef0: 73 2f 67 65 6e 65 72 69 63 2f 74 63 6c 54 68 72 s/generic/tclThr
0f00: 65 61 64 54 65 73 74 2e 63 09 32 30 30 35 2d 30 eadTest.c.2005-0
0f10: 37 2d 32 36 20 31 32 3a 32 34 3a 33 39 2e 30 30 7-26 12:24:39.00
0f20: 30 30 30 30 30 30 30 20 2d 30 37 30 30 0a 2b 2b 0000000 -0700.++
0f30: 2b 20 74 63 6c 38 2e 35 2d 74 72 61 6e 73 66 65 + tcl8.5-transfe
0f40: 72 2f 67 65 6e 65 72 69 63 2f 74 63 6c 54 68 72 r/generic/tclThr
0f50: 65 61 64 54 65 73 74 2e 63 09 32 30 30 35 2d 30 eadTest.c.2005-0
0f60: 38 2d 30 34 20 31 31 3a 31 34 3a 31 31 2e 30 30 8-04 11:14:11.00
0f70: 30 30 30 30 30 30 30 20 2d 30 37 30 30 0a 40 40 0000000 -0700.@@
0f80: 20 2d 34 37 39 2c 36 20 2b 34 37 39 2c 31 33 20 -479,6 +479,13
0f90: 40 40 0a 20 20 20 20 20 72 65 73 75 6c 74 20 3d @@. result =
0fa0: 20 54 63 6c 5f 49 6e 69 74 28 74 73 64 50 74 72 Tcl_Init(tsdPtr
0fb0: 2d 3e 69 6e 74 65 72 70 29 3b 0a 20 20 20 20 20 ->interp);.
0fc0: 72 65 73 75 6c 74 20 3d 20 54 63 6c 54 68 72 65 result = TclThre
0fd0: 61 64 5f 49 6e 69 74 28 74 73 64 50 74 72 2d 3e ad_Init(tsdPtr->
0fe0: 69 6e 74 65 72 70 29 3b 0a 20 0a 2b 20 20 20 20 interp);. .+
0ff0: 2f 2a 20 54 68 69 73 20 69 73 20 70 61 72 74 20 /* This is part
1000: 6f 66 20 74 68 65 20 74 65 73 74 20 66 61 63 69 of the test faci
1010: 6c 69 74 79 2e 0a 2b 20 20 20 20 20 2a 20 49 6e lity..+ * In
1020: 69 74 69 61 6c 69 7a 65 20 5f 41 4c 4c 5f 20 74 itialize _ALL_ t
1030: 65 73 74 20 63 6f 6d 6d 61 6e 64 73 20 66 6f 72 est commands for
1040: 0a 2b 20 20 20 20 20 2a 20 75 73 65 20 62 79 20 .+ * use by
1050: 74 68 65 20 6e 65 77 20 74 68 72 65 61 64 2e 0a the new thread..
1060: 2b 20 20 20 20 20 2a 2f 0a 2b 0a 2b 20 20 20 20 + */.+.+
1070: 72 65 73 75 6c 74 20 3d 20 54 63 6c 74 65 73 74 result = Tcltest
1080: 5f 49 6e 69 74 28 74 73 64 50 74 72 2d 3e 69 6e _Init(tsdPtr->in
1090: 74 65 72 70 29 3b 0a 2b 0a 20 20 20 20 20 2f 2a terp);.+. /*
10a0: 0a 20 20 20 20 20 20 2a 20 55 70 64 61 74 65 20 . * Update
10b0: 74 68 65 20 6c 69 73 74 20 6f 66 20 74 68 72 65 the list of thre
10c0: 61 64 73 2e 0a 20 20 20 20 20 20 2a 2f 0a 2d 2d ads.. */.--
10d0: 2d 20 74 63 6c 38 2e 35 2d 63 68 61 6e 67 65 73 - tcl8.5-changes
10e0: 2f 74 65 73 74 73 2f 69 6f 2e 74 65 73 74 09 32 /tests/io.test.2
10f0: 30 30 35 2d 30 37 2d 32 36 20 31 32 3a 32 34 3a 005-07-26 12:24:
1100: 34 37 2e 30 30 30 30 30 30 30 30 30 20 2d 30 37 47.000000000 -07
1110: 30 30 0a 2b 2b 2b 20 74 63 6c 38 2e 35 2d 74 72 00.+++ tcl8.5-tr
1120: 61 6e 73 66 65 72 2f 74 65 73 74 73 2f 69 6f 2e ansfer/tests/io.
1130: 74 65 73 74 09 32 30 30 35 2d 30 38 2d 30 34 20 test.2005-08-04
1140: 31 31 3a 31 37 3a 33 30 2e 30 30 30 30 30 30 30 11:17:30.0000000
1150: 30 30 20 2d 30 37 30 30 0a 40 40 20 2d 37 31 31 00 -0700.@@ -711
1160: 31 2c 36 20 2b 37 31 31 31 2c 37 35 20 40 40 0a 1,6 +7111,75 @@.
1170: 20 20 20 20 20 72 65 6d 6f 76 65 46 69 6c 65 20 removeFile
1180: 65 6f 66 63 68 61 72 0a 20 7d 20 2d 72 65 73 75 eofchar. } -resu
1190: 6c 74 20 7b 37 37 20 3d 20 32 33 34 33 31 7d 0a lt {77 = 23431}.
11a0: 20 0a 2b 0a 2b 23 20 54 65 73 74 20 74 68 65 20 .+.+# Test the
11b0: 63 75 74 74 69 6e 67 20 61 6e 64 20 73 70 6c 69 cutting and spli
11c0: 63 69 6e 67 20 6f 66 20 63 68 61 6e 6e 65 6c 73 cing of channels
11d0: 2c 20 74 68 69 73 20 69 73 20 69 6e 63 69 64 65 , this is incide
11e0: 6e 74 69 61 6c 6c 79 20 74 68 65 0a 2b 23 20 61 ntially the.+# a
11f0: 74 74 61 63 68 2f 64 65 74 61 63 68 20 66 61 63 ttach/detach fac
1200: 69 6c 69 74 79 20 6f 66 20 70 61 63 6b 61 67 65 ility of package
1210: 20 54 68 72 65 61 64 2c 20 62 75 74 20 5f 5f 77 Thread, but __w
1220: 69 74 68 6f 75 74 20 61 6e 79 0a 2b 23 20 73 61 ithout any.+# sa
1230: 66 65 67 75 61 72 64 73 5f 5f 2e 20 49 74 20 63 feguards__. It c
1240: 61 6e 20 61 6c 73 6f 20 62 65 20 75 73 65 64 20 an also be used
1250: 74 6f 20 65 6d 75 6c 61 74 65 20 74 72 61 6e 73 to emulate trans
1260: 66 65 72 20 6f 66 20 63 68 61 6e 6e 65 6c 73 0a fer of channels.
1270: 2b 23 20 62 65 74 77 65 65 6e 20 74 68 72 65 61 +# between threa
1280: 64 73 2c 20 61 6e 64 20 69 73 20 75 73 65 64 20 ds, and is used
1290: 66 6f 72 20 74 68 61 74 20 68 65 72 65 2e 0a 2b for that here..+
12a0: 0a 2b 74 65 73 74 20 69 6f 2d 37 30 2e 30 20 7b .+test io-70.0 {
12b0: 43 75 74 74 69 6e 67 20 26 20 53 70 6c 69 63 69 Cutting & Splici
12c0: 6e 67 20 63 68 61 6e 6e 65 6c 73 7d 20 7b 74 65 ng channels} {te
12d0: 73 74 63 68 61 6e 6e 65 6c 7d 20 7b 0a 2b 20 20 stchannel} {.+
12e0: 20 20 73 65 74 20 66 20 5b 6d 61 6b 65 46 69 6c set f [makeFil
12f0: 65 20 7b 2e 2e 2e 20 64 75 6d 6d 79 20 2e 2e 2e e {... dummy ...
1300: 7d 20 63 75 74 73 70 6c 69 63 65 5d 0a 2b 20 20 } cutsplice].+
1310: 20 20 73 65 74 20 63 20 5b 6f 70 65 6e 20 24 66 set c [open $f
1320: 20 72 5d 0a 2b 0a 2b 20 20 20 20 73 65 74 20 20 r].+.+ set
1330: 20 20 20 72 65 73 20 7b 7d 0a 2b 20 20 20 20 6c res {}.+ l
1340: 61 70 70 65 6e 64 20 72 65 73 20 5b 63 61 74 63 append res [catc
1350: 68 20 7b 73 65 65 6b 20 24 63 20 30 20 73 74 61 h {seek $c 0 sta
1360: 72 74 7d 5d 0a 2b 20 20 20 20 74 65 73 74 63 68 rt}].+ testch
1370: 61 6e 6e 65 6c 20 63 75 74 20 24 63 0a 2b 0a 2b annel cut $c.+.+
1380: 20 20 20 20 6c 61 70 70 65 6e 64 20 72 65 73 20 lappend res
1390: 5b 63 61 74 63 68 20 7b 73 65 65 6b 20 24 63 20 [catch {seek $c
13a0: 30 20 73 74 61 72 74 7d 5d 0a 2b 20 20 20 20 74 0 start}].+ t
13b0: 65 73 74 63 68 61 6e 6e 65 6c 20 73 70 6c 69 63 estchannel splic
13c0: 65 20 24 63 0a 2b 0a 2b 20 20 20 20 6c 61 70 70 e $c.+.+ lapp
13d0: 65 6e 64 20 72 65 73 20 5b 63 61 74 63 68 20 7b end res [catch {
13e0: 73 65 65 6b 20 24 63 20 30 20 73 74 61 72 74 7d seek $c 0 start}
13f0: 5d 0a 2b 20 20 20 20 63 6c 6f 73 65 20 24 63 0a ].+ close $c.
1400: 2b 0a 2b 20 20 20 20 72 65 6d 6f 76 65 46 69 6c +.+ removeFil
1410: 65 20 63 75 74 73 70 6c 69 63 65 0a 2b 0a 2b 20 e cutsplice.+.+
1420: 20 20 20 73 65 74 20 72 65 73 0a 2b 7d 20 7b 30 set res.+} {0
1430: 20 31 20 30 7d 0a 2b 0a 2b 23 20 46 6f 6c 6c 6f 1 0}.+.+# Follo
1440: 77 69 6e 67 20 61 20 64 75 70 6c 69 63 61 74 65 wing a duplicate
1450: 20 6f 66 20 63 6f 64 65 20 66 6f 75 6e 64 20 69 of code found i
1460: 6e 20 22 74 68 72 65 61 64 2e 74 65 73 74 22 2e n "thread.test".
1470: 20 46 69 6e 64 20 61 20 62 65 74 74 65 72 0a 2b Find a better.+
1480: 23 20 77 61 79 20 6f 66 20 64 6f 69 6e 67 20 74 # way of doing t
1490: 68 69 73 20 77 69 74 68 6f 75 74 20 64 75 70 6c his without dupl
14a0: 69 63 61 74 69 6f 6e 2e 20 4d 61 79 62 65 20 70 ication. Maybe p
14b0: 6c 61 63 65 6d 65 6e 74 20 69 6e 74 6f 20 61 20 lacement into a
14c0: 70 72 6f 63 0a 2b 23 20 77 68 69 63 68 20 74 72 proc.+# which tr
14d0: 61 6e 73 66 6f 72 6d 73 20 74 6f 20 6e 6f 70 20 ansforms to nop
14e0: 61 66 74 65 72 20 74 68 65 20 66 69 72 73 74 20 after the first
14f0: 63 61 6c 6c 2c 20 61 6e 64 20 70 6c 61 63 65 6d call, and placem
1500: 65 6e 74 20 6f 66 20 69 74 73 0a 2b 23 20 64 65 ent of its.+# de
1510: 66 69 6e 74 69 6f 6e 20 69 6e 20 61 20 63 65 6e fintion in a cen
1520: 74 72 61 6c 20 6c 6f 63 61 74 69 6f 6e 2e 0a 2b tral location..+
1530: 0a 2b 74 65 73 74 43 6f 6e 73 74 72 61 69 6e 74 .+testConstraint
1540: 20 74 65 73 74 74 68 72 65 61 64 20 5b 65 78 70 testthread [exp
1550: 72 20 7b 5b 69 6e 66 6f 20 63 6f 6d 6d 61 6e 64 r {[info command
1560: 73 20 74 65 73 74 74 68 72 65 61 64 5d 20 21 3d s testthread] !=
1570: 20 7b 7d 7d 5d 0a 2b 0a 2b 69 66 20 7b 5b 74 65 {}}].+.+if {[te
1580: 73 74 43 6f 6e 73 74 72 61 69 6e 74 20 74 65 73 stConstraint tes
1590: 74 74 68 72 65 61 64 5d 7d 20 7b 0a 2b 20 20 20 tthread]} {.+
15a0: 20 74 65 73 74 74 68 72 65 61 64 20 65 72 72 6f testthread erro
15b0: 72 70 72 6f 63 20 54 68 72 65 61 64 45 72 72 6f rproc ThreadErro
15c0: 72 0a 2b 0a 2b 20 20 20 20 70 72 6f 63 20 54 68 r.+.+ proc Th
15d0: 72 65 61 64 45 72 72 6f 72 20 7b 69 64 20 69 6e readError {id in
15e0: 66 6f 7d 20 7b 0a 2b 09 67 6c 6f 62 61 6c 20 74 fo} {.+.global t
15f0: 68 72 65 61 64 45 72 72 6f 72 0a 2b 09 73 65 74 hreadError.+.set
1600: 20 74 68 72 65 61 64 45 72 72 6f 72 20 24 69 6e threadError $in
1610: 66 6f 0a 2b 20 20 20 20 7d 0a 2b 0a 2b 20 20 20 fo.+ }.+.+
1620: 20 70 72 6f 63 20 54 68 72 65 61 64 4e 75 6c 6c proc ThreadNull
1630: 45 72 72 6f 72 20 7b 69 64 20 69 6e 66 6f 7d 20 Error {id info}
1640: 7b 0a 2b 09 23 20 69 67 6e 6f 72 65 0a 2b 20 20 {.+.# ignore.+
1650: 20 20 7d 0a 2b 7d 0a 2b 0a 2b 74 65 73 74 20 69 }.+}.+.+test i
1660: 6f 2d 37 30 2e 31 20 7b 54 72 61 6e 73 66 65 72 o-70.1 {Transfer
1670: 20 63 68 61 6e 6e 65 6c 7d 20 7b 74 65 73 74 63 channel} {testc
1680: 68 61 6e 6e 65 6c 20 74 65 73 74 74 68 72 65 61 hannel testthrea
1690: 64 7d 20 7b 0a 2b 20 20 20 20 73 65 74 20 66 20 d} {.+ set f
16a0: 5b 6d 61 6b 65 46 69 6c 65 20 7b 2e 2e 2e 20 64 [makeFile {... d
16b0: 75 6d 6d 79 20 2e 2e 2e 7d 20 63 75 74 73 70 6c ummy ...} cutspl
16c0: 69 63 65 5d 0a 2b 20 20 20 20 73 65 74 20 63 20 ice].+ set c
16d0: 5b 6f 70 65 6e 20 24 66 20 72 5d 0a 2b 0a 2b 20 [open $f r].+.+
16e0: 20 20 20 73 65 74 20 20 20 20 20 72 65 73 20 7b set res {
16f0: 7d 0a 2b 20 20 20 20 6c 61 70 70 65 6e 64 20 72 }.+ lappend r
1700: 65 73 20 5b 63 61 74 63 68 20 7b 73 65 65 6b 20 es [catch {seek
1710: 24 63 20 30 20 73 74 61 72 74 7d 5d 0a 2b 20 20 $c 0 start}].+
1720: 20 20 74 65 73 74 63 68 61 6e 6e 65 6c 20 63 75 testchannel cu
1730: 74 20 24 63 0a 2b 20 20 20 20 6c 61 70 70 65 6e t $c.+ lappen
1740: 64 20 72 65 73 20 5b 63 61 74 63 68 20 7b 73 65 d res [catch {se
1750: 65 6b 20 24 63 20 30 20 73 74 61 72 74 7d 5d 0a ek $c 0 start}].
1760: 2b 0a 2b 20 20 20 20 73 65 74 20 74 69 64 20 5b +.+ set tid [
1770: 74 65 73 74 74 68 72 65 61 64 20 63 72 65 61 74 testthread creat
1780: 65 5d 0a 2b 20 20 20 20 74 65 73 74 74 68 72 65 e].+ testthre
1790: 61 64 20 73 65 6e 64 20 24 74 69 64 20 5b 6c 69 ad send $tid [li
17a0: 73 74 20 73 65 74 20 63 20 24 63 5d 0a 2b 20 20 st set c $c].+
17b0: 20 20 6c 61 70 70 65 6e 64 20 72 65 73 20 5b 74 lappend res [t
17c0: 65 73 74 74 68 72 65 61 64 20 73 65 6e 64 20 24 estthread send $
17d0: 74 69 64 20 7b 0a 2b 09 74 65 73 74 63 68 61 6e tid {.+.testchan
17e0: 6e 65 6c 20 73 70 6c 69 63 65 20 24 63 0a 2b 09 nel splice $c.+.
17f0: 73 65 74 20 72 65 73 20 5b 63 61 74 63 68 20 7b set res [catch {
1800: 73 65 65 6b 20 24 63 20 30 20 73 74 61 72 74 7d seek $c 0 start}
1810: 5d 0a 2b 09 63 6c 6f 73 65 20 24 63 0a 2b 09 73 ].+.close $c.+.s
1820: 65 74 20 72 65 73 0a 2b 20 20 20 20 7d 5d 0a 2b et res.+ }].+
1830: 0a 2b 20 20 20 20 74 63 6c 74 65 73 74 3a 3a 74 .+ tcltest::t
1840: 68 72 65 61 64 52 65 61 70 0a 2b 20 20 20 20 72 hreadReap.+ r
1850: 65 6d 6f 76 65 46 69 6c 65 20 63 75 74 73 70 6c emoveFile cutspl
1860: 69 63 65 0a 2b 0a 2b 20 20 20 20 73 65 74 20 72 ice.+.+ set r
1870: 65 73 0a 2b 7d 20 7b 30 20 31 20 30 7d 0a 2b 0a es.+} {0 1 0}.+.
1880: 20 23 20 63 6c 65 61 6e 75 70 0a 20 66 6f 72 65 # cleanup. fore
1890: 61 63 68 20 66 69 6c 65 20 5b 6c 69 73 74 20 66 ach file [list f
18a0: 6f 6f 42 61 72 20 6c 6f 6e 67 66 69 6c 65 20 73 ooBar longfile s
18b0: 63 72 69 70 74 20 6f 75 74 70 75 74 20 74 65 73 cript output tes
18c0: 74 31 20 70 69 70 65 20 6d 79 5f 73 63 72 69 70 t1 pipe my_scrip
18d0: 74 20 66 6f 6f 20 5c 0a 20 09 62 61 72 20 74 65 t foo \. .bar te
18e0: 73 74 32 20 74 65 73 74 33 20 63 61 74 20 73 74 st2 test3 cat st
18f0: 64 6f 75 74 20 6b 79 72 69 6c 6c 69 63 2e 74 78 dout kyrillic.tx
1900: 74 20 75 74 66 38 2d 66 63 6f 70 79 2e 74 78 74 t utf8-fcopy.txt
1910: 20 75 74 66 38 2d 72 70 2e 74 78 74 5d 20 7b 0a utf8-rp.txt] {.