summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--generic/tclIOCmd.c21
-rw-r--r--tests/chanio.test40
-rw-r--r--tests/io.test40
-rw-r--r--tests/ioCmd.test8
5 files changed, 96 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index be32e53..fe9b909 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-04-10 Andreas Kupries <andreask@activestate.com>
+
+ * generic/tclIOCmd.c (Tcl_FcopyObjCmd): Keeping check for negative
+ values, changed to not be an error, but behave like the special
+ value -1 (copy all, default).
+
+ * tests/iocmd.test (iocmd-15.{12,13}): Removed.
+
+ * tests/io.test (io-52.5{,a,b}): Reverted last change, added
+ * tests/chanio.test (chan-io-52.5{,a,b}): comment regarding the
+ meaning of -1, added two more testcases for other negative values,
+ and input wrapped to negative.
+
2008-04-09 Andreas Kupries <andreask@activestate.com>
* tests/chanio.test (chan-io-52.5): Removed '-size -1' from test,
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index 3c34845..00ca527 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIOCmd.c,v 1.51.2.1 2008/04/09 18:36:18 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclIOCmd.c,v 1.51.2.2 2008/04/10 20:55:26 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -1644,18 +1644,13 @@ Tcl_FcopyObjCmd(
return TCL_ERROR;
}
if (toRead<0) {
- Tcl_WideInt w;
- if (Tcl_GetWideIntFromObj(interp, objv[i+1], &w) != TCL_OK) {
- return TCL_ERROR;
- }
- if (w >= (Tcl_WideInt)0) {
- Tcl_AppendResult(interp,
- "integer value to large to represent as 32bit signed value",
- NULL);
- } else {
- Tcl_AppendResult(interp, "negative size forbidden", NULL);
- }
- return TCL_ERROR;
+ /*
+ * Handle all negative sizes like -1, meaning 'copy all'. By
+ * resetting toRead we avoid changes in the core copying
+ * functions (which explicitly check for -1 and crash on any
+ * other negative value).
+ */
+ toRead = -1;
}
break;
case FcopyCommand:
diff --git a/tests/chanio.test b/tests/chanio.test
index 75c0013..f276a00 100644
--- a/tests/chanio.test
+++ b/tests/chanio.test
@@ -13,7 +13,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: chanio.test,v 1.3.2.7 2008/04/09 19:51:12 andreas_kupries Exp $
+# RCS: @(#) $Id: chanio.test,v 1.3.2.8 2008/04/10 20:55:27 andreas_kupries Exp $
if {[catch {package require tcltest 2}]} {
chan puts stderr "Skipping tests in [info script]. tcltest 2 required."
@@ -6541,13 +6541,47 @@ test chan-io-52.4 {TclCopyChannel} {fcopy} {
chan close $f2
lappend result [file size $path(test1)]
} {0 0 40}
-test chan-io-52.5 {TclCopyChannel} {fcopy} {
+test chan-io-52.5 {TclCopyChannel, all} {fcopy} {
file delete $path(test1)
set f1 [open $thisScript]
set f2 [open $path(test1) w]
chan configure $f1 -translation lf -blocking 0
chan configure $f2 -translation lf -blocking 0
- chan copy $f1 $f2 ;#-size -1
+ chan copy $f1 $f2 -size -1 ;# -1 means 'copy all', same as if no -size specified.
+ set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]]
+ chan close $f1
+ chan close $f2
+ set s1 [file size $thisScript]
+ set s2 [file size $path(test1)]
+ if {"$s1" == "$s2"} {
+ lappend result ok
+ }
+ set result
+} {0 0 ok}
+test chan-io-52.5a {TclCopyChannel, all, other negative value} {fcopy} {
+ file delete $path(test1)
+ set f1 [open $thisScript]
+ set f2 [open $path(test1) w]
+ chan configure $f1 -translation lf -blocking 0
+ chan configure $f2 -translation lf -blocking 0
+ chan copy $f1 $f2 -size -2 ;# < 0 behaves like -1, copy all
+ set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]]
+ chan close $f1
+ chan close $f2
+ set s1 [file size $thisScript]
+ set s2 [file size $path(test1)]
+ if {"$s1" == "$s2"} {
+ lappend result ok
+ }
+ set result
+} {0 0 ok}
+test chan-io-52.5b {TclCopyChannel, all, wrapped to ngative value} {fcopy} {
+ file delete $path(test1)
+ set f1 [open $thisScript]
+ set f2 [open $path(test1) w]
+ chan configure $f1 -translation lf -blocking 0
+ chan configure $f2 -translation lf -blocking 0
+ chan copy $f1 $f2 -size 3221176172 ;# Wrapped to < 0, behaves like -1, copy all
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]]
chan close $f1
chan close $f2
diff --git a/tests/io.test b/tests/io.test
index 45e7338..6ec186c 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -13,7 +13,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: io.test,v 1.80.2.7 2008/04/09 19:51:12 andreas_kupries Exp $
+# RCS: @(#) $Id: io.test,v 1.80.2.8 2008/04/10 20:55:27 andreas_kupries Exp $
if {[catch {package require tcltest 2}]} {
puts stderr "Skipping tests in [info script]. tcltest 2 required."
@@ -6541,13 +6541,47 @@ test io-52.4 {TclCopyChannel} {fcopy} {
close $f2
lappend result [file size $path(test1)]
} {0 0 40}
-test io-52.5 {TclCopyChannel} {fcopy} {
+test io-52.5 {TclCopyChannel, all} {fcopy} {
file delete $path(test1)
set f1 [open $thisScript]
set f2 [open $path(test1) w]
fconfigure $f1 -translation lf -blocking 0
fconfigure $f2 -translation lf -blocking 0
- fcopy $f1 $f2 ;#-size -1
+ fcopy $f1 $f2 -size -1 ;# -1 means 'copy all', same as if no -size specified.
+ set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
+ close $f1
+ close $f2
+ set s1 [file size $thisScript]
+ set s2 [file size $path(test1)]
+ if {"$s1" == "$s2"} {
+ lappend result ok
+ }
+ set result
+} {0 0 ok}
+test io-52.5a {TclCopyChannel, all, other negative value} {fcopy} {
+ file delete $path(test1)
+ set f1 [open $thisScript]
+ set f2 [open $path(test1) w]
+ fconfigure $f1 -translation lf -blocking 0
+ fconfigure $f2 -translation lf -blocking 0
+ fcopy $f1 $f2 -size -2 ;# < 0 behaves like -1, copy all
+ set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
+ close $f1
+ close $f2
+ set s1 [file size $thisScript]
+ set s2 [file size $path(test1)]
+ if {"$s1" == "$s2"} {
+ lappend result ok
+ }
+ set result
+} {0 0 ok}
+test io-52.5b {TclCopyChannel, all, wrapped to negative value} {fcopy} {
+ file delete $path(test1)
+ set f1 [open $thisScript]
+ set f2 [open $path(test1) w]
+ fconfigure $f1 -translation lf -blocking 0
+ fconfigure $f2 -translation lf -blocking 0
+ fcopy $f1 $f2 -size 3221176172 ;# Wrapped to < 0, behaves like -1, copy all
set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
close $f1
close $f2
diff --git a/tests/ioCmd.test b/tests/ioCmd.test
index 2906871..5c6a330 100644
--- a/tests/ioCmd.test
+++ b/tests/ioCmd.test
@@ -13,7 +13,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: ioCmd.test,v 1.36.2.3 2008/04/09 18:36:18 andreas_kupries Exp $
+# RCS: @(#) $Id: ioCmd.test,v 1.36.2.4 2008/04/10 20:55:27 andreas_kupries Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -606,12 +606,6 @@ test iocmd-15.11 {Tcl_FcopyObjCmd} {fcopy} {
test iocmd-15.12 {Tcl_FcopyObjCmd} {fcopy} {
list [catch {fcopy $rfile $wfile -command bar -size foo} msg] $msg
} {1 {expected integer but got "foo"}}
-test iocmd-15.13 {Tcl_FcopyObjCmd} {fcopy} {
- list [catch {fcopy $rfile $wfile -command bar -size 3221176172} msg] $msg
-} {1 {integer value to large to represent as 32bit signed value}}
-test iocmd-15.14 {Tcl_FcopyObjCmd} {fcopy} {
- list [catch {fcopy $rfile $wfile -command bar -size -2} msg] $msg
-} {1 {negative size forbidden}}
close $rfile
close $wfile