summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2002-02-10 11:06:05 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2002-02-10 11:06:05 +0000
commit7950f36a3c7906b0893d847946940f59787f08c6 (patch)
treeedbf9b284f4bc435d9b2d73f27fbc3531862e17b /t
parentde745a2ec314da23cb486732c6f7078af1fa26c6 (diff)
parent2eb5892fff31d60c2828ced5e374168be3df4a62 (diff)
downloadperl-7950f36a3c7906b0893d847946940f59787f08c6.tar.gz
Integrate mainline
p4raw-id: //depot/perlio@14619
Diffstat (limited to 't')
-rw-r--r--t/lib/warnings/pp_hot61
-rwxr-xr-xt/op/arith.t18
2 files changed, 56 insertions, 23 deletions
diff --git a/t/lib/warnings/pp_hot b/t/lib/warnings/pp_hot
index c5a3790587..11826b9ca2 100644
--- a/t/lib/warnings/pp_hot
+++ b/t/lib/warnings/pp_hot
@@ -7,7 +7,7 @@
print STDIN "abc" ;
Filehandle %s opened only for output [pp_print]
- print <STDOUT> ;
+ $a = <STDOUT> ;
print() on closed filehandle %s [pp_print]
close STDIN ; print STDIN "abc" ;
@@ -62,27 +62,32 @@ print() on unopened filehandle abc at - line 4.
########
# pp_hot.c [pp_print]
use warnings 'io' ;
-print STDIN "anc";
-print <STDOUT>;
-print <STDERR>;
-open(FOO, ">&STDOUT") and print <FOO>;
-print getc(STDERR);
-print getc(FOO);
-####################################################################
-# The next test is known to fail on some systems (Linux+old glibc, #
-# some *BSDs (including Mac OS X and NeXT), among others. #
-# We skip it for now (on the grounds that it is "just" a warning). #
-####################################################################
-#read(FOO,$_,1);
+# There is no guarantee that STDOUT is output only, or STDIN input only.
+# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
+# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
+# So we must make our own file handle that is read only.
+my $file = "./xcv" ; unlink $file ;
+open (FH, ">$file") or die $! ;
+close FH or die $! ;
+die "There is no file $file" unless -f $file ;
+open (FH, "<$file") or die $! ;
+print FH "anc" ;
+open(FOO, "<&FH") or die $! ;
+print FOO "anc" ;
no warnings 'io' ;
-print STDIN "anc";
+print FH "anc" ;
+print FOO "anc" ;
+use warnings 'io' ;
+print FH "anc" ;
+print FOO "anc" ;
+close (FH) or die $! ;
+close (FOO) or die $! ;
+unlink $file ;
EXPECT
-Filehandle STDIN opened only for input at - line 3.
-Filehandle STDOUT opened only for output at - line 4.
-Filehandle STDERR opened only for output at - line 5.
-Filehandle FOO opened only for output at - line 6.
-Filehandle STDERR opened only for output at - line 7.
-Filehandle FOO opened only for output at - line 8.
+Filehandle FH opened only for input at - line 12.
+Filehandle FOO opened only for input at - line 14.
+Filehandle FH opened only for input at - line 19.
+Filehandle FOO opened only for input at - line 20.
########
# pp_hot.c [pp_print]
use warnings 'closed' ;
@@ -150,14 +155,26 @@ readline() on closed filehandle STDIN at - line 4.
# pp_hot.c [Perl_do_readline]
use warnings 'io' ;
my $file = "./xcv" ; unlink $file ;
-open (FH, ">./xcv") ;
+open (FH, ">$file") or die $! ;
my $a = <FH> ;
no warnings 'io' ;
$a = <FH> ;
-close (FH) ;
+use warnings 'io' ;
+open(FOO, ">&FH") or die $! ;
+$a = <FOO> ;
+no warnings 'io' ;
+$a = <FOO> ;
+use warnings 'io' ;
+$a = <FOO> ;
+$a = <FH> ;
+close (FH) or die $! ;
+close (FOO) or die $! ;
unlink $file ;
EXPECT
Filehandle FH opened only for output at - line 5.
+Filehandle FOO opened only for output at - line 10.
+Filehandle FOO opened only for output at - line 14.
+Filehandle FH opened only for output at - line 15.
########
# pp_hot.c [Perl_sub_crush_depth]
use warnings 'recursion' ;
diff --git a/t/op/arith.t b/t/op/arith.t
index 6e61477baf..a607e60149 100755
--- a/t/op/arith.t
+++ b/t/op/arith.t
@@ -1,6 +1,6 @@
#!./perl -w
-print "1..130\n";
+print "1..132\n";
sub try ($$) {
print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
@@ -245,7 +245,23 @@ tryeq 125, -4.5 / 2, -2.25;
tryeq 126, -5.5 / -2, 2.75;
# Bluuurg if your floating point can't accurately cope with powers of 2
+# [I suspect this is parsing string->float problems, not actual arith]
tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg
tryeq 128, 18446744073709551616/2, 9223372036854775808;
tryeq 129, 18446744073709551616/4294967296, 4294967296;
tryeq 130, 18446744073709551616/9223372036854775808, 2;
+
+{
+ # The peephole optimiser is wrong to think that it can substitute intops
+ # in place of regular ops, because i_multiply can overflow.
+ # Bug reported by "Sisyphus" <kalinabears@hdc.com.au>
+ my $n = 1127;
+
+ my $float = ($n % 1000) * 167772160.0;
+ tryeq 131, $float, 21307064320;
+
+ # On a 32 bit machine, if the i_multiply op is used, you will probably get
+ # -167772160. It's actually undefined behaviour, so anything may happen.
+ my $int = ($n % 1000) * 167772160;
+ tryeq 132, $int, 21307064320;
+}