ulib/util.c

filter: Statementstmt 73.8% 79 / 107 Branchbran 43.1% 19 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 64.9% 98 / 151 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« ulib/node.c ↑ Summary ulib/clock.c »
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4  
5 #include "ulib/util.h"
6  
7 #ifdef __cplusplus
8 }
9 #endif
10  
11 /******************************************************************************
12 * all for croak_caller before 5.13.4.
13 */
14 #define PERL_ARGS_ASSERT_DOPOPTOSUB_AT assert(cxstk)
15  
16 #ifdef PERL_GLOBAL_STRUCT
17 # define dVAR pVAR = (struct perl_vars*)PERL_GET_VARS()
18 #else
19 # define dVAR dNOOP
20 #endif
21  
22 #ifndef dopoptosub
23 #define dopoptosub(plop) dopoptosub_at(cxstack, (plop))
24 #endif
25  
26 #ifndef dopoptosub_at
27 #if !defined(PERL_IMPLICIT_CONTEXT)
28 # define dopoptosub_at my_dopoptosub_at
29 #else
30 # define dopoptosub_at(a,b) my_dopoptosub_at(aTHX_ a,b)
31 #endif
32 #endif
33  
34 STATIC I32
35 2 my_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock)
36 {
37 dVAR;
38 I32 i;
39  
40 PERL_ARGS_ASSERT_DOPOPTOSUB_AT;
41  
42 5 ▶ for (i = startingblock; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = startingblock; i >= 0; i--) { 5 0 5
43 5 register const PERL_CONTEXT * const cx = &cxstk[i];
44 5 ▶ switch (CxTYPE(cx)) {
Branch: 1 branch
BranchTrueFalseTotal
switch (CxTYPE(cx)) { 3 2 5
45 3 default:
46 3 continue;
47 2 case CXt_EVAL:
48 case CXt_SUB:
49 case CXt_FORMAT:
50 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
51 2 return i;
52 }
53 }
54 0 return i;
55 }
56  
57 const PERL_CONTEXT *
58 1 my_caller_cx(pTHX_ I32 count, const PERL_CONTEXT **dbcxp)
59 {
60 1 register I32 cxix = dopoptosub(cxstack_ix);
61 register const PERL_CONTEXT *cx;
62 1 register const PERL_CONTEXT *ccstack = cxstack;
63 1 const PERL_SI *top_si = PL_curstackinfo;
64  
65 for (;;) {
66 /* we may be in a higher stacklevel, so dig down deeper */
67 1 ▶ while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
Branch: 2 branches
BranchTrueFalseTotal
while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 0 1 1
while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 0 0 0
68 0 top_si = top_si->si_prev;
69 0 ccstack = top_si->si_cxstack;
70 0 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
71 }
72 1 ▶ if (cxix < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (cxix < 0) 0 1 1
73 0 return NULL;
74 /* caller() should not report the automatic calls to &DB::sub */
75 1 ▶ if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
Branch: 3 branches
BranchTrueFalseTotal
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && 1 0 1
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && 0 1 1
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && 0 0 0
76 0 ▶ ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
Branch: 1 branch
BranchTrueFalseTotal
ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 0 0 0
77 0 count++;
78 1 ▶ if (!count--)
Branch: 1 branch
BranchTrueFalseTotal
if (!count--) 1 0 1
79 1 break;
80 0 cxix = dopoptosub_at(ccstack, cxix - 1);
81 }
82  
83 1 cx = &ccstack[cxix];
84 1 ▶ if (dbcxp) *dbcxp = cx;
Branch: 1 branch
BranchTrueFalseTotal
if (dbcxp) *dbcxp = cx; 0 1 1
85  
86 1 ▶ if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
Branch: 2 branches
BranchTrueFalseTotal
if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { 0 1 1
if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { 0 0 0
87 1 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
88 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
89 field below is defined for any cx. */
90 /* caller() should not report the automatic calls to &DB::sub */
91 1 ▶ if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
Branch: 4 branches
BranchTrueFalseTotal
if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) 1 0 1
if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) 0 1 1
if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) 0 0 0
if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) 0 0 0
92 0 cx = &ccstack[dbcxix];
93 }
94  
95 1 return cx;
96 }
97  
98 1 void my_croak_caller(const char *pat, ...) {
99 dTHX;
100 va_list args;
101 1 const PERL_CONTEXT *cx = my_caller_cx(aTHX_ 0, NULL);
102  
103 /* make error appear at call site */
104 assert(cx);
105 1 PL_curcop = cx->blk_oldcop;
106  
107 1 va_start(args, pat);
108 1 vcroak(pat, &args);
109 NOT_REACHED; /* NOTREACHED */
110 va_end(args);
111 }
112  
113 /******************************************************************************/
114  
115 6 void uu_clear(struct_uu_t *io) {
116 6 io->v1.time_low = 0;
117 6 io->v1.time_mid = 0;
118 6 io->v1.time_high_and_version = 0;
119 6 io->v1.clock_seq_and_variant = 0;
120 6 io->v1.node[0] = 0;
121 6 io->v1.node[1] = 0;
122 6 io->v1.node[2] = 0;
123 6 io->v1.node[3] = 0;
124 6 io->v1.node[4] = 0;
125 6 io->v1.node[5] = 0;
126 6 }
127  
128 0 void uu_copy_binary(pUCXT, const uu_t in, uu_t out) {
129 /* XXX use Copy */
130 0 U8 *cp1 = (U8*)&in;
131 0 U8 *cp2 = out;
132 UV i;
133  
134 0 ▶ for (i=0; i < 16; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < 16; i++) 0 0 0
135 0 *cp1++ = *cp2++;
136 0 }
137  
138 0 void uu_copy_struct(pUCXT, const struct_uu_t *in, struct_uu_t *out) {
139 /* XXX use Copy */
140 0 out->v1.time_low = in->v1.time_low;
141 0 out->v1.time_mid = in->v1.time_mid;
142 0 out->v1.time_high_and_version = in->v1.time_high_and_version;
143 0 out->v1.clock_seq_and_variant = in->v1.clock_seq_and_variant;
144 0 out->v1.node[0] = in->v1.node[0];
145 0 out->v1.node[1] = in->v1.node[1];
146 0 out->v1.node[2] = in->v1.node[2];
147 0 out->v1.node[3] = in->v1.node[3];
148 0 out->v1.node[4] = in->v1.node[4];
149 0 out->v1.node[5] = in->v1.node[5];
150 0 }
151  
152 2 static NV uu_time_v1(const struct_uu_t *in) {
153 U64 sum;
154 NV rv;
155  
156 2 sum = ((U64)in->v1.time_high_and_version & 0x0fff) << 48
157 2 | ((U64)in->v1.time_mid) << 32
158 2 | (U64)in->v1.time_low;
159 2 sum -= 122192928000000000ULL;
160 2 rv = (NV)sum / 10000000.0;
161  
162 2 return rv;
163 }
164  
165 2 static NV uu_time_v4(const struct_uu_t *in) {
166 2 return 0.0;
167 }
168  
169 1 static NV uu_time_v6(const struct_uu_t *in) {
170 U64 sum;
171 NV rv;
172  
173 1 sum = ((U64)in->v6.time_high) << 28
174 1 | ((U64)in->v6.time_mid) << 12
175 1 | ((U64)in->v6.time_low_and_version & 0x0fff);
176 1 sum -= 122192928000000000ULL;
177 1 rv = (NV)sum / 10000000.0;
178  
179 1 return rv;
180 }
181  
182 1 static NV uu_time_v7(const struct_uu_t *in) {
183 U64 sum;
184 NV rv;
185  
186 1 sum = ((U64)in->v7.time_high) << 16
187 1 | (U64)in->v7.time_low;
188 1 rv = (NV)sum / 1000.0;
189  
190 1 return rv;
191 }
192  
193 9 NV uu_time(const struct_uu_t *in) {
194 int version;
195  
196 9 version = in->v1.time_high_and_version >> 12;
197  
198 9 switch(version) {
199 2 case 1: return uu_time_v1(in);
200 2 case 4: return uu_time_v4(in);
201 1 case 6: return uu_time_v6(in);
202 1 case 7: return uu_time_v7(in);
203 }
204 3 return 0;
205 }
206  
207 /* a.k.a. version */
208 667 UV uu_type(const struct_uu_t *in) {
209 UV type;
210  
211 667 type = in->v1.time_high_and_version >> 12;
212  
213 667 ▶ if (type <= 8)
Branch: 1 branch
BranchTrueFalseTotal
if (type <= 8) 667 0 667
214 667 return type;
215 0 return 0;
216 }
217  
218 720 UV uu_variant(const struct_uu_t *in) {
219 U16 variant;
220  
221 720 variant = in->v1.clock_seq_and_variant;
222  
223 720 ▶ if ((variant & 0x8000) == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ((variant & 0x8000) == 0) return 0; 55 665 720
224 665 ▶ if ((variant & 0x4000) == 0) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if ((variant & 0x4000) == 0) return 1; 657 8 665
225 8 ▶ if ((variant & 0x2000) == 0) return 2;
Branch: 1 branch
BranchTrueFalseTotal
if ((variant & 0x2000) == 0) return 2; 4 4 8
226 4 return 3;
227 }
228  
229 /* ex:set ts=2 sw=2 itab=spaces: */
« ulib/node.c ↑ Summary ulib/clock.c »