Skip to content

Commit aaaa854

Browse files
committed
Time::HiRes::sleep: use (;$) prototype, like CORE::sleep
Time::HiRes::sleep is supposed to be a drop-in replacement for CORE::sleep, but before this patch Time::HiRes::sleep had no prototype, leading to the following incompatibilities: CORE::sleep(1, "foo", "bar"); # syntax error Time::HiRes::sleep(1, "foo", "bar"); # OK, ignores all but 1st argument my @t = 42; CORE::sleep @t; # sleeps for one second (number of elements in @t) Time::HiRes::sleep @t; # sleeps for 42 seconds (@t in list context) CORE::sleep 1, next if $foo; # if $foo, then sleep for one second and start next loop iteration Time::HiRes::sleep 1, next if $foo; # parses as: Time::HiRes::sleep(1, next) if $foo; # if $foo, then start next loop iteration; no delay Fixes #23628.
1 parent 2a3e42a commit aaaa854

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

dist/Time-HiRes/Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Revision history for the Perl extension Time::HiRes.
1919
build failures with MSVC.
2020
- don't try to suppress C++ compatibility warnings in C++ builds, since
2121
that warns.
22+
- Fix sleep's prototype to match CORE::sleep (;$).
2223

2324
1.9764 [2020-08-10]
2425
- Fix a bunch of repeated-word typos

dist/Time-HiRes/HiRes.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval
5050
stat lstat utime
5151
);
5252

53-
our $VERSION = '1.9778';
53+
our $VERSION = '1.9779';
5454
our $XS_VERSION = $VERSION;
5555
$VERSION = eval $VERSION;
5656

dist/Time-HiRes/HiRes.xs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ nanosleep(nsec)
10191019

10201020
NV
10211021
sleep(...)
1022+
PROTOTYPE: ;$
10221023
PREINIT:
10231024
struct timeval Ta, Tb;
10241025
CODE:

dist/Time-HiRes/t/sleep.t

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
use strict;
22

3-
use Test::More tests => 4;
3+
use Test::More tests => 5;
44
BEGIN { push @INC, '.' }
55
use t::Watchdog;
66

77
BEGIN { require_ok "Time::HiRes"; }
88

99
use Config;
1010

11+
SKIP: {
12+
skip "no hi-res sleep", 1 unless defined &Time::HiRes::sleep;
13+
is prototype(\&Time::HiRes::sleep), prototype('CORE::sleep'),
14+
"Time::HiRes::sleep's prototype matches CORE::sleep's";
15+
}
16+
1117
my $xdefine = '';
1218
if (open(XDEFINE, "<", "xdefine")) {
1319
chomp($xdefine = <XDEFINE> || "");
@@ -35,5 +41,3 @@ SKIP: {
3541
printf("# sleep...%s\n", Time::HiRes::tv_interval($r));
3642
ok 1;
3743
}
38-
39-
1;

dist/Time-HiRes/t/time.t

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
use strict;
22

3-
use Test::More tests => 2;
3+
use Test::More tests => 3;
44
BEGIN { push @INC, '.' }
55
use t::Watchdog;
66

77
BEGIN { require_ok "Time::HiRes"; }
88

9+
SKIP: {
10+
skip "no hi-res time", 1 unless defined &Time::HiRes::time;
11+
is prototype(\&Time::HiRes::time), prototype('CORE::time'),
12+
"Time::HiRes::time's prototype matches CORE::time's";
13+
}
14+
915
SKIP: {
1016
skip "no gettimeofday", 1 unless &Time::HiRes::d_gettimeofday;
1117
my ($s, $n, $i) = (0);
@@ -20,5 +26,3 @@ SKIP: {
2026
or print("# Time::HiRes::time() not close to CORE::time()\n");
2127
printf("# s = $s, n = $n, s/n = %s\n", abs($s)/$n);
2228
}
23-
24-
1;

0 commit comments

Comments
 (0)