Skip to content

Commit de4257d

Browse files
committed
Time::HiRes.xs factor out "negative time not invented yet" croaks() msgs
1 parent 7c0d4cd commit de4257d

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

dist/Time-HiRes/HiRes.xs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,9 @@ usleep(useconds)
10141014
useconds -= NV_1E6 * seconds;
10151015
}
10161016
} else if (useconds < 0.0)
1017-
croak("Time::HiRes::usleep(%" NVgf
1018-
"): negative time not invented yet", useconds);
1019-
1017+
croak("%s(%" NVgf "%s",
1018+
"Time::HiRes::usleep", useconds,
1019+
"): negative time not invented yet");
10201020
usleep((U32)useconds);
10211021
} else
10221022
PerlProc_pause();
@@ -1039,8 +1039,8 @@ nanosleep(nsec)
10391039
struct timespec sleepfor, unslept;
10401040
CODE:
10411041
if (nsec < 0.0)
1042-
croak("Time::HiRes::nanosleep(%" NVgf
1043-
"): negative time not invented yet", nsec);
1042+
croak("%s(%" NVgf "%s", "Time::HiRes::nanosleep", nsec,
1043+
"): negative time not invented yet");
10441044
nanosleep_init(nsec, &sleepfor, &unslept);
10451045
if (nanosleep(&sleepfor, &unslept) == 0) {
10461046
RETVAL = nsec;
@@ -1085,15 +1085,16 @@ sleep(...)
10851085
useconds = -(IV)useconds;
10861086
# endif /* #if defined(__sparc64__) && defined(__GNUC__) */
10871087
if ((IV)useconds < 0)
1088-
croak("Time::HiRes::sleep(%" NVgf
1088+
croak("%s(%" NVgf
10891089
"): internal error: useconds < 0 (unsigned %" UVuf
1090-
" signed %" IVdf ")",
1090+
" signed %" IVdf ")", "Time::HiRes::sleep",
10911091
seconds, useconds, (IV)useconds);
10921092
}
10931093
usleep(useconds);
10941094
} else
1095-
croak("Time::HiRes::sleep(%" NVgf
1096-
"): negative time not invented yet", seconds);
1095+
croak("%s(%" NVgf "%s",
1096+
"Time::HiRes::sleep", seconds,
1097+
"): negative time not invented yet");
10971098
} else
10981099
PerlProc_pause();
10991100

@@ -1128,7 +1129,9 @@ ualarm(useconds,uinterval=0)
11281129
int uinterval
11291130
CODE:
11301131
if (useconds < 0 || uinterval < 0)
1131-
croak("Time::HiRes::ualarm(%d, %d): negative time not invented yet", useconds, uinterval);
1132+
croak("%s(%d, %d%s",
1133+
"Time::HiRes::ualarm", useconds, uinterval,
1134+
"): negative time not invented yet");
11321135
# if defined(HAS_SETITIMER) && defined(ITIMER_REAL)
11331136
{
11341137
struct itimerval itv;
@@ -1158,9 +1161,9 @@ alarm(seconds,interval=0)
11581161
NV interval
11591162
CODE:
11601163
if (seconds < 0.0 || interval < 0.0)
1161-
croak("Time::HiRes::alarm(%" NVgf ", %" NVgf
1162-
"): negative time not invented yet", seconds, interval);
1163-
1164+
croak("%s(%" NVgf ", %" NVgf "%s",
1165+
"Time::HiRes::alarm", seconds, interval,
1166+
"): negative time not invented yet");
11641167
{
11651168
IV iseconds = (IV)seconds;
11661169
IV iinterval = (IV)interval;
@@ -1281,9 +1284,10 @@ setitimer(which, seconds, interval = 0)
12811284
struct itimerval oldit;
12821285
PPCODE:
12831286
if (seconds < 0.0 || interval < 0.0)
1284-
croak("Time::HiRes::setitimer(%" IVdf ", %" NVgf ", %" NVgf
1285-
"): negative time not invented yet",
1286-
(IV)which, seconds, interval);
1287+
croak("%s(%" IVdf ", %" NVgf ", %" NVgf "%s",
1288+
"Time::HiRes::setitimer",
1289+
(IV)which, seconds, interval,
1290+
"): negative time not invented yet");
12871291
newit.it_value.tv_sec = (IV)seconds;
12881292
newit.it_value.tv_usec =
12891293
(IV)((seconds - (NV)newit.it_value.tv_sec) * NV_1E6);
@@ -1350,9 +1354,9 @@ PROTOTYPE: $$@
13501354
utbufp = NULL;
13511355
else {
13521356
if (SvNV(accessed) < 0.0 || SvNV(modified) < 0.0)
1353-
croak("Time::HiRes::utime(%" NVgf ", %" NVgf
1354-
"): negative time not invented yet",
1355-
SvNV(accessed), SvNV(modified));
1357+
croak("%s(%" NVgf ", %" NVgf "%s", "Time::HiRes::utime",
1358+
SvNV(accessed), SvNV(modified),
1359+
"): negative time not invented yet");
13561360
Zero(&utbuf, sizeof utbuf, char);
13571361

13581362
utbuf[0].tv_sec = (Time_t)SvNV(accessed); /* time accessed */
@@ -1499,8 +1503,9 @@ clock_nanosleep(clock_id, nsec, flags = 0)
14991503
struct timespec sleepfor, unslept;
15001504
CODE:
15011505
if (nsec < 0.0)
1502-
croak("Time::HiRes::clock_nanosleep(..., %" NVgf
1503-
"): negative time not invented yet", nsec);
1506+
croak("%s(..., %" NVgf "%s",
1507+
"Time::HiRes::clock_nanosleep", nsec,
1508+
"): negative time not invented yet");
15041509
nanosleep_init(nsec, &sleepfor, &unslept);
15051510
if (clock_nanosleep(clock_id, flags, &sleepfor, &unslept) == 0) {
15061511
RETVAL = nsec;

0 commit comments

Comments
 (0)