Artifacts Associated With Ticket 405995ffffffffff
Ticket change [a39b4c37da] (rid 110069) by nobody on 2001-03-05 11:34:35:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Tcl_Ungets puts the bytes into the beginning of the buffer, not staring at bufPtr->nextAdded. diff -r tcl8.3.2/generic/tclIO.c tcl8.3.2.new/generic/tclIO.c 4553c4553 < bufPtr->buf[i] = str[i]; --- > bufPtr->buf[bufPtr->nextAdded++] = str[i]; 4555d4554 < bufPtr->nextAdded += len;
- foundin initialized to: "obsolete: 8.4a2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "24. Channel Commands"
- title initialized to: "Tcl_Ungets filling buffer wrongly"
- type initialized to: "Bug"
Ticket change [048f8cfe9c] (rid 120016) by andreas_kupries on 2001-07-17 01:51:46:
- assignee changed to: "andreas_kupries"
Ticket change [9376a32dd4] (rid 105822) by andreas_kupries on 2001-07-20 01:24:31:
- icomment:
Logged In: YES user_id=75003 Doesn't this have to take "atEnd" into account too ?
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [46a22ff0c8] (rid 99550) by jiangwu on 2004-02-03 02:41:54:
- icomment:
Logged In: YES user_id=966384 I tried this patch on 8.4.4 and it seems to work. Here is the diff against 8.4.4: cvs diff -u tclIO.c Index: tclIO.c ============================================== ===================== RCS file: /home/cvs/starvine/cvsroot/tcl/generic/tclIO.c,v retrieving revision 1.2 diff -u -r1.2 tclIO.c --- tclIO.c 11 Oct 2003 07:02:47 -0000 1.2 +++ tclIO.c 2 Feb 2004 19:36:55 -0000 @@ -5041,9 +5041,8 @@ bufPtr = AllocChannelBuffer(len); for (i = 0; i < len; i++) { - bufPtr->buf[i] = str[i]; + bufPtr->buf[bufPtr->nextAdded++] = str[i]; } - bufPtr->nextAdded += len; if (statePtr->inQueueHead == (ChannelBuffer *) NULL) { bufPtr->nextPtr = (ChannelBuffer *) NULL; - login: "jiangwu"
- mimetype: "text/plain"
- username: "jiangwu"
- icomment:
Ticket change [326e895f0e] (rid 93608) by davygrvy on 2004-02-03 04:16:53:
- assignee changed to: "davygrvy"
Ticket change [80796a4133] (rid 116874) by davygrvy on 2004-02-03 04:31:20:
- icomment:
Logged In: YES user_id=7549 atEnd is handled by the splice operation below this code. Fix applied to HEAD: tclIO.c -r1.70
- login: "davygrvy"
- mimetype: "text/plain"
- username: "davygrvy"
- icomment:
Ticket change [4cbad4271d] (rid 126939) by davygrvy on 2004-02-03 04:35:34:
- closedate changed to: "2004-02-02T21:35:34"
- closer changed to: "davygrvy"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [693784f873] (rid 103210) by hobbs on 2004-02-03 04:42:08:
- icomment:
Logged In: YES user_id=72656 If the fix is correct, why not backport it to 8.4 as well?
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
- icomment:
Ticket change [97bea819dc] (rid 110489) by dgp on 2004-02-03 04:56:24:
- icomment:
Logged In: YES user_id=80530 Is there a test in the test suite that fails without the fix, and succeeds with it?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [8865bb97ab] (rid 131857) by davygrvy on 2004-02-03 05:00:17:
- icomment:
Logged In: YES user_id=7549 no there isn't
- login: "davygrvy"
- mimetype: "text/plain"
- username: "davygrvy"
- icomment:
Ticket change [17ab7930d1] (rid 122537) by dkf on 2004-02-03 18:14:31:
- icomment:
Logged In: YES user_id=79902 Reopening until a test is written. Sorry to be tedious, but it's the only way to stop silly mistakes in the future. (BTW, if it is awkward to test this with normal commands, just slap some test code into tclTest.c and do it that way. :))
- login: "dkf"
- mimetype: "text/plain"
- status changed to: "Open"
- username: "dkf"
- icomment:
Ticket change [3ec0071ad7] (rid 121325) by dkf on 2004-02-03 18:14:55:
- closedate changed to: "2004-02-03T11:14:55"
- closer changed to: "dkf"
- priority changed to: "9 Immediate"
- status changed to: "Closed"
Ticket change [6ecade9997] (rid 100202) by jiangwu on 2004-02-07 03:29:42:
- icomment:
Logged In: YES user_id=966384 There are no way to test this using normal Tcl command. Here is something I put together, which adds a "ungets" subcommand to "testchannel", then added a single test to the "io.test" to verify ungets. This test fails without the fix and succeeds with the fix: > cvs diff -u generic/tclTest.c tests/io.test Index: generic/tclTest.c ============================================== ===================== RCS file: /home/cvs/starvine/cvsroot/tcl/generic/tclTest.c,v retrieving revision 1.2 diff -u -r1.2 tclTest.c --- generic/tclTest.c 11 Oct 2003 07:02:48 -0000 1.2 +++ generic/tclTest.c 6 Feb 2004 20:26:53 -0000 @@ -291,6 +291,9 @@ static Tcl_Channel TestOpenFileChannelProc3 _ANSI_ARGS_(( Tcl_Interp *interp, CONST char *fileName, CONST char *modeString, int permissions)); +static int UngetsChannelProc _ANSI_ARGS_(( + Tcl_Interp *interp, Tcl_Channel channel, + CONST char *input, CONST char *addAtEnd)); static int TestpanicCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, CONST char **argv)); static int TestparserObjCmd _ANSI_ARGS_ ((ClientData dummy, @@ -5158,6 +5161,46 @@ return (NULL); } } + + +/* + *-------------------------------------------------------- -------------- + * + * UngetsChannelProc -- + * + * Implements the "ungets ..." subcommand in TestChannelCmd. Calls + * the "Tcl_Ungets" C API with the given arguments. + * + * Results: + * A integer value, as returned by Tcl_Ungets. + * + * Side effects: + * None. + * + *-------------------------------------------------------- -------------- + */ +static int +UngetsChannelProc(interp, channel, input, addAtEnd) + Tcl_Interp *interp; /* Interpreter for error reporting */ + Tcl_Channel channel; /* Channel to push the data back */ + CONST char *input; /* String to push back */ + CONST char *addAtEnd; /* A integer flag, 1 or 0 for whether + the string should be pushed back to + the end or the beginning */ +{ + int inputLen = strlen(input); + int len, addAtEndFlag; + + if (Tcl_GetInt(interp, addAtEnd, &addAtEndFlag) == TCL_ERROR) { + Tcl_AppendResult(interp, "expecting an integer flag for \"addAtEnd\"", + (char *) NULL); + return TCL_ERROR; + } + len = Tcl_Ungets(channel, input, inputLen, addAtEndFlag); + Tcl_SetObjResult(interp, Tcl_NewIntObj(len)); + + return TCL_OK; +} ♀ /* *--------------------------------------------------------- ------------- @@ -5580,9 +5623,23 @@ return Tcl_UnstackChannel(interp, chan); } + if ((cmdName[0] == 'u') && (strncmp(cmdName, "ungets", len) == 0)) { + /* + * Syntax: ungets channel string + */ + + if (argc != 5) { + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], + " ungets channel string atEnd\"", (char *) NULL); + return TCL_ERROR; + } + + return UngetsChannelProc(interp, chan, argv[3], argv [4]); + } + Tcl_AppendResult(interp, "bad option \"", cmdName, "\": should be ", "cut, clearchannelhandlers, info, isshared, mode, open, " - "readable, splice, writable, transform, unstack", + "readable, splice, writable, transform, unstack, ungets", (char *) NULL); return TCL_ERROR; } Index: tests/io.test ============================================== ===================== RCS file: /home/cvs/starvine/cvsroot/tcl/tests/io.test,v retrieving revision 1.2 diff -u -r1.2 io.test --- tests/io.test 11 Oct 2003 07:02:50 -0000 1.2 +++ tests/io.test 6 Feb 2004 20:27:00 -0000 @@ -7109,8 +7109,19 @@ list $x $result } {1 {gets {} catch {error writing "stdout": invalid argument}}} +# Test Tcl_Ungets - +test io-61.1 {testing Tcl_Ungets, push data back at beginning} {testchannel} { + set f [open $path(test1) w] + puts $f "123456789" + close $f + set f [open $path(test1) r] + gets $f + testchannel ungets $f "123" 0 + set x [gets $f] + close $f + set x +} {123} # cleanup foreach file [list fooBar longfile script output test1 pipe my_script foo \ - login: "jiangwu"
- mimetype: "text/plain"
- username: "jiangwu"
- icomment: