hr_duputil.h

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 48 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 94 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Ref/Store/Common.pm ↑ Summary Store.xs »
1 #ifndef HR_DUPUTIL_H_
2 #define HR_DUPUTIL_H_
3 #include "hreg.h"
4 #undef NDEBUG
5 #include <assert.h>
6  
7 enum {
8 HRK_DUP_WEAK_ENCAP = 1 << 0,
9 HRK_DUP_WEAK_VALUE = 1 << 1
10 };
11  
12 #define HR_DUPKEY_OLD_LOOKUPS "__XS_OLD_LOOKUPS:"
13  
14 #define HR_DUPKEY_KENCAP "__XS_KENCAP:"
15 #define HR_DUPKEY_AENCAP "__XS_AENCAP:"
16 #define HR_DUPKEY_VHASH "__XS_V2VI:"
17  
18 typedef struct {
19 void *vhash;
20 int flags;
21 } HR_Dup_Kinfo;
22  
23 typedef struct {
24 void *slookup;
25 void *flookup;
26 void *rlookup;
27 void *alookup;
28 } HR_Dup_OldLookups;
29  
30 typedef struct {
31 void *vhash;
32 } HR_Dup_Vinfo;
33  
34 #define mk_old_lookup_key(vname, table_addr) \
35 char vname[256] = { '\0' }; \
36 sprintf(vname, "%s%p", HR_DUPKEY_OLD_LOOKUPS, table_addr);
37  
38 #define mk_di_key(vname, pfix, eptr) \
39 char vname[256] = { '\0' }; \
40 sprintf(vname, "%s@%p", pfix, eptr);
41
42 #define mk_vi_key(vname, vaddr) \
43 char vname[256] = { '\0' }; \
44 sprintf(vname, "%s%p", HR_DUPKEY_VHASH, vaddr);
45  
46 static inline void
47 hr_dup_store_old_lookups(HV *ptr_map, HR_Table_t parent)
48 {
49  
50 mk_old_lookup_key(hkey, parent);
51 HR_DEBUG("Storing: %s", hkey);
52 if(hv_exists(ptr_map, hkey, strlen(hkey))) {
53 return;
54 }
55
56 SV *ol_sv = newSV(sizeof(HR_Dup_OldLookups));
57 HR_Dup_OldLookups *ol = (HR_Dup_OldLookups*)SvPVX(ol_sv);
58
59 SV *slookup, *flookup, *rlookup, *alookup;
60
61 get_hashes(parent,
62 HR_HKEY_LOOKUP_SCALAR, &slookup,
63 HR_HKEY_LOOKUP_REVERSE, &rlookup,
64 HR_HKEY_LOOKUP_FORWARD, &flookup,
65 HR_HKEY_LOOKUP_ATTR, &alookup,
66 HR_HKEY_LOOKUP_NULL
67 );
68
69 ol->slookup = SvRV(slookup);
70 ol->rlookup = SvRV(rlookup);
71 ol->flookup = SvRV(flookup);
72 ol->alookup = SvRV(alookup);
73
74 hv_store(ptr_map, hkey, strlen(hkey), ol_sv, 0);
75 }
76  
77 static inline HR_Dup_OldLookups*
78 hr_dup_get_old_lookups(HV *ptr_map, void *old_table)
79 {
80 mk_old_lookup_key(hkey, old_table);
81 HR_DEBUG("Fetching: %s", hkey);
82 HR_DEBUG("Retrieving for %lu (%p)", old_table, old_table);
83 SV **dupold_sv = hv_fetch(ptr_map, hkey, strlen(hkey), 0);
84 assert(dupold_sv);
85 return (HR_Dup_OldLookups*)SvPVX(*dupold_sv);
86 }
87  
88  
89 static inline HR_Dup_Kinfo*
90 0 hr_dup_store_kinfo(HV *ptr_map, char *kprefix, void *eptr, int size)
91 {
92 0 ▶ if(!size) {
Branch: 1 branch
BranchTrueFalseTotal
if(!size) { 0 0 0
93 0 size = sizeof(HR_Dup_Kinfo);
94 }
95 0 SV *stored_sv = newSV(size);
96 0 HR_Dup_Kinfo *di = (HR_Dup_Kinfo*)SvPVX(stored_sv);
97 0 mk_di_key(hkey, kprefix, eptr);
98 0 hv_store(ptr_map, hkey, strlen(hkey), stored_sv, 0);
99 0 return di;
100 }
101  
102 static inline HR_Dup_Kinfo*
103 0 hr_dup_get_kinfo(HV *ptr_map, char *kprefix, void *old_eptr)
104 {
105 0 mk_di_key(hkey, kprefix, old_eptr);
106 0 SV **stored = hv_fetch(ptr_map, hkey, strlen(hkey), 0);
107 0 ▶ assert(stored);
Branch: 1 branch
BranchTrueFalseTotal
assert(stored); 0 0 0
108 0 return (HR_Dup_Kinfo*)SvPVX(*stored);
109 }
110  
111 static inline HR_Dup_Vinfo*
112 0 hr_dup_get_vinfo(HV *ptr_map, void *vaddr, int create)
113 {
114 0 mk_vi_key(hkey, vaddr);
115 0 ▶ SV **stored = hv_fetch(ptr_map, hkey, strlen(hkey), create);
Branch: 1 branch
BranchTrueFalseTotal
SV **stored = hv_fetch(ptr_map, hkey, strlen(hkey), create); 0 0 0
116
117 0 ▶ if(!create) {
Branch: 1 branch
BranchTrueFalseTotal
if(!create) { 0 0 0
118 0 ▶ if(!stored) {
Branch: 1 branch
BranchTrueFalseTotal
if(!stored) { 0 0 0
119 0 return NULL;
120 }
121 } else {
122 0 ▶ assert(stored && *stored);
Branch: 2 branches
BranchTrueFalseTotal
assert(stored && *stored); 0 0 0
assert(stored && *stored); 0 0 0
123 0 ▶ if(SvTYPE(*stored) == SVt_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTYPE(*stored) == SVt_NULL) { 0 0 0
124 0 ▶ SvUPGRADE(*stored, SVt_PV);
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE(*stored, SVt_PV); 0 0 0
125 0 ▶ SvGROW( (*stored), sizeof(HR_Dup_Vinfo));
Branch: 2 branches
BranchTrueFalseTotal
SvGROW( (*stored), sizeof(HR_Dup_Vinfo)); 0 0 0
SvGROW( (*stored), sizeof(HR_Dup_Vinfo)); 0 0 0
126 0 ((HR_Dup_Vinfo*)SvPVX( (*stored)) )->vhash = NULL;
127 }
128 }
129 0 return (HR_Dup_Vinfo*)SvPVX(*stored);
130 }
131  
132 static inline SV*
133 0 hr_dup_newsv_for_oldsv(HV *ptr_map, void *oldptr, int copy)
134 {
135 0 mk_ptr_string(old_s, oldptr);
136 0 ▶ HR_DEBUG("Fetching for %lu (%p)", oldptr, oldptr);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Fetching for %lu (%p)", oldptr, oldptr); 0 0 0
HR_DEBUG("Fetching for %lu (%p)", oldptr, oldptr); 0 0 0
137 0 SV **ret = hv_fetch(ptr_map, old_s, strlen(old_s), 0);
138 0 ▶ if(!ret) {
Branch: 1 branch
BranchTrueFalseTotal
if(!ret) { 0 0 0
139 0 ▶ HR_DEBUG("Couldn't fetch!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Couldn't fetch!"); 0 0 0
HR_DEBUG("Couldn't fetch!"); 0 0 0
140 0 sv_dump((SV*)ptr_map);
141 }
142 0 ▶ assert(ret);
Branch: 1 branch
BranchTrueFalseTotal
assert(ret); 0 0 0
143 0 ▶ if(copy) {
Branch: 1 branch
BranchTrueFalseTotal
if(copy) { 0 0 0
144 0 return newSVsv(*ret);
145 } else {
146 0 return *ret;
147 }
148 }
149  
150 static inline void
151 0 hr_dup_store_rv(HV *ptr_map, SV *rv)
152 {
153 0 ▶ assert(SvROK(rv));
Branch: 1 branch
BranchTrueFalseTotal
assert(SvROK(rv)); 0 0 0
154
155 0 mk_ptr_string(sv_s, SvRV(rv));
156 0 ▶ HR_DEBUG("Checking to see if %s is already stored", sv_s);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Checking to see if %s is already stored", sv_s); 0 0 0
HR_DEBUG("Checking to see if %s is already stored", sv_s); 0 0 0
157 0 ▶ if(!hv_exists(ptr_map, sv_s, strlen(sv_s))) {
Branch: 1 branch
BranchTrueFalseTotal
if(!hv_exists(ptr_map, sv_s, strlen(sv_s))) { 0 0 0
158 0 ▶ HR_DEBUG("It isn't!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("It isn't!"); 0 0 0
HR_DEBUG("It isn't!"); 0 0 0
159 0 SV *stored = newSVsv(rv);
160 0 sv_rvweaken(stored);
161 0 hv_store(ptr_map, sv_s, strlen(sv_s), stored, 0);
162 }
163 0 }
164  
165 #endif /*HR_DUPUTIL_H_*/
« blib/lib/Ref/Store/Common.pm ↑ Summary Store.xs »