include/tkr/tkr_abi_in.h

filter: Statementstmt 97.4% 38 / 39 Branchbran 80.7% 21 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.7% 59 / 65 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/tkr/tkr_obj.h ↑ Summary include/tkr/tkr_civil.h »
1 #ifndef TKR_ABI_IN_H
2 #define TKR_ABI_IN_H
3  
4 /* The two tables this dist is built on: Time::Keeper's (values, zones by
5 * name, wall clocks) and Time::Keeper::Zone's (the transitions and both
6 * readings of a wall time). Time::Keeper's is resolved when the module
7 * loads, since every rule makes Time::Keeper values; Zone's the first time
8 * a named zone is seen, as the core does, so a program whose rules stay in
9 * UTC never loads the zone data.
10 *
11 * Neither has anything to degrade to, so each of the three ways of not
12 * getting a table croaks and says which it was: the module could not be
13 * loaded (with perl's reason), it loaded but gave no table, or its table is
14 * older than the version this dist calls into.
15 *
16 * Both tables are const data in their shared objects, the same for every
17 * interpreter, so one pointer each serves them all. Calls are written
18 * (T->entry)(aTHX_ ...): the parentheses keep a member's name from being
19 * read as a function-like macro on a perl built with PERL_IMPLICIT_SYS. */
20  
21 #define TKR_TK_NEEDS 2 /* time_keeper_abi.h: cal_fields and new_sv_cal are version 2's */
22 #define TKR_TKZ_NEEDS 2 /* time_keeper_zone_abi.h: resolve_local_all is version 2's */
23  
24 static const time_keeper_abi *tkr_tk_table = NULL;
25 static const tkz_abi *tkr_tkz_table = NULL;
26  
27 /* The address a module's _abi_ptr gives, or 0, with the load error in *msg
28 * (a mortal) when it would not load. The caller's $@ is left as it was. */
29 static UV
30 36 tkr_abi_ptr_of(pTHX_ const char *code, SV **msg)
31 {
32 SV *sv, *err;
33 36 UV ptr = 0;
34 36 *msg = NULL;
35 36 ENTER;
36 36 save_scalar(PL_errgv);
37 36 sv = eval_pv(code, 0);
38 36 ▶ err = ERRSV;
Branch: 1 branch
BranchTrueFalseTotal
err = ERRSV; 36 0 36
39 36 ▶ if (err && SvTRUE(err))
Branch: 2 branches
BranchTrueFalseTotal
if (err && SvTRUE(err)) 36 0 36
if (err && SvTRUE(err)) 1 35 36
40 1 *msg = sv_2mortal(newSVsv(err));
41 35 ▶ else if (sv && SvOK(sv))
Branch: 2 branches
BranchTrueFalseTotal
else if (sv && SvOK(sv)) 35 0 35
else if (sv && SvOK(sv)) 35 0 35
42 35 ptr = SvUV(sv);
43 36 LEAVE;
44 36 return ptr;
45 }
46  
47 static const time_keeper_abi *
48 14962780 tkr_tk(pTHX)
49 {
50 SV *msg;
51 UV ptr;
52 const time_keeper_abi *t;
53 14962780 ▶ if (tkr_tk_table)
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_tk_table) 14962760 20 14962780
54 14962760 return tkr_tk_table;
55 20 ptr = tkr_abi_ptr_of(aTHX_ "require Time::Keeper; Time::Keeper::_abi_ptr()", &msg);
56 20 ▶ if (msg)
Branch: 1 branch
BranchTrueFalseTotal
if (msg) 0 20 20
57 0 croak("Time::Keeper::Recurrence needs Time::Keeper 0.05 or later, with its C ABI at version %d or later, "
58 "and could not load it: %" SVf, TKR_TK_NEEDS, SVfARG(msg));
59 20 ▶ if (!ptr)
Branch: 1 branch
BranchTrueFalseTotal
if (!ptr) 1 19 20
60 1 croak("Time::Keeper::Recurrence needs Time::Keeper 0.05 or later, with its C ABI at version %d or later: "
61 "the Time::Keeper that loaded has no C ABI table", TKR_TK_NEEDS);
62 19 t = INT2PTR(const time_keeper_abi *, ptr);
63 19 ▶ if (t->abi_version < TKR_TK_NEEDS)
Branch: 1 branch
BranchTrueFalseTotal
if (t->abi_version < TKR_TK_NEEDS) 1 18 19
64 1 croak("Time::Keeper::Recurrence needs Time::Keeper with its C ABI at version %d or later: "
65 "the Time::Keeper that loaded has version %d", TKR_TK_NEEDS, t->abi_version);
66 18 tkr_tk_table = t;
67 18 return t;
68 }
69  
70 static const tkz_abi *
71 10279729 tkr_tkz(pTHX)
72 {
73 SV *msg;
74 UV ptr;
75 const tkz_abi *t;
76 10279729 ▶ if (tkr_tkz_table)
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_tkz_table) 10279713 16 10279729
77 10279713 return tkr_tkz_table;
78 16 ptr = tkr_abi_ptr_of(aTHX_ "require Time::Keeper::Zone; Time::Keeper::Zone::_abi_ptr()", &msg);
79 16 ▶ if (msg)
Branch: 1 branch
BranchTrueFalseTotal
if (msg) 1 15 16
80 1 croak("Time::Keeper::Recurrence needs Time::Keeper::Zone 0.04 or later, with its C ABI at version %d or later, "
81 "and could not load it: %" SVf, TKR_TKZ_NEEDS, SVfARG(msg));
82 15 ▶ if (!ptr)
Branch: 1 branch
BranchTrueFalseTotal
if (!ptr) 1 14 15
83 1 croak("Time::Keeper::Recurrence needs Time::Keeper::Zone 0.04 or later, with its C ABI at version %d or later: "
84 "the Time::Keeper::Zone that loaded has no C ABI table", TKR_TKZ_NEEDS);
85 14 t = INT2PTR(const tkz_abi *, ptr);
86 14 ▶ if (t->abi_version < TKR_TKZ_NEEDS)
Branch: 1 branch
BranchTrueFalseTotal
if (t->abi_version < TKR_TKZ_NEEDS) 1 13 14
87 1 croak("Time::Keeper::Recurrence needs Time::Keeper::Zone with its C ABI at version %d or later: "
88 "the Time::Keeper::Zone that loaded has version %d", TKR_TKZ_NEEDS, t->abi_version);
89 13 tkr_tkz_table = t;
90 13 return t;
91 }
92  
93 #endif
« include/tkr/tkr_obj.h ↑ Summary include/tkr/tkr_civil.h »