The following code fails when compiled with defined(HAS_SETITIMER) &&
defined(ITIMER_REAL):
use strict;
use Time::HiRes qw(alarm);
my $alrm;
$SIG{ALRM} = sub { $alrm++};
alarm(0.1);
sleep(1);
print $alrm ? "ok\n" : "fail\n";
The attached patch fixes the problem
Subject: | perl-time-hires.diff |
--- HiRes.xs.0 2008-05-10 20:02:23.000000000 +0200
+++ HiRes.xs 2008-05-11 18:44:53.000000000 +0200
@@ -925,7 +925,6 @@
CODE:
if (useconds < 0 || uinterval < 0)
croak("Time::HiRes::ualarm(%d, %d): negative time not invented yet", useconds, uinterval);
- if (useconds >= IV_1E6 || uinterval >= IV_1E6)
#if defined(HAS_SETITIMER) && defined(ITIMER_REAL)
{
struct itimerval itv;
@@ -936,10 +935,10 @@
}
}
#else
+ if (useconds >= IV_1E6 || uinterval >= IV_1E6)
croak("Time::HiRes::ualarm(%d, %d): useconds or uinterval equal to or more than %"IVdf, useconds, uinterval, IV_1E6);
+ RETVAL = ualarm(useconds, uinterval);
#endif
- else
- RETVAL = ualarm(useconds, uinterval);
OUTPUT:
RETVAL
@@ -954,7 +953,6 @@
{
IV useconds = IV_1E6 * seconds;
IV uinterval = IV_1E6 * interval;
- if (seconds >= IV_1E6 || interval >= IV_1E6)
#if defined(HAS_SETITIMER) && defined(ITIMER_REAL)
{
struct itimerval itv;
@@ -965,8 +963,9 @@
}
}
#else
- RETVAL = (NV)ualarm((IV)(seconds * IV_1E6),
- (IV)(interval * IV_1E6)) / NV_1E6;
+ if (useconds >= IV_1E6 || uinterval >= IV_1E6)
+ croak("Time::HiRes::alarm(%d, %d): seconds or interval equal to or more than 1.0 ", useconds, uinterval, IV_1E6);
+ RETVAL = (NV)ualarm( useconds, uinterval) / NV_1E6;
#endif
}