src/xs/typemap/object.cc

filter: Statementstmt 80.4% 37 / 46 Branchbran 46.0% 35 / 76 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 59.0% 72 / 122 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Framework_xsgen.cc ↑ Summary t/typemap/object/static_cast.xsi »
1 #include "object.h"
2 #include <cxxabi.h>
3 #include "error.h"
4  
5 namespace xs { namespace typemap { namespace object {
6  
7 using destroy_hook_t = bool(*)(pTHX_ SV*);
8  
9 CV* fake_dtor;
10 svt_copy_t backref_marker;
11  
12 static destroy_hook_t orig_destroy_hook;
13  
14 0 static int _backref_marker (pTHX_ SV*, MAGIC*, SV*, const char*, I32) { assert(0); return 0; } // should not be called
15  
16 9801834 static bool destroy_hook (pTHX_ SV* sv) {
17 9801834 MAGIC* mg = SvMAGIC(sv);
18 9808296 ▶ for (; mg; mg = mg->mg_moremagic) {
Branch: 1 branch
BranchTrueFalseTotal
for (; mg; mg = mg->mg_moremagic) { 6469 9801827 9808296
19 6469 ▶ if (mg->mg_virtual && (mg->mg_flags & MGf_COPY) && (mg->mg_virtual->svt_copy == backref_marker)) {
Branch: 3 branches
BranchTrueFalseTotal
if (mg->mg_virtual && (mg->mg_flags & MGf_COPY) && (mg->mg_virtual->svt_copy == backref_marker)) { 6469 0 6469
if (mg->mg_virtual && (mg->mg_flags & MGf_COPY) && (mg->mg_virtual->svt_copy == backref_marker)) { 307 6162 6469
if (mg->mg_virtual && (mg->mg_flags & MGf_COPY) && (mg->mg_virtual->svt_copy == backref_marker)) { 18 289 307
20 18 ▶ if ((mg->mg_flags & MGf_LOCAL) && mg->mg_virtual->svt_local(aTHX_ sv, mg)) return TRUE;
Branch: 3 branches
BranchTrueFalseTotal
if ((mg->mg_flags & MGf_LOCAL) && mg->mg_virtual->svt_local(aTHX_ sv, mg)) return TRUE; 18 0 18
if ((mg->mg_flags & MGf_LOCAL) && mg->mg_virtual->svt_local(aTHX_ sv, mg)) return TRUE; 7 11 18
if ((mg->mg_flags & MGf_LOCAL) && mg->mg_virtual->svt_local(aTHX_ sv, mg)) return TRUE; 7 11 18
21 }
22 }
23 9801827 ▶ if (orig_destroy_hook) return orig_destroy_hook(aTHX_ sv);
Branch: 1 branch
BranchTrueFalseTotal
if (orig_destroy_hook) return orig_destroy_hook(aTHX_ sv); 0 9801827 9801827
24 9801827 return TRUE;
25 }
26  
27 37 void init () {
28 37 ▶ Stash stash("XS::Framework", GV_ADD);
Branch: 1 branch
BranchTrueFalseTotal
Stash stash("XS::Framework", GV_ADD); 37 0 37
29  
30 37 ▶ fake_dtor = newCONSTSUB(stash, "__FAKE_DTOR", newSViv(0));
Branch: 2 branches
BranchTrueFalseTotal
fake_dtor = newCONSTSUB(stash, "__FAKE_DTOR", newSViv(0)); 37 0 37
fake_dtor = newCONSTSUB(stash, "__FAKE_DTOR", newSViv(0)); 37 0 37
31 37 backref_marker = &_backref_marker;
32  
33 37 ▶ if (PL_destroyhook != &Perl_sv_destroyable) orig_destroy_hook = PL_destroyhook;
Branch: 1 branch
BranchTrueFalseTotal
if (PL_destroyhook != &Perl_sv_destroyable) orig_destroy_hook = PL_destroyhook; 0 37 37
34 37 PL_destroyhook = destroy_hook; // needed for correct operation of Typemap Storage MG with Backref feature enabled
35 37 }
36  
37 24 panda::string type_details(const std::type_info& ti) {
38 int status;
39 24 panda::string r;
40 24 ▶ char* class_name = abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status);
Branch: 1 branch
BranchTrueFalseTotal
char* class_name = abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status); 24 0 24
41 24 ▶ if (status != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (status != 0) { 0 24 24
42 0 ▶ r += "[abi::__cxa_demangle error] ";
Branch: 1 branch
BranchTrueFalseTotal
r += "[abi::__cxa_demangle error] "; 0 0 0
43 0 ▶ r += ti.name();
Branch: 1 branch
BranchTrueFalseTotal
r += ti.name(); 0 0 0
44 }
45 else {
46 24 ▶ r += class_name;
Branch: 1 branch
BranchTrueFalseTotal
r += class_name; 24 0 24
47 24 free(class_name);
48 }
49 48 return r;
50 }
51  
52 0 [[ noreturn ]] void _throw_no_package (const std::type_info& ti) {
53 0 panda::string exc("no default perl class defined for typemap '");
54 0 ▶ exc += type_details(ti);
Branch: 2 branches
BranchTrueFalseTotal
exc += type_details(ti); 0 0 0
exc += type_details(ti); 0 0 0
55 0 ▶ exc += "', either define it or explicitly bless PROTO on output";
Branch: 1 branch
BranchTrueFalseTotal
exc += "', either define it or explicitly bless PROTO on output"; 0 0 0
56 0 throw panda::exception(exc);
57 }
58  
59 24 [[ noreturn ]] void _throw_incorrect_arg(SV* arg, const std::type_info& expected, panda::string_view package) {
60 //"arg is an incorrect or corrupted object";
61 24 panda::string arg_type;
62 24 ▶ if (!arg) { arg_type = "NULL"; }
Branch: 2 branches
BranchTrueFalseTotal
if (!arg) { arg_type = "NULL"; } 0 24 24
if (!arg) { arg_type = "NULL"; } 0 0 0
63 else {
64 24 Sv sv{arg};
65 24 ▶ if (!sv.is_object() && !sv.is_object_ref()) {
Branch: 3 branches
BranchTrueFalseTotal
if (!sv.is_object() && !sv.is_object_ref()) { 0 24 24
if (!sv.is_object() && !sv.is_object_ref()) { 0 0 0
if (!sv.is_object() && !sv.is_object_ref()) { 0 24 24
66 0 ▶ arg_type = "not an object";
Branch: 1 branch
BranchTrueFalseTotal
arg_type = "not an object"; 0 0 0
67 }
68 else {
69 24 ▶ Object obj(sv);
Branch: 1 branch
BranchTrueFalseTotal
Object obj(sv); 24 0 24
70 24 ▶ arg_type = obj.stash().name();
Branch: 3 branches
BranchTrueFalseTotal
arg_type = obj.stash().name(); 24 0 24
arg_type = obj.stash().name(); 24 0 24
arg_type = obj.stash().name(); 24 0 24
71 24 }
72 24 }
73 24 panda::string ex_details = "cannot convert arg '";
74 24 ▶ ex_details += arg_type;
Branch: 1 branch
BranchTrueFalseTotal
ex_details += arg_type; 24 0 24
75 24 ▶ ex_details += "' to expected '";
Branch: 1 branch
BranchTrueFalseTotal
ex_details += "' to expected '"; 24 0 24
76 24 ▶ ex_details += package;
Branch: 1 branch
BranchTrueFalseTotal
ex_details += package; 24 0 24
77 24 ▶ ex_details += "' (C++ type '" + type_details(expected) + "')";
Branch: 4 branches
BranchTrueFalseTotal
ex_details += "' (C++ type '" + type_details(expected) + "')"; 24 0 24
ex_details += "' (C++ type '" + type_details(expected) + "')"; 24 0 24
ex_details += "' (C++ type '" + type_details(expected) + "')"; 24 0 24
ex_details += "' (C++ type '" + type_details(expected) + "')"; 24 0 24
78 24 ▶ throw ex_details;
Branch: 1 branch
BranchTrueFalseTotal
throw ex_details; 24 0 24
79 48 }
80  
81 }}}
82  
« Framework_xsgen.cc ↑ Summary t/typemap/object/static_cast.xsi »