perl_type_tools.h

filter: Statementstmt 81.8% 27 / 33 Branchbran 65.3% 17 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.5% 44 / 59 SCAR 0
CC
0
Cov
0%
CRAP 0
« mh_histogram.c ↑ Summary XS/Axis.xs »
1 #ifndef perl_type_tools_h_
2 #define perl_type_tools_h_
3  
4 #include "mh_axis.h"
5  
6 #define DEREF_RV_TO_AV(av, sv) \
7 STMT_START { \
8 SvGETMAGIC(sv); \
9 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) \
10 av = (AV*)SvRV(sv); \
11 else \
12 av = NULL; \
13 } STMT_END
14  
15 #define HV_FETCHS_FATAL(svptr, hv, key) \
16 STMT_START { \
17 svptr = hv_fetchs(hv, key, 0); \
18 if (svptr == NULL) \
19 croak("Failed to get key '%s' from hash", key); \
20 } STMT_END
21  
22 STATIC void
23 522 av_to_double_ary(pTHX_ AV *in, double *out)
24 {
25 I32 thisN;
26 SV** elem;
27 I32 i;
28  
29 522 thisN = av_len(in)+1;
30 522 ▶ if (thisN == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (thisN == 0) 522 0 522
31 return;
32  
33 2106 ▶ for (i = 0; i < thisN; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < thisN; ++i) { 1584 522 2106
34 1584 ▶ if (NULL == (elem = av_fetch(in, i, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == (elem = av_fetch(in, i, 0))) 0 1584 1584
35 0 croak("Could not fetch element %i from array", i);
36 1584 ▶ else if (SvROK(*elem)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(*elem)) { 0 1584 1584
37 0 croak("Element %i in array is a reference! (Expected number)", i);
38 }
39 else {
40 1584 out[i] = SvNV(*elem);
41 }
42 }
43 }
44  
45  
46 STATIC void
47 1622 av_to_unsigned_int_ary(pTHX_ AV *in, unsigned int *out)
48 {
49 I32 thisN;
50 SV** elem;
51 I32 i;
52  
53 1622 thisN = av_len(in)+1;
54 1622 ▶ if (thisN == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (thisN == 0) 1622 0 1622
55 return;
56  
57 6440 ▶ for (i = 0; i < thisN; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < thisN; ++i) { 4818 1622 6440
58 4818 ▶ if (NULL == (elem = av_fetch(in, i, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == (elem = av_fetch(in, i, 0))) 0 4818 4818
59 0 croak("Could not fetch element from array");
60 else
61 4818 out[i] = SvUV(*elem);
62 }
63 }
64  
65  
66 STATIC void
67 24 unsigned_int_ary_to_av(pTHX_ unsigned int n, unsigned int *in, AV **out)
68 {
69 unsigned int i;
70 24 *out = newAV();
71 24 av_fill(*out, n-1);
72 96 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 72 24 96
73 72 av_store(*out, i, newSVuv(in[i]));
74 }
75 24 }
76  
77  
78 STATIC void
79 double_ary_to_av(pTHX_ unsigned int n, double *in, AV **out)
80 {
81 unsigned int i;
82 *out = newAV();
83 av_fill(*out, n-1);
84 for (i = 0; i < n; ++i) {
85 av_store(*out, i, newSVnv(in[i]));
86 }
87 }
88  
89  
90 STATIC mh_axis_t **
91 10 av_to_axis_ary(pTHX_ AV *in, I32 n)
92 {
93 SV **elem;
94 SV *sv;
95 I32 i;
96 mh_axis_t **out;
97  
98 10 ▶ if (n == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) 10 0 10
99 return NULL;
100  
101 10 out = (mh_axis_t **)malloc(sizeof(mh_axis_t *) * n);
102  
103 33 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 23 10 33
104 23 ▶ if (NULL == (elem = av_fetch(in, i, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == (elem = av_fetch(in, i, 0))) 0 23 23
105 0 croak("Could not fetch element from array");
106 else {
107 /* inlined typemap... */
108 23 sv = *elem;
109 23 ▶ if( sv_isobject(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG) )
Branch: 2 branches
BranchTrueFalseTotal
if( sv_isobject(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG) ) 23 0 23
if( sv_isobject(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG) ) 23 0 23
110 23 out[i] = (mh_axis_t *)SvIV((SV*)SvRV( sv ));
111 else {
112 0 free(out);
113 0 croak("Element with index %u of input array reference is not a Math::Histogram::Axis object!", i);
114 }
115 }
116 }
117  
118 return out;
119 }
120  
121  
122 #endif
« mh_histogram.c ↑ Summary XS/Axis.xs »