xs/complex.c

filter: Statementstmt 100% 90 / 90 Branchbran 76.4% 52 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.8% 142 / 158 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/names.c ↑ Summary corpus/ffi_build_plugin/lib2/FFI/Build/Plugin/Foo1.pm »
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 static double
9 84 decompose(SV *sv, int imag)
10 {
11 /* Re(z) */
12 84 dSP;
13  
14 int count;
15 84 double result = 0.0;
16  
17 84 ENTER;
18 84 SAVETMPS;
19 84 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 84 84
20 84 ▶ XPUSHs(sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv); 0 84 84
21 84 PUTBACK;
22  
23 84 ▶ count = call_pv(imag ? "Math::Complex::Im" : "Math::Complex::Re", G_ARRAY);
Branch: 1 branch
BranchTrueFalseTotal
count = call_pv(imag ? "Math::Complex::Im" : "Math::Complex::Re", G_ARRAY); 42 42 84
24  
25 84 SPAGAIN;
26  
27 84 ▶ if(count >= 1)
Branch: 1 branch
BranchTrueFalseTotal
if(count >= 1) 84 0 84
28 84 result = POPn;
29  
30 84 PUTBACK;
31 84 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 84 0 84
32 84 LEAVE;
33  
34 84 return result;
35 }
36  
37 static void
38 36 set(SV *sv, SV *new_value, int imag)
39 {
40 36 dSP;
41  
42 36 ENTER;
43 36 SAVETMPS;
44 36 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 36 36
45 36 ▶ XPUSHs(sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv); 0 36 36
46 36 ▶ XPUSHs(new_value);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(new_value); 0 36 36
47 36 PUTBACK;
48  
49 36 ▶ call_pv(imag ? "Math::Complex::Im" : "Math::Complex::Re", G_DISCARD);
Branch: 1 branch
BranchTrueFalseTotal
call_pv(imag ? "Math::Complex::Im" : "Math::Complex::Re", G_DISCARD); 18 18 36
50  
51 36 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 36 36
52 36 LEAVE;
53 36 }
54  
55 void
56 111 ffi_pl_perl_to_complex_float(SV *sv, float *ptr)
57 {
58 111 ▶ if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex"))
Branch: 2 branches
BranchTrueFalseTotal
if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 21 90 111
if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 21 0 21
59 {
60 21 ptr[0] = decompose(sv, 0);
61 21 ptr[1] = decompose(sv, 1);
62 }
63 90 ▶ else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 69 21 90
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 69 0 69
64 69 {
65 69 AV *av = (AV*) SvRV(sv);
66 SV **real_sv, **imag_sv;
67 69 real_sv = av_fetch(av, 0, 0);
68 69 imag_sv = av_fetch(av, 1, 0);
69 69 ▶ ptr[0] = real_sv != NULL ? SvNV(*real_sv) : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
ptr[0] = real_sv != NULL ? SvNV(*real_sv) : 0.0; 66 3 69
70 69 ▶ ptr[1]= imag_sv != NULL ? SvNV(*imag_sv) : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
ptr[1]= imag_sv != NULL ? SvNV(*imag_sv) : 0.0; 66 3 69
71 }
72 21 ▶ else if(SvOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
else if(SvOK(sv)) 18 3 21
73 {
74 18 ptr[0] = SvNV(sv);
75 18 ptr[1] = 0.0;
76 }
77 else
78 {
79 3 ptr[0] = 0.0;
80 3 ptr[1] = 0.0;
81 }
82 111 }
83  
84 void
85 69 ffi_pl_complex_float_to_perl(SV *sv, float *ptr)
86 {
87 69 ▶ if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex"))
Branch: 3 branches
BranchTrueFalseTotal
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 66 3 69
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 9 57 66
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 9 0 9
88 {
89 /* the complex variable is a Math::Complex object */
90 9 set(sv, sv_2mortal(newSVnv(ptr[0])), 0);
91 9 set(sv, sv_2mortal(newSVnv(ptr[1])), 1);
92 }
93 60 ▶ else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 57 3 60
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 57 0 57
94 57 {
95 /* the compex variable is already an array */
96 57 AV *av = (AV*) SvRV(sv);
97 57 av_store(av, 0, newSVnv(ptr[0]));
98 57 av_store(av, 1, newSVnv(ptr[1]));
99 }
100 else
101 {
102 /* the complex variable is something else and an array needs to be created */
103 SV *values[2];
104 AV *av;
105 3 values[0] = newSVnv(ptr[0]);
106 3 values[1] = newSVnv(ptr[1]);
107 3 av = av_make(2, values);
108 3 sv_setsv(sv, newRV_noinc((SV*)av));
109 }
110 69 }
111  
112 void
113 111 ffi_pl_perl_to_complex_double(SV *sv, double *ptr)
114 {
115 111 ▶ if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex"))
Branch: 2 branches
BranchTrueFalseTotal
if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 21 90 111
if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 21 0 21
116 {
117 21 ptr[0] = decompose(sv, 0);
118 21 ptr[1] = decompose(sv, 1);
119 }
120 90 ▶ else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 69 21 90
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 69 0 69
121 69 {
122 69 AV *av = (AV*) SvRV(sv);
123 SV **real_sv, **imag_sv;
124 69 real_sv = av_fetch(av, 0, 0);
125 69 imag_sv = av_fetch(av, 1, 0);
126 69 ▶ ptr[0] = real_sv != NULL ? SvNV(*real_sv) : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
ptr[0] = real_sv != NULL ? SvNV(*real_sv) : 0.0; 66 3 69
127 69 ▶ ptr[1]= imag_sv != NULL ? SvNV(*imag_sv) : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
ptr[1]= imag_sv != NULL ? SvNV(*imag_sv) : 0.0; 66 3 69
128 }
129 21 ▶ else if(SvOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
else if(SvOK(sv)) 18 3 21
130 {
131 18 ptr[0] = SvNV(sv);
132 18 ptr[1] = 0.0;
133 }
134 else
135 {
136 3 ptr[0] = 0.0;
137 3 ptr[1] = 0.0;
138 }
139 111 }
140  
141 void
142 69 ffi_pl_complex_double_to_perl(SV *sv, double *ptr)
143 {
144 69 ▶ if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex"))
Branch: 3 branches
BranchTrueFalseTotal
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 66 3 69
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 9 57 66
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "Math::Complex")) 9 0 9
145 {
146 /* the complex variable is a Math::Complex object */
147 9 set(sv, sv_2mortal(newSVnv(ptr[0])), 0);
148 9 set(sv, sv_2mortal(newSVnv(ptr[1])), 1);
149 }
150 60 ▶ else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 57 3 60
else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) 57 0 57
151 57 {
152 /* the compex variable is already an array */
153 57 AV *av = (AV*) SvRV(sv);
154 57 av_store(av, 0, newSVnv(ptr[0]));
155 57 av_store(av, 1, newSVnv(ptr[1]));
156 }
157 else
158 {
159 /* the complex variable is something else and an array needs to be created */
160 SV *values[2];
161 AV *av;
162 3 values[0] = newSVnv(ptr[0]);
163 3 values[1] = newSVnv(ptr[1]);
164 3 av = av_make(2, values);
165 3 sv_setsv(sv, newRV_noinc((SV*)av));
166 }
167 69 }
168  
« xs/names.c ↑ Summary corpus/ffi_build_plugin/lib2/FFI/Build/Plugin/Foo1.pm »