Workaround for buggy gcc 2.95.3 in openbsd/sparc64.
Jarkko Hietaniemi [Fri, 23 May 2003 12:52:05 +0000 (12:52 +0000)]
p4raw-id: //depot/perl@19592

ext/Time/HiRes/HiRes.pm
ext/Time/HiRes/HiRes.t
ext/Time/HiRes/HiRes.xs

index f4c2c80..49653c3 100644 (file)
@@ -317,6 +317,17 @@ Here is an example of using NVtime from C:
   myNVtime = INT2PTR(double(*)(), SvIV(*svp));
   printf("The current time is: %f\n", (*myNVtime)());
 
+=head1 DIAGNOSTICS
+
+=head2 negative time not invented yet
+
+You tried to use a negative time argument.
+
+=head2 internal error: useconds < 0 (unsigned ... signed ...)
+
+Something went horribly wrong-- the number of microseconds that cannot
+become negative just became negative.  Maybe your compiler is broken?
+
 =head1 CAVEATS
 
 Notice that the core time() maybe rounding rather than truncating.
index 90e0979..9f6239a 100644 (file)
@@ -126,7 +126,6 @@ if (!$have_usleep || !$have_gettimeofday) {
 }
 else {
     my $r = [gettimeofday()];
-    #jTime::HiRes::sleep 0.5;
     Time::HiRes::sleep( 0.5 );
     my $f = tv_interval $r;
     ok 11, $f > 0.4 && $f < 0.9, "slept $f instead of 0.5 secs.";
index 560cb3d..5464f64 100644 (file)
@@ -36,9 +36,11 @@ typedef NVTYPE NV;
 #  ifdef IVSIZE
 #      if IVSIZE == LONGSIZE
 #           define     IVdf            "ld"
+#           define     UVuf            "lu"
 #       else
 #           if IVSIZE == INTSIZE
 #               define IVdf    "d"
+#               define UVuf    "u"
 #           endif
 #       endif
 #   else
@@ -683,6 +685,17 @@ sleep(...)
                 UV useconds = (UV)(1E6 * (seconds - (UV)seconds));
                 if (seconds >= 1.0)
                     sleep((U32)seconds);
+                if ((IV)useconds < 0) {
+#if defined(__sparc64__) && defined(__GNUC__)
+                  /* Sparc64 gcc 2.95.3 (e.g. on NetBSD) has a bug
+                   * where (0.5 - (UV)(0.5)) will under certain
+                   * circumstances (if the double is cast to UV more
+                   * than once?) evaluate to -0.5, instead of 0.5. */
+                  useconds = -(IV)useconds;
+#endif
+                  if ((IV)useconds < 0)
+                    croak("Time::HiRes::sleep(%"NVgf"): internal error: useconds < 0 (unsigned %"UVuf" signed %"IVdf")", seconds, useconds, (IV)useconds);
+                }
                 usleep(useconds);
            } else
                croak("Time::HiRes::sleep(%"NVgf"): negative time not invented yet", seconds);