src/xs/Sv.cc

filter: Statementstmt 97.6% 42 / 43 Branchbran 50.0% 17 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.6% 59 / 77 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« t/svapi/scope.cc ↑ Summary t/typemap/svapi.xsi »
1 #include "Sv.h"
2 #include "Sub.h"
3 #include "Simple.h"
4 #include <ostream>
5  
6 namespace xs {
7  
8 static Sv::payload_marker_t _default_marker;
9 49 Sv::payload_marker_t* Sv::default_marker() { return &_default_marker; }
10  
11 const Sv Sv::undef(&PL_sv_undef);
12 const Sv Sv::yes(&PL_sv_yes);
13 const Sv Sv::no(&PL_sv_no);
14  
15 63 MAGIC* Sv::payload_attach (void* ptr, SV* obj, const payload_marker_t* marker) {
16 63 upgrade(SVt_PVMG);
17 MAGIC* mg;
18 63 Newx(mg, 1, MAGIC);
19 63 mg->mg_moremagic = SvMAGIC(sv);
20 63 SvMAGIC_set(sv, mg);
21 63 mg->mg_virtual = const_cast<payload_marker_t*>(marker);
22 63 mg->mg_type = PERL_MAGIC_ext;
23 63 mg->mg_len = 0;
24 63 mg->mg_ptr = (char*)ptr;
25 63 mg->mg_private = 0;
26  
27 63 ▶ if (obj) {
Branch: 1 branch
BranchTrueFalseTotal
if (obj) { 8 55 63
28 8 mg->mg_obj = SvREFCNT_inc_simple_NN(obj);
29 8 mg->mg_flags = MGf_REFCOUNTED;
30 } else {
31 55 mg->mg_obj = NULL;
32 55 mg->mg_flags = 0;
33 }
34  
35 #ifdef USE_ITHREADS
36 if (marker->svt_dup) mg->mg_flags |= MGf_DUP;
37 #endif
38  
39 63 return mg;
40 }
41  
42 37 void Sv::__at_perl_destroy () {
43 37 const_cast<Sv*>(&undef)->reset();
44 37 const_cast<Sv*>(&yes)->reset();
45 37 const_cast<Sv*>(&no)->reset();
46 37 }
47  
48 1344 std::ostream& operator<< (std::ostream& os, const Sv& sv) {
49 1344 SV* v = sv;
50 1344 ▶ if (!v) return os << (void*)nullptr;
Branch: 1 branch
BranchTrueFalseTotal
if (!v) return os << (void*)nullptr; 27 1317 1344
51 1317 switch (sv.type()) {
52 76 ▶ case SVt_NULL: return os << "<undef>";
Branch: 1 branch
BranchTrueFalseTotal
case SVt_NULL: return os << "<undef>"; 76 0 76
53 133 ▶ case SVt_PVAV: return os << "array(" << (void*)v << ')';
Branch: 3 branches
BranchTrueFalseTotal
case SVt_PVAV: return os << "array(" << (void*)v << ')'; 133 0 133
case SVt_PVAV: return os << "array(" << (void*)v << ')'; 133 0 133
case SVt_PVAV: return os << "array(" << (void*)v << ')'; 133 0 133
54 223 ▶ case SVt_PVHV: return os << "hash(" << (void*)v << ')';
Branch: 3 branches
BranchTrueFalseTotal
case SVt_PVHV: return os << "hash(" << (void*)v << ')'; 223 0 223
case SVt_PVHV: return os << "hash(" << (void*)v << ')'; 223 0 223
case SVt_PVHV: return os << "hash(" << (void*)v << ')'; 223 0 223
55 0 ▶ case SVt_PVFM: return os << "format(" << (void*)v << ')';
Branch: 3 branches
BranchTrueFalseTotal
case SVt_PVFM: return os << "format(" << (void*)v << ')'; 0 0 0
case SVt_PVFM: return os << "format(" << (void*)v << ')'; 0 0 0
case SVt_PVFM: return os << "format(" << (void*)v << ')'; 0 0 0
56 885 default:
57 STRLEN len;
58 885 auto s = SvPV(v, len);
59 885 ▶ return os.write(s, len);
Branch: 1 branch
BranchTrueFalseTotal
return os.write(s, len); 885 0 885
60 }
61 }
62  
63 235 Sv eval (const panda::string& code) {
64 235 Sv ret = eval_pv(code.c_str(), 0);
65  
66 235 auto errsv = GvSV(PL_errgv);
67 235 ▶ if (SvTRUE(errsv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(errsv)) { 235 0 235
if (SvTRUE(errsv)) { 1 234 235
68 1 auto exc = Sv::noinc(errsv);
69 1 ▶ GvSV(PL_errgv) = newSVpvs("");
Branch: 1 branch
BranchTrueFalseTotal
GvSV(PL_errgv) = newSVpvs(""); 1 0 1
70 1 ▶ throw PerlRuntimeException(exc);
Branch: 1 branch
BranchTrueFalseTotal
throw PerlRuntimeException(exc); 1 0 1
71 1 }
72  
73 234 return ret;
74 1 }
75  
76 }
« t/svapi/scope.cc ↑ Summary t/typemap/svapi.xsi »