Tcl Source Code

Artifact [7b4158cbb9]
Login

Artifact 7b4158cbb9cd52c5fe87709182967e1b73549db2:

Attachment "3151675.patch" to ticket [3151675fff] added by nijtmans 2011-01-06 17:46:54.
Index: generic/tclIOCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOCmd.c,v
retrieving revision 1.71
diff -u -r1.71 tclIOCmd.c
--- generic/tclIOCmd.c	10 Dec 2010 13:08:54 -0000	1.71
+++ generic/tclIOCmd.c	6 Jan 2011 10:41:28 -0000
@@ -135,32 +135,23 @@
 	break;
 
     case 4: /* [puts -nonewline $chan $x] or [puts $chan $x nonewline] */
+	newline = 0;
 	if (strcmp(TclGetString(objv[1]), "-nonewline") == 0) {
 	    chanObjPtr = objv[2];
 	    string = objv[3];
-	} else {
+	    break;
+	} else if (strcmp(TclGetString(objv[2]), "nonewline") == 0) {
 	    /*
 	     * The code below provides backwards compatibility with an old
 	     * form of the command that is no longer recommended or
 	     * documented.
 	     */
 
-	    const char *arg;
-	    int length;
-
-	    arg = TclGetStringFromObj(objv[3], &length);
-	    if ((length != 9)
-		    || (strncmp(arg, "nonewline", (size_t) length) != 0)) {
-		Tcl_AppendResult(interp, "bad argument \"", arg,
-			"\": should be \"nonewline\"", NULL);
-		return TCL_ERROR;
-	    }
 	    chanObjPtr = objv[1];
 	    string = objv[2];
+	    break;
 	}
-	newline = 0;
-	break;
-
+	/* Fall through */
     default:
 	/* [puts] or [puts some bad number of arguments...] */
 	Tcl_WrongNumArgs(interp, 1, objv, "?-nonewline? ?channelId? string");
@@ -434,19 +425,12 @@
 
     toRead = -1;
     if (i < objc) {
-	const char *arg;
-
-	arg = TclGetString(objv[i]);
-	if (isdigit(UCHAR(arg[0]))) { /* INTL: digit */
-	    if (TclGetIntFromObj(interp, objv[i], &toRead) != TCL_OK) {
-		return TCL_ERROR;
-	    }
-	} else if (strcmp(arg, "nonewline") == 0) {
+	if (strcmp(TclGetString(objv[i]), "nonewline") == 0) {
 	    newline = 1;
-	} else {
-	    Tcl_AppendResult(interp, "bad argument \"", arg,
-		    "\": should be \"nonewline\"", NULL);
+	} else if (TclGetIntFromObj(interp, objv[i], &toRead) != TCL_OK) {
 	    return TCL_ERROR;
+	} else if (toRead < 0) {
+	    goto argerror;
 	}
     }
 
Index: tests/chanio.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/chanio.test,v
retrieving revision 1.26
diff -u -r1.26 chanio.test
--- tests/chanio.test	24 Nov 2010 11:56:57 -0000	1.26
+++ tests/chanio.test	6 Jan 2011 10:41:29 -0000
@@ -3932,7 +3932,7 @@
     chan read $f -1
 } -returnCodes error -cleanup {
     chan close $f
-} -result {bad argument "-1": should be "nonewline"}
+} -result {wrong # args: should be "chan read channelId ?numChars?" or "chan read ?-nonewline? channelId"}
 test chan-io-32.4 {Tcl_Read, positive byte count} -body {
     set f [open $path(longfile) r]
     string length [chan read $f 1024]
Index: tests/io.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/io.test,v
retrieving revision 1.97
diff -u -r1.97 io.test
--- tests/io.test	10 Dec 2010 17:00:12 -0000	1.97
+++ tests/io.test	6 Jan 2011 10:41:29 -0000
@@ -3858,7 +3858,7 @@
     set l [list [catch {read $f -1} msg] $msg]
     close $f
     set l
-} {1 {bad argument "-1": should be "nonewline"}}
+} {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}}
 test io-32.4 {Tcl_Read, positive byte count} {
     set f [open $path(longfile) r]
     set x [read $f 1024]
Index: tests/ioCmd.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/ioCmd.test,v
retrieving revision 1.53
diff -u -r1.53 ioCmd.test
--- tests/ioCmd.test	3 Aug 2010 20:06:47 -0000	1.53
+++ tests/ioCmd.test	6 Jan 2011 10:41:29 -0000
@@ -35,7 +35,7 @@
 } {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}}
 test iocmd-1.3 {puts command} {
    list [catch {puts froboz -nonewline kablooie} msg] $msg
-} {1 {bad argument "kablooie": should be "nonewline"}}
+} {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}}
 test iocmd-1.4 {puts command} {
    list [catch {puts froboz hello} msg] $msg
 } {1 {can not find channel named "froboz"}}
@@ -138,7 +138,7 @@
 } {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"} {TCL WRONGARGS}}
 test iocmd-4.9 {read command} {
     list [catch {read stdin foo} msg] $msg $::errorCode
-} {1 {bad argument "foo": should be "nonewline"} NONE}
+} {1 {expected integer but got "foo"} {TCL VALUE NUMBER}}
 test iocmd-4.10 {read command} {
     list [catch {read file107} msg] $msg $::errorCode
 } {1 {can not find channel named "file107"} {TCL LOOKUP CHANNEL file107}}