Skip to content

Commit 85750a8

Browse files
committed
Time::HiRes.xs add a specialized croak_unimplemented(cv) function
croak("%s(): unimplemented in this platform", "Time::HiRes::ualarm"); This can be estimated at 6 + 7 + 7 = 20 bytes of machine code on Intel. My guess on a RISC CPU is 3 * 2 * 4 = 24 bytes. On any CPU arch, the asm code will look like: mov rel_U32; mov rel_U32; call rel_U32; So create a dedicated static croak func, so these unimplemented stubs are smaller, and will look like: mov reg, reg; call rel_U32; RISC: 4 + (4 || 8) Intel: 3 + (5 || 6)
1 parent 4fd0d8a commit 85750a8

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

dist/Time-HiRes/HiRes.xs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,39 @@ nsec_without_unslept(struct timespec *sleepfor,
972972
# define IS_SAFE_PATHNAME(pv, len, opname) (((len)>1)&&memchr((pv), 0, (len)-1)?(SETERRNO(ENOENT, LIB_INVARG),WARNEMU(opname),FALSE):(TRUE))
973973
#endif
974974

975+
STATIC void
976+
S_croak_xs_unimplemented(const CV *const cv);
977+
978+
STATIC void
979+
S_croak_xs_unimplemented(const CV *const cv)
980+
{
981+
dTHX;
982+
char buf[sizeof("CODE(0x%" UVxf ")") + (sizeof(UV)*8)];
983+
const char * pv1;
984+
const GV *const gv = CvGV(cv);
985+
if (gv) {
986+
const char *const gvname = GvNAME(gv);
987+
const HV *const stash = GvSTASH(gv);
988+
const char *const hvname = stash ? HvNAME(stash) : NULL;
989+
if (hvname)
990+
Perl_croak_nocontext("%s::%s(): unimplemented in this platform",
991+
hvname, gvname);
992+
else {
993+
pv1 = gvname;
994+
goto one_str;
995+
}
996+
} else {
997+
my_sprintf(buf, sizeof(buf), "CODE(0x%" UVxf ")", PTR2UV(cv));
998+
pv1 = buf;
999+
1000+
one_str:
1001+
Perl_croak_nocontext(
1002+
"%s::%s(): unimplemented in this platform" + (sizeof("%s::")-1),
1003+
pv1);
1004+
}
1005+
}
1006+
#define croak_xs_unimplemented S_croak_xs_unimplemented
1007+
9751008
MODULE = Time::HiRes PACKAGE = Time::HiRes
9761009

9771010
PROTOTYPES: ENABLE
@@ -990,7 +1023,8 @@ BOOT:
9901023
/* from MSDN: >= WinXP, function will always succeed and never return zero */
9911024
unsigned __int64 l_tick_frequency_mem;
9921025
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&l_tick_frequency_mem))
993-
croak("%s(): unimplemented in this platform", "QueryPerformanceFrequency");
1026+
croak("%s::%s(): unimplemented in this platform" + (sizeof("%s::")-1),
1027+
"QueryPerformanceFrequency");
9941028
l_tick_frequency = l_tick_frequency_mem;
9951029
/* 32-bit CPU anti-sharding paranoia */
9961030
S_InterlockedExchange64(&tick_frequency, l_tick_frequency);
@@ -1097,7 +1131,7 @@ nanosleep(nsec)
10971131
NV_DIE nsec
10981132
CODE:
10991133
PERL_UNUSED_ARG(nsec);
1100-
croak("%s(): unimplemented in this platform", "Time::HiRes::nanosleep");
1134+
croak_xs_unimplemented(cv);
11011135
RETVAL = 0.0;
11021136
OUTPUT:
11031137
RETVAL
@@ -1154,7 +1188,7 @@ usleep(useconds)
11541188
NV_DIE useconds
11551189
CODE:
11561190
PERL_UNUSED_ARG(useconds);
1157-
croak("%s(): unimplemented in this platform", "Time::HiRes::usleep");
1191+
croak_xs_unimplemented(cv);
11581192
RETVAL = 0.0;
11591193
OUTPUT:
11601194
RETVAL
@@ -1254,7 +1288,7 @@ ualarm(useconds,interval=0)
12541288
CODE:
12551289
PERL_UNUSED_ARG(useconds);
12561290
PERL_UNUSED_ARG(interval);
1257-
croak("%s(): unimplemented in this platform", "Time::HiRes::ualarm");
1291+
croak_xs_unimplemented(cv);
12581292
RETVAL = -1;
12591293
OUTPUT:
12601294
RETVAL
@@ -1266,7 +1300,7 @@ alarm(seconds,interval=0)
12661300
CODE:
12671301
PERL_UNUSED_ARG(seconds);
12681302
PERL_UNUSED_ARG(interval);
1269-
croak("%s(): unimplemented in this platform", "Time::HiRes::alarm");
1303+
croak_xs_unimplemented(cv);
12701304
RETVAL = 0.0;
12711305
OUTPUT:
12721306
RETVAL
@@ -1459,7 +1493,7 @@ PROTOTYPE: $$@
14591493
I32_DIE
14601494
utime(accessed, modified, ...)
14611495
CODE:
1462-
croak("%s(): unimplemented in this platform", "Time::HiRes::utime");
1496+
croak_xs_unimplemented(cv);
14631497
RETVAL = 0;
14641498
OUTPUT:
14651499
RETVAL
@@ -1492,7 +1526,7 @@ clock_gettime(clock_id = 0)
14921526
clockid_t die_t clock_id
14931527
CODE:
14941528
PERL_UNUSED_ARG(clock_id);
1495-
croak("%s(): unimplemented in this platform", "Time::HiRes::clock_gettime");
1529+
croak_xs_unimplemented(cv);
14961530
RETVAL = 0.0;
14971531
OUTPUT:
14981532
RETVAL
@@ -1525,7 +1559,7 @@ clock_getres(clock_id = 0)
15251559
clockid_t die_t clock_id
15261560
CODE:
15271561
PERL_UNUSED_ARG(clock_id);
1528-
croak("%s(): unimplemented in this platform", "Time::HiRes::clock_getres");
1562+
croak_xs_unimplemented(cv);
15291563
RETVAL = 0.0;
15301564
OUTPUT:
15311565
RETVAL
@@ -1566,7 +1600,7 @@ clock_nanosleep(clock_id, nsec, flags = 0)
15661600
PERL_UNUSED_ARG(clock_id);
15671601
PERL_UNUSED_ARG(nsec);
15681602
PERL_UNUSED_ARG(flags);
1569-
croak("%s(): unimplemented in this platform", "Time::HiRes::clock_nanosleep");
1603+
croak_xs_unimplemented(cv);
15701604
RETVAL = 0.0;
15711605
OUTPUT:
15721606
RETVAL
@@ -1591,7 +1625,7 @@ clock()
15911625
NV_DIE
15921626
clock()
15931627
CODE:
1594-
croak("%s(): unimplemented in this platform", "Time::HiRes::clock");
1628+
croak_xs_unimplemented(cv);
15951629
RETVAL = 0.0;
15961630
OUTPUT:
15971631
RETVAL

0 commit comments

Comments
 (0)