From: Jarkko Hietaniemi Date: Fri, 23 May 2003 12:52:05 +0000 (+0000) Subject: Workaround for buggy gcc 2.95.3 in openbsd/sparc64. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db0b859feb1075204019fdea30072b46da24e0c5;p=p5sagit%2Fp5-mst-13.2.git Workaround for buggy gcc 2.95.3 in openbsd/sparc64. p4raw-id: //depot/perl@19592 --- diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm index f4c2c80..49653c3 100644 --- a/ext/Time/HiRes/HiRes.pm +++ b/ext/Time/HiRes/HiRes.pm @@ -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. diff --git a/ext/Time/HiRes/HiRes.t b/ext/Time/HiRes/HiRes.t index 90e0979..9f6239a 100644 --- a/ext/Time/HiRes/HiRes.t +++ b/ext/Time/HiRes/HiRes.t @@ -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."; diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index 560cb3d..5464f64 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -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);