xs/util.h

filter: Statementstmt 90.0% 27 / 30 Branchbran 67.5% 27 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.1% 54 / 70 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/accessors.h ↑ Summary XS.xs »
1 #ifndef __INHERITED_XS_UTIL_H_
2 #define __INHERITED_XS_UTIL_H_
3  
4 inline MAGIC*
5 CAIXS_mg_findext(SV* sv, int type, MGVTBL* vtbl) {
6 MAGIC* mg;
7  
8 if (sv) {
9 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
10 if (mg->mg_type == type && mg->mg_virtual == vtbl) {
11 return mg;
12 }
13 }
14 }
15  
16 return NULL;
17 }
18  
19 inline shared_keys*
20 785 CAIXS_find_payload(CV* cv) {
21 shared_keys* payload;
22  
23 #ifndef MULTIPLICITY
24 /* Blessed are ye and get a fastpath */
25 785 payload = (shared_keys*)(CvXSUBANY(cv).any_ptr);
26 785 ▶ if (UNLIKELY(!payload)) croak("Can't find hash key information");
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!payload)) croak("Can't find hash key information"); 0 785 785
27 #else
28 /*
29 We can't look into CvXSUBANY under threads, as it could have been written in the parent thread
30 and had gone away at any time without prior notice. So, instead, we have to scan our magical
31 refcnt storage - there's always a proper thread-local SV*, cloned for us by perl itself.
32 */
33 MAGIC* mg = CAIXS_mg_findext((SV*)cv, PERL_MAGIC_ext, &sv_payload_marker);
34 if (UNLIKELY(!mg)) croak("Can't find hash key information");
35  
36 payload = (shared_keys*)AvARRAY((AV*)(mg->mg_obj));
37 #endif
38  
39 785 return payload;
40 }
41  
42 inline HV*
43 143 CAIXS_find_stash(pTHX_ SV* self, CV* cv) {
44 HV* stash;
45  
46 143 ▶ if (SvROK(self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(self)) { 17 126 143
47 17 stash = SvSTASH(SvRV(self));
48  
49 } else {
50 126 GV* acc_gv = CvGV(cv);
51 126 ▶ if (UNLIKELY(!acc_gv)) croak("Can't have package accessor in anon sub");
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!acc_gv)) croak("Can't have package accessor in anon sub"); 0 126 126
52 126 stash = GvSTASH(acc_gv);
53  
54 126 ▶ const char* stash_name = HvENAME(stash);
Branch: 6 branches
BranchTrueFalseTotal
const char* stash_name = HvENAME(stash); 126 0 126
const char* stash_name = HvENAME(stash); 126 0 126
const char* stash_name = HvENAME(stash); 126 0 126
const char* stash_name = HvENAME(stash); 0 126 126
const char* stash_name = HvENAME(stash); 0 126 126
const char* stash_name = HvENAME(stash); 126 0 126
55 126 const char* self_name = SvPV_nolen(self);
56 126 ▶ if (strcmp(stash_name, self_name) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp(stash_name, self_name) != 0) { 21 105 126
57 21 stash = gv_stashsv(self, GV_ADD);
58 21 ▶ if (UNLIKELY(!stash)) croak("Couldn't get required stash");
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!stash)) croak("Couldn't get required stash"); 0 21 21
59 }
60 }
61  
62 143 return stash;
63 }
64  
65 static GV*
66 296 CAIXS_fetch_glob(pTHX_ HV* stash, SV* pkg_key) {
67 296 HE* hent = hv_fetch_ent(stash, pkg_key, 0, 0);
68 296 ▶ GV* glob = hent ? (GV*)HeVAL(hent) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
GV* glob = hent ? (GV*)HeVAL(hent) : NULL; 237 59 296
69  
70 296 ▶ if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) {
Branch: 5 branches
BranchTrueFalseTotal
if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) { 237 59 296
if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) { 0 237 237
if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) { 237 59 296
if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) { 0 237 237
if (UNLIKELY(!glob || !isGV(glob) || SvFAKE(glob))) { 59 237 296
71 59 ▶ if (!glob) glob = (GV*)newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (!glob) glob = (GV*)newSV(0); 59 0 59
72  
73 59 gv_init_sv(glob, stash, pkg_key, 0);
74  
75 59 ▶ if (hent) {
Branch: 1 branch
BranchTrueFalseTotal
if (hent) { 0 59 59
76 /* There was just a stub instead of the full glob */
77 0 SvREFCNT_inc_simple_void_NN((SV*)glob);
78 0 SvREFCNT_dec_NN(HeVAL(hent));
79 0 HeVAL(hent) = (SV*)glob;
80  
81 } else {
82 59 ▶ if (!hv_store_ent(stash, pkg_key, (SV*)glob, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_store_ent(stash, pkg_key, (SV*)glob, 0)) { 1 58 59
83 1 SvREFCNT_dec_NN(glob);
84 1 croak("Couldn't add a glob to package");
85 }
86 }
87 }
88  
89 295 return glob;
90 }
91  
92 #endif /* __INHERITED_XS_UTIL_H_ */
« xs/accessors.h ↑ Summary XS.xs »