xs/record_opaque.c

filter: Statementstmt 89.5% 60 / 67 Branchbran 77.5% 45 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 84.0% 105 / 125 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/record_string.c ↑ Summary xs/custom.c »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "ppport.h"
5 #include "ffi_platypus.h"
6 #include "ffi_platypus_guts.h"
7  
8 16 XS(ffi_pl_record_accessor_opaque)
9 {
10 ffi_pl_record_member *member;
11 SV *self;
12 SV *arg;
13 char *ptr1;
14 void **ptr2;
15  
16 16 dVAR; dXSARGS;
17  
18 16 ▶ if(items == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(items == 0) 0 16 16
19 0 croak("This is a method, you must provide at least the object");
20  
21 16 member = (ffi_pl_record_member*) CvXSUBANY(cv).any_ptr;
22  
23 16 self = ST(0);
24 16 ▶ if(SvROK(self))
Branch: 1 branch
BranchTrueFalseTotal
if(SvROK(self)) 16 0 16
25 16 self = SvRV(self);
26  
27 16 ▶ if(!SvOK(self))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvOK(self)) 0 16 16
28 0 croak("Null record error");
29  
30 16 ptr1 = (char*) SvPV_nolen(self);
31 16 ptr2 = (void**) &ptr1[member->offset];
32  
33 16 ▶ if(items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if(items > 1) 6 10 16
34 {
35 6 ▶ if(SvREADONLY(self))
Branch: 1 branch
BranchTrueFalseTotal
if(SvREADONLY(self)) 2 4 6
36 {
37 2 croak("record is read-only");
38 }
39 else
40 {
41 4 arg = ST(1);
42 4 ▶ *ptr2 = SvOK(arg) ? INT2PTR(void*, SvIV(arg)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
*ptr2 = SvOK(arg) ? INT2PTR(void*, SvIV(arg)) : NULL; 3 1 4
43 }
44 }
45  
46 14 ▶ if(GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_VOID) 4 10 14
47 4 XSRETURN_EMPTY;
48  
49 10 ▶ if(*ptr2 != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(*ptr2 != NULL) 9 1 10
50 9 XSRETURN_IV( PTR2IV( *ptr2 ));
51 else
52 1 XSRETURN_EMPTY;
53 }
54  
55 27 XS(ffi_pl_record_accessor_opaque_array)
56 {
57 ffi_pl_record_member *member;
58 SV *self;
59 SV *arg;
60 SV **item;
61 AV *av;
62 char *ptr1;
63 void **ptr2;
64 int i;
65  
66 27 dVAR; dXSARGS;
67  
68 27 ▶ if(items == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(items == 0) 0 27 27
69 0 croak("This is a method, you must provide at least the object");
70  
71 27 member = (ffi_pl_record_member*) CvXSUBANY(cv).any_ptr;
72  
73 27 self = ST(0);
74 27 ▶ if(SvROK(self))
Branch: 1 branch
BranchTrueFalseTotal
if(SvROK(self)) 27 0 27
75 27 self = SvRV(self);
76  
77 27 ▶ if(!SvOK(self))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvOK(self)) 0 27 27
78 0 croak("Null record error");
79  
80 27 ptr1 = (char*) SvPV_nolen(self);
81 27 ptr2 = (void**) &ptr1[member->offset];
82  
83 27 ▶ if(items > 1 && SvREADONLY(self))
Branch: 2 branches
BranchTrueFalseTotal
if(items > 1 && SvREADONLY(self)) 12 15 27
if(items > 1 && SvREADONLY(self)) 4 8 12
84 {
85 4 croak("record is read-only");
86 }
87  
88 23 ▶ if(items > 2)
Branch: 1 branch
BranchTrueFalseTotal
if(items > 2) 2 21 23
89 {
90 2 i = SvIV(ST(1));
91 2 ▶ if(i >= 0 && i < member->count)
Branch: 2 branches
BranchTrueFalseTotal
if(i >= 0 && i < member->count) 2 0 2
if(i >= 0 && i < member->count) 2 0 2
92 {
93 2 arg = ST(2);
94 2 ▶ ptr2[i] = SvOK(arg) ? INT2PTR(void*, SvIV(arg)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ptr2[i] = SvOK(arg) ? INT2PTR(void*, SvIV(arg)) : NULL; 1 1 2
95 }
96 else
97 {
98 0 warn("illegal index %d", i);
99 }
100 }
101 21 ▶ else if(items > 1)
Branch: 1 branch
BranchTrueFalseTotal
else if(items > 1) 6 15 21
102 {
103 6 arg = ST(1);
104 6 ▶ if(SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if(SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) 3 3 6
if(SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) 3 0 3
105 {
106 3 av = (AV*) SvRV(arg);
107 10 ▶ for(i=0; i < member->count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < member->count; i++) 7 3 10
108 {
109 7 item = av_fetch(av, i, 0);
110 7 ▶ if(item != NULL && SvOK(*item))
Branch: 2 branches
BranchTrueFalseTotal
if(item != NULL && SvOK(*item)) 7 0 7
if(item != NULL && SvOK(*item)) 6 1 7
111 {
112 6 ptr2[i] = INT2PTR(void*, SvIV(*item));
113 }
114 else
115 {
116 1 ptr2[i] = NULL;
117 }
118 }
119 }
120 else
121 {
122 3 i = SvIV(ST(1));
123 3 ▶ if(i < 0 && i >= member->count)
Branch: 2 branches
BranchTrueFalseTotal
if(i < 0 && i >= member->count) 0 3 3
if(i < 0 && i >= member->count) 0 0 0
124 {
125 0 warn("illegal index %d", i);
126 0 XSRETURN_EMPTY;
127 }
128 3 ▶ else if(ptr2[i] == NULL)
Branch: 1 branch
BranchTrueFalseTotal
else if(ptr2[i] == NULL) 1 2 3
129 {
130 1 XSRETURN_EMPTY;
131 }
132 else
133 {
134 2 XSRETURN_IV(PTR2IV(ptr2[i]));
135 }
136 warn("passing non array reference into ffi/platypus array argument type");
137 }
138 }
139  
140 20 ▶ if(GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_VOID) 5 15 20
141 5 XSRETURN_EMPTY;
142  
143 15 av = newAV();
144 15 av_fill(av, member->count-1);
145 48 ▶ for(i=0; i < member->count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < member->count; i++) 33 15 48
146 {
147 33 ▶ if(ptr2[i] != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(ptr2[i] != NULL) 31 2 33
148 31 sv_setiv(*av_fetch(av, i, 1), PTR2IV(ptr2[i]));
149 }
150 15 ST(0) = newRV_inc((SV*)av);
151 15 XSRETURN(1);
152 }
« xs/record_string.c ↑ Summary xs/custom.c »