hreg.c

filter: Statementstmt 69.0% 156 / 226 Branchbran 46.4% 130 / 280 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 56.5% 286 / 506 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« hr_implattr.c ↑ Summary hr_hrimpl.c »
1 #include "hreg.h"
2 #include "hrpriv.h"
3 #include <perl.h>
4 #undef NDEBUG
5 #include <assert.h>
6  
7 ////////////////////////////////////////////////////////////////////////////////
8 ////////////////////////////////////////////////////////////////////////////////
9 ////////////////////////////////////////////////////////////////////////////////
10 /// Internal Predeclarations ///
11 ////////////////////////////////////////////////////////////////////////////////
12 ////////////////////////////////////////////////////////////////////////////////
13 ////////////////////////////////////////////////////////////////////////////////
14 static inline HR_Action
15 *action_find_similar(HR_Action *actions, SV *hashref,
16 void *key, HR_KeyType_t ktype,
17 HR_Action **lastp);
18  
19 static inline HR_Action*
20 trigger_and_free_action(HR_Action *action_list, SV *object);
21  
22 static inline void action_sanitize_str(HR_Action *action);
23 static inline void action_sanitize_ptr(HR_Action *action);
24  
25 #define action_sanitize(actionp) \
26 ((actionp->ktype == HR_KEY_TYPE_STR) \
27 ? action_sanitize_str(actionp) : \
28 action_sanitize_ptr(actionp)); \
29 if( (actionp->flags & (HR_FLAG_HASHREF_RV|HR_FLAG_SV_REFCNT_DEC)) ) { \
30 SvREFCNT_dec(actionp->hashref); \
31 } \
32 action_clear(actionp);
33  
34 ////////////////////////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Definitions ///
38 ////////////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////////////////////////
41  
42 #define cmp_container_SV2RV(sv, rv) \
43 (SvROK(rv) && sv == SvRV(rv))
44  
45 #define cmp_container_RV2RV(rv1, rv2) \
46 (SvROK(rv1) && SvROK(rv2) && SvRV(rv1) == SvRV(rv2))
47  
48 248 static inline void action_sanitize_str(HR_Action *action)
49 {
50 if( (action->flags & HR_FLAG_STR_NO_ALLOC == 0 ) ) {
51 Safefree(action->key);
52 action->key == NULL;
53 }
54 248 }
55  
56 655 static inline void action_sanitize_ptr(HR_Action *action)
57 {
58 655 ▶ if( (action->flags & HR_FLAG_SV_REFCNT_DEC) ) {
Branch: 1 branch
BranchTrueFalseTotal
if( (action->flags & HR_FLAG_SV_REFCNT_DEC) ) { 0 655 655
59 0 ▶ HR_DEBUG("Decreasing reference count on SV=%p", action->key);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Decreasing reference count on SV=%p", action->key); 0 0 0
HR_DEBUG("Decreasing reference count on SV=%p", action->key); 0 0 0
60 0 SvREFCNT_dec((SV*)action->key);
61 0 action->key = NULL;
62 }
63 655 }
64  
65  
66 837 static inline HR_Action* action_find_similar(
67 HR_Action *action_list,
68 SV* hashref, void *key, HR_KeyType_t ktype,
69 HR_Action **lastp)
70 {
71 837 ▶ HR_DEBUG("Request to find ktype=%d, kp=%p", ktype, hashref);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Request to find ktype=%d, kp=%p", ktype, hashref); 837 0 837
HR_DEBUG("Request to find ktype=%d, kp=%p", ktype, hashref); 0 837 837
72 837 HR_Action *cur = action_list;
73 837 *lastp = cur;
74
75 837 int uhashref_is_opaque = (ktype & HR_KEY_SFLAG_HASHREF_OPAQUE);
76 837 ktype &= (~HR_KEY_SFLAG_HASHREF_OPAQUE);
77
78 /*Prefilter for container comparison*/
79 1716 ▶ for(; cur; *lastp = cur, cur = cur->next) {
Branch: 1 branch
BranchTrueFalseTotal
for(; cur; *lastp = cur, cur = cur->next) { 1266 450 1716
80 1266 ▶ if(uhashref_is_opaque == 0 && action_container_is_sv(cur)) {
Branch: 2 branches
BranchTrueFalseTotal
if(uhashref_is_opaque == 0 && action_container_is_sv(cur)) { 1028 238 1266
if(uhashref_is_opaque == 0 && action_container_is_sv(cur)) { 1007 21 1028
81 1007 ▶ if(action_container_is_rv(cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if(action_container_is_rv(cur)) { 0 1007 1007
82 0 ▶ if(!cmp_container_RV2RV(cur->hashref, hashref)) {
Branch: 3 branches
BranchTrueFalseTotal
if(!cmp_container_RV2RV(cur->hashref, hashref)) { 0 0 0
if(!cmp_container_RV2RV(cur->hashref, hashref)) { 0 0 0
if(!cmp_container_RV2RV(cur->hashref, hashref)) { 0 0 0
83 0 continue;
84 }
85 } else {
86 1007 ▶ if(!cmp_container_SV2RV(cur->hashref, hashref)) {
Branch: 2 branches
BranchTrueFalseTotal
if(!cmp_container_SV2RV(cur->hashref, hashref)) { 1007 0 1007
if(!cmp_container_SV2RV(cur->hashref, hashref)) { 768 239 1007
87 768 continue;
88 }
89 }
90 259 ▶ } else if(cur->hashref != hashref) {
Branch: 1 branch
BranchTrueFalseTotal
} else if(cur->hashref != hashref) { 110 149 259
91 110 continue;
92 }
93
94 /*Container Matches*/
95 388 ▶ if(ktype == HR_KEY_TYPE_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(ktype == HR_KEY_TYPE_NULL) { 77 311 388
96 77 ▶ HR_DEBUG("Returning OK on container match");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Returning OK on container match"); 77 0 77
HR_DEBUG("Returning OK on container match"); 0 77 77
97 77 return cur;
98 }
99
100 311 switch(ktype) {
101 0 case HR_KEY_STYPE_PTR_RV:
102 0 ▶ if(action_key_is_rv(cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if(action_key_is_rv(cur)) { 0 0 0
103 0 ▶ assert(SvROK((SV*)cur->key) && SvROK((SV*)key));
Branch: 2 branches
BranchTrueFalseTotal
assert(SvROK((SV*)cur->key) && SvROK((SV*)key)); 0 0 0
assert(SvROK((SV*)cur->key) && SvROK((SV*)key)); 0 0 0
104 0 ▶ if(SvRV((SV*)cur->key) == (SV*)key) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvRV((SV*)cur->key) == (SV*)key) { 0 0 0
105 0 ▶ HR_DEBUG("SvRV comparison matches. Returning OK");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("SvRV comparison matches. Returning OK"); 0 0 0
HR_DEBUG("SvRV comparison matches. Returning OK"); 0 0 0
106 0 return cur;
107 }
108 }
109 0 break;
110 311 case HR_KEY_TYPE_PTR:
111 311 ▶ if((char*)key == cur->key) {
Branch: 1 branch
BranchTrueFalseTotal
if((char*)key == cur->key) { 310 1 311
112 310 ▶ HR_DEBUG("Pointer Address %p matches. Returning OK",
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Pointer Address %p matches. Returning OK", 310 0 310
HR_DEBUG("Pointer Address %p matches. Returning OK", 0 310 310
113 key);
114 310 return cur;
115 }
116 1 break;
117 0 case HR_KEY_TYPE_STR:
118 0 ▶ if(strcmp((char*)key, cur->key) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(strcmp((char*)key, cur->key) == 0) { 0 0 0
119 0 ▶ HR_DEBUG("String comparison matches. Returning OK");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("String comparison matches. Returning OK"); 0 0 0
HR_DEBUG("String comparison matches. Returning OK"); 0 0 0
120 0 return cur;
121 }
122 0 break;
123 0 default:
124 0 die("Unknown key type %d", ktype);
125 break;
126 }
127 }
128 450 ▶ HR_DEBUG("Couldn't find match");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Couldn't find match"); 450 0 450
HR_DEBUG("Couldn't find match"); 0 450 450
129 450 return NULL;
130 }
131  
132 HREG_API_INTERNAL void
133 1042 HR_add_action(HR_Action *action_list,
134 HR_Action *new_action,
135 int want_unique)
136 {
137 1042 HR_Action *cur = NULL, *last = action_list;
138 1042 ▶ HR_DEBUG("hashref=%p, action_list=%p", new_action->hashref, action_list);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("hashref=%p, action_list=%p", new_action->hashref, action_list); 1040 2 1042
HR_DEBUG("hashref=%p, action_list=%p", new_action->hashref, action_list); 0 1042 1042
139
140 1042 int search_flags = 0;
141 int tail_len;
142
143 1042 ▶ if(action_list->ktype == HR_KEY_TYPE_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(action_list->ktype == HR_KEY_TYPE_NULL) { 490 552 1042
144 490 ▶ HR_DEBUG("List empty, creating new");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("List empty, creating new"); 490 0 490
HR_DEBUG("List empty, creating new"); 0 490 490
145 490 cur = action_list;
146 //goto GT_INSERT_ENTRY;
147 } else {
148
149 552 ▶ if(new_action->atype == HR_ACTION_TYPE_CALL_CFUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if(new_action->atype == HR_ACTION_TYPE_CALL_CFUNC) { 18 534 552
150 18 search_flags = HR_KEY_SFLAG_HASHREF_OPAQUE;
151 }
152 552 ▶ if( (cur = action_find_similar(
Branch: 1 branch
BranchTrueFalseTotal
if( (cur = action_find_similar( 167 385 552
153 action_list, new_action->hashref,
154 552 new_action->key, new_action->ktype|search_flags, &last)) ) {
155
156 167 ▶ HR_DEBUG("Existing action found for %p", cur->hashref);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Existing action found for %p", cur->hashref); 167 0 167
HR_DEBUG("Existing action found for %p", cur->hashref); 0 167 167
157 167 return;
158
159 }
160 }
161
162 //Newxz_Action(cur);
163 //HR_DEBUG("cur is now %p", cur);
164 //last->next = cur;
165 //
166 //GT_INSERT_ENTRY:
167 875 ▶ if(!cur) {
Branch: 1 branch
BranchTrueFalseTotal
if(!cur) { 385 490 875
168 385 Newxz_Action(cur);
169 }
170 875 ▶ if(last) {
Branch: 1 branch
BranchTrueFalseTotal
if(last) { 875 0 875
171 875 last->next = cur;
172 }
173
174 875 ▶ HR_DEBUG("cur=%p", cur);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("cur=%p", cur); 875 0 875
HR_DEBUG("cur=%p", cur); 0 875 875
175 875 ▶ Copy(new_action, cur, 1, HR_Action);
Branch: 2 branches
BranchTrueFalseTotal
Copy(new_action, cur, 1, HR_Action); 0 875 875
Copy(new_action, cur, 1, HR_Action); 0 875 875
176 875 cur->next = NULL;
177
178 875 switch (new_action->ktype) {
179 627 case HR_KEY_TYPE_PTR:
180 627 ▶ HR_DEBUG("Found pointer key type=%p", new_action->key);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Found pointer key type=%p", new_action->key); 627 0 627
HR_DEBUG("Found pointer key type=%p", new_action->key); 0 627 627
181 627 break;
182 248 case HR_KEY_TYPE_STR:
183 248 ▶ HR_DEBUG("Found string type");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Found string type"); 248 0 248
HR_DEBUG("Found string type"); 0 248 248
184 if(new_action->flags & HR_FLAG_STR_NO_ALLOC == 0) {
185 Newx(cur->key, strlen(new_action->key)+1, char);
186 *((char*)(cur->key)) = '\0';
187 strcpy(cur->key, new_action->key);
188 }
189 248 break;
190 0 default:
191 0 die("Only pointer and string keys are supported!");
192 break;
193 }
194
195 875 ▶ HR_DEBUG("Done assigning key");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Done assigning key"); 875 0 875
HR_DEBUG("Done assigning key"); 0 875 875
196 875 ▶ if(new_action->atype != HR_ACTION_TYPE_CALL_CFUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if(new_action->atype != HR_ACTION_TYPE_CALL_CFUNC) { 601 274 875
197
198 601 ▶ if( (new_action->flags & HR_FLAG_HASHREF_RV) ) {
Branch: 1 branch
BranchTrueFalseTotal
if( (new_action->flags & HR_FLAG_HASHREF_RV) ) { 0 601 601
199 0 cur->hashref = newSVsv(new_action->hashref);
200 0 ▶ if( (new_action->flags & HR_FLAG_HASHREF_WEAKEN) ) {
Branch: 1 branch
BranchTrueFalseTotal
if( (new_action->flags & HR_FLAG_HASHREF_WEAKEN) ) { 0 0 0
201 0 sv_rvweaken(cur->hashref);
202 }
203 } else {
204 601 cur->hashref = SvRV(new_action->hashref);
205 }
206 } else {
207 274 cur->hashref = new_action->hashref;
208 }
209 }
210  
211  
212  
213 HREG_API_INTERNAL
214 HR_Action*
215 155 HR_free_action(HR_Action *action)
216 {
217 155 HR_Action *ret = action->next;
218 155 ▶ action_sanitize(action);
Branch: 3 branches
BranchTrueFalseTotal
action_sanitize(action); 0 155 155
action_sanitize(action); 0 155 155
action_sanitize(action); 0 155 155
219 155 ▶ HR_DEBUG("Free: %p", action);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Free: %p", action); 155 0 155
HR_DEBUG("Free: %p", action); 0 155 155
220 155 Free_Action(action);
221 155 return ret;
222 }
223  
224 HREG_API_INTERNAL
225 HR_DeletionStatus_t
226 229 HR_del_action(HR_Action *action_list, SV *hashref, void *key, HR_KeyType_t ktype)
227 {
228 229 HR_Action *cur = action_list, *last = action_list;
229 229 cur = action_find_similar(action_list, hashref, key, ktype, &last);
230
231 229 ▶ if(!cur) {
Branch: 1 branch
BranchTrueFalseTotal
if(!cur) { 37 192 229
232 37 ▶ HR_DEBUG("Nothing to delete");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Nothing to delete"); 37 0 37
HR_DEBUG("Nothing to delete"); 0 37 37
233 37 return HR_ACTION_NOT_FOUND;
234 }
235
236
237 /*Action is first action, and there are no others*/
238 192 ▶ if(cur == action_list) {
Branch: 1 branch
BranchTrueFalseTotal
if(cur == action_list) { 159 33 192
239 159 ▶ if(cur->next == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(cur->next == NULL) { 155 4 159
240 155 ▶ HR_DEBUG("Detected empty action list");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Detected empty action list"); 155 0 155
HR_DEBUG("Detected empty action list"); 0 155 155
241 155 cur->hashref = NULL;
242 155 return HR_ACTION_EMPTY;
243 } else {
244 4 ▶ assert(last == cur && cur == action_list);
Branch: 2 branches
BranchTrueFalseTotal
assert(last == cur && cur == action_list); 4 0 4
assert(last == cur && cur == action_list); 4 0 4
245 4 ▶ HR_DEBUG("Shifting first action...");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Shifting first action..."); 4 0 4
HR_DEBUG("Shifting first action..."); 0 4 4
246 4 HR_Action *nextp = cur->next;
247 4 ▶ action_sanitize(cur);
Branch: 3 branches
BranchTrueFalseTotal
action_sanitize(cur); 0 4 4
action_sanitize(cur); 0 4 4
action_sanitize(cur); 0 4 4
248 4 ▶ Copy(nextp, last, 1, HR_Action);
Branch: 2 branches
BranchTrueFalseTotal
Copy(nextp, last, 1, HR_Action); 0 4 4
Copy(nextp, last, 1, HR_Action); 0 4 4
249 4 Free_Action(nextp);
250 4 return HR_ACTION_DELETED;
251 }
252 } else {
253 33 ▶ HR_DEBUG("Delete %p hashref=%p", cur, cur->hashref);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Delete %p hashref=%p", cur, cur->hashref); 33 0 33
HR_DEBUG("Delete %p hashref=%p", cur, cur->hashref); 0 33 33
254 33 ▶ action_sanitize(cur);
Branch: 3 branches
BranchTrueFalseTotal
action_sanitize(cur); 0 33 33
action_sanitize(cur); 0 33 33
action_sanitize(cur); 0 33 33
255
256 33 last->next = cur->next;
257 33 Free_Action(cur);
258 }
259 33 return HR_ACTION_DELETED;
260 }
261  
262 HREG_API_INTERNAL
263 HR_DeletionStatus_t
264 56 HR_nullify_action(HR_Action *action_list, SV *hashref, void *key, HR_KeyType_t ktype)
265 {
266 56 HR_Action *last = NULL;
267
268 56 action_list = action_find_similar(action_list, hashref, key, ktype, &last);
269 56 ▶ if(action_list) {
Branch: 1 branch
BranchTrueFalseTotal
if(action_list) { 28 28 56
270 28 ▶ HR_DEBUG("Nullifying action");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Nullifying action"); 28 0 28
HR_DEBUG("Nullifying action"); 0 28 28
271 28 ▶ action_sanitize(action_list);
Branch: 3 branches
BranchTrueFalseTotal
action_sanitize(action_list); 0 28 28
action_sanitize(action_list); 0 28 28
action_sanitize(action_list); 0 28 28
272 28 return HR_ACTION_DELETED;
273 }
274 28 ▶ HR_DEBUG("Can't find action to nullify!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Can't find action to nullify!"); 28 0 28
HR_DEBUG("Can't find action to nullify!"); 0 28 28
275 28 return HR_ACTION_NOT_FOUND;
276 }
277  
278 HREG_API_INTERNAL
279 void
280 335 HR_trigger_and_free_actions(HR_Action *action_list, SV *object)
281 {
282 335 HR_Action *head = action_list;
283 335 ▶ HR_DEBUG("BEGIN action_list=%p, next=%p", action_list,
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("BEGIN action_list=%p, next=%p", action_list, 335 0 335
HR_DEBUG("BEGIN action_list=%p, next=%p", action_list, 0 335 335
284 action_list->next);
285 HR_Action *last;
286 683 ▶ while( (action_list = trigger_and_free_action(action_list, object)) ) { ; }
Branch: 1 branch
BranchTrueFalseTotal
while( (action_list = trigger_and_free_action(action_list, object)) ) { ; } 348 335 683
287
288 /*We don't want to let each action being freed immediately. Speficially
289 we want to allow a case where we can nullify existing actions, in which
290 case we need the integrity of the linked list*/
291
292 335 action_list = head;
293 1018 ▶ while(action_list) {
Branch: 1 branch
BranchTrueFalseTotal
while(action_list) { 683 335 1018
294 683 last = action_list;
295 683 action_list = action_list->next;
296 683 ▶ HR_DEBUG("Free %p", last);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Free %p", last); 683 0 683
HR_DEBUG("Free %p", last); 0 683 683
297 683 Free_Action(last);
298 }
299 335 ▶ HR_DEBUG("Done");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Done"); 335 0 335
HR_DEBUG("Done"); 0 335 335
300 335 }
301  
302  
303 static inline void
304 0 invoke_coderef(SV *coderef, SV *object, char *key)
305 {
306 0 SV *tmpref = sv_2mortal(newRV_inc(object));
307 0 U32 old_refcount = refcnt_ka_begin(object);
308
309 0 dSP; /*Define stack variableS*/
310
311 0 ENTER;
312 0 SAVETMPS;
313
314 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
315
316 0 ▶ XPUSHs(tmpref);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(tmpref); 0 0 0
317 0 ▶ XPUSHs(sv_2mortal(newSVpv(key, strlen(key))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(key, strlen(key)))); 0 0 0
318
319 0 PUTBACK;
320
321
322 0 call_sv(coderef, G_DISCARD);
323 0 refcnt_ka_end(object, old_refcount);
324
325 0 SPAGAIN;
326 0 PUTBACK;
327 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
328
329 0 LEAVE;
330 0 }
331  
332 static inline HR_Action*
333 683 trigger_and_free_action(HR_Action *action_list, SV *object)
334 {
335
336 static int recurse_level = 0;
337
338 683 HR_Action *ret = NULL;
339 683 recurse_level++;
340
341 683 ▶ if(!action_list->hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if(!action_list->hashref) { 12 671 683
342 12 ▶ HR_DEBUG("Can't find hashref!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Can't find hashref!"); 12 0 12
HR_DEBUG("Can't find hashref!"); 0 12 12
343 12 goto GT_ACTION_FREE;
344 }
345
346 SV *container;
347
348 671 ▶ if( (action_list->flags & HR_FLAG_HASHREF_RV) ) {
Branch: 1 branch
BranchTrueFalseTotal
if( (action_list->flags & HR_FLAG_HASHREF_RV) ) { 0 671 671
349 0 ▶ if(!SvROK(action_list->hashref)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!SvROK(action_list->hashref)) { 0 0 0
350 0 ▶ HR_DEBUG("Hashref is no longer a valid reference");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Hashref is no longer a valid reference"); 0 0 0
HR_DEBUG("Hashref is no longer a valid reference"); 0 0 0
351 0 goto GT_ACTION_FREE;
352 } else {
353 0 container = SvRV(action_list->hashref);
354 }
355 } else {
356 671 container = action_list->hashref;
357 }
358
359 U32 old_refcount;
360
361 671 ▶ HR_DEBUG("ENTER! (LVL=%d)", recurse_level);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("ENTER! (LVL=%d)", recurse_level); 671 0 671
HR_DEBUG("ENTER! (LVL=%d)", recurse_level); 0 671 671
362 671 switch (action_list->ktype) {
363
364 0 case HR_KEY_TYPE_NULL:
365 0 ▶ HR_DEBUG("Action nullified!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Action nullified!"); 0 0 0
HR_DEBUG("Action nullified!"); 0 0 0
366 0 goto GT_ACTION_FREE;
367 break;
368
369 423 case HR_KEY_TYPE_PTR: {
370 423 switch (action_list->atype) {
371 281 case HR_ACTION_TYPE_DEL_HV:
372 case HR_ACTION_TYPE_DEL_AV: {
373
374 281 ▶ if(SvREADONLY(container)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvREADONLY(container)) { 0 281 281
375 0 warn("Container is read-only. Skipping deletion");
376 0 goto GT_ACTION_FREE;
377 break;
378 }
379 /*Since this function can recurse, we need to ensure our
380 collection remains valid*/
381 281 ▶ HR_DEBUG("(KEEPALIVE): Refcount for container=%p is now %d", container, SvREFCNT(container));
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("(KEEPALIVE): Refcount for container=%p is now %d", container, SvREFCNT(container)); 281 0 281
HR_DEBUG("(KEEPALIVE): Refcount for container=%p is now %d", container, SvREFCNT(container)); 0 281 281
382 281 old_refcount = refcnt_ka_begin(container);
383
384 281 ▶ if(action_list->atype == HR_ACTION_TYPE_DEL_HV) {
Branch: 1 branch
BranchTrueFalseTotal
if(action_list->atype == HR_ACTION_TYPE_DEL_HV) { 281 0 281
385 281 ▶ if( HvKEYS((HV*)container) ) {
Branch: 2 branches
BranchTrueFalseTotal
if( HvKEYS((HV*)container) ) { 0 281 281
if( HvKEYS((HV*)container) ) { 281 0 281
386 281 ▶ if( (action_list->flags & HR_FLAG_PTR_NO_STRINGIFY) ) {
Branch: 1 branch
BranchTrueFalseTotal
if( (action_list->flags & HR_FLAG_PTR_NO_STRINGIFY) ) { 0 281 281
387 0 ▶ HR_DEBUG("Deleting packed pointer %p (HV=%p)",
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Deleting packed pointer %p (HV=%p)", 0 0 0
HR_DEBUG("Deleting packed pointer %p (HV=%p)", 0 0 0
388 action_list->key, container);
389 0 hv_delete((HV*)container, &(action_list->key),
390 sizeof(char*), G_DISCARD);
391 } else {
392 281 mk_ptr_string(ptr_s, action_list->key);
393 281 ▶ HR_DEBUG("Clearing stringified pointer %s (HV=%p)",
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Clearing stringified pointer %s (HV=%p)", 281 0 281
HR_DEBUG("Clearing stringified pointer %s (HV=%p)", 0 281 281
394 ptr_s, container);
395 281 hv_delete((HV*)container, ptr_s,
396 strlen(ptr_s), G_DISCARD);
397 }
398 }
399 } else { /*DEL_AV*/
400 0 ▶ HR_DEBUG("Clearing idx=%d from AV=%p", action_list->key, container);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Clearing idx=%d from AV=%p", action_list->key, container); 0 0 0
HR_DEBUG("Clearing idx=%d from AV=%p", action_list->key, container); 0 0 0
401 0 ▶ if(av_exists( (AV*)container, (UV)action_list->key )) {
Branch: 1 branch
BranchTrueFalseTotal
if(av_exists( (AV*)container, (UV)action_list->key )) { 0 0 0
402 0 ▶ HR_DEBUG("idx=%d exists", (UV)action_list->key);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("idx=%d exists", (UV)action_list->key); 0 0 0
HR_DEBUG("idx=%d exists", (UV)action_list->key); 0 0 0
403 0 sv_setsv(*(av_fetch((AV*)container, (UV)action_list->key, 1)),
404 &PL_sv_undef);
405 }
406 }
407
408 /*Now we want to check how much the refcount has changed*/
409 281 ▶ HR_DEBUG("KEEPALIVE, ORIG=%d, CUR=%d", FAKE_REFCOUNT, SvREFCNT(container));
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("KEEPALIVE, ORIG=%d, CUR=%d", FAKE_REFCOUNT, SvREFCNT(container)); 281 0 281
HR_DEBUG("KEEPALIVE, ORIG=%d, CUR=%d", FAKE_REFCOUNT, SvREFCNT(container)); 0 281 281
410 281 refcnt_ka_end(container, old_refcount);
411
412 281 break;
413 }
414
415 0 case HR_ACTION_TYPE_CALL_CV: {
416 0 warn("Support for SV keys for coderefs not yet implemented. "
417 "Stringifying pointer");
418 0 mk_ptr_string(arg_s, action_list->key);
419 0 invoke_coderef(action_list->hashref, object, arg_s);
420 0 break;
421 }
422
423 142 case HR_ACTION_TYPE_CALL_CFUNC: {
424 142 ▶ HR_DEBUG("Calling C Function!");
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Calling C Function!"); 142 0 142
HR_DEBUG("Calling C Function!"); 0 142 142
425 142 ((HR_ActionCallback)(action_list->hashref)) (object, action_list->key, action_list);
426 142 break;
427 }
428
429 0 default:
430 0 die("Unhandled action type=%d", action_list->atype);
431 break;
432 }
433 //action_sanitize_ptr(action_list);
434 423 break;
435 }
436
437 248 case HR_KEY_TYPE_STR:
438 248 old_refcount = refcnt_ka_begin(container);
439
440 248 switch(action_list->atype) {
441 248 case HR_ACTION_TYPE_DEL_HV: {
442 248 ▶ HR_DEBUG("Removing string key=%s (A=%d)", action_list->key,
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("Removing string key=%s (A=%d)", action_list->key, 248 0 248
HR_DEBUG("Removing string key=%s (A=%d)", action_list->key, 0 248 248
443 action_list->atype);
444 248 hv_delete((HV*)container,
445 action_list->key, strlen(action_list->key), G_DISCARD);
446 248 break;
447 }
448 0 case HR_ACTION_TYPE_CALL_CV: {
449 0 invoke_coderef(action_list->hashref, object, action_list->key);
450 0 break;
451 }
452 0 default:
453 0 die("Unsupported action %d for string type", action_list->atype);
454 break;
455 }
456 248 refcnt_ka_end(container, old_refcount);
457 //action_sanitize_str(action_list);
458 248 break;
459
460 /*Switch ktype*/
461 0 default:
462 0 die("Unhandled key type %d!", action_list->ktype);
463 break;
464 }
465 683 GT_ACTION_FREE:
466 683 ret = action_list->next;
467 683 ▶ action_sanitize(action_list);
Branch: 3 branches
BranchTrueFalseTotal
action_sanitize(action_list); 248 435 683
action_sanitize(action_list); 0 683 683
action_sanitize(action_list); 0 683 683
468 //action_clear(action_list);
469 683 ▶ HR_DEBUG("EXIT (LVL=%d)", recurse_level);
Branch: 2 branches
BranchTrueFalseTotal
HR_DEBUG("EXIT (LVL=%d)", recurse_level); 683 0 683
HR_DEBUG("EXIT (LVL=%d)", recurse_level); 0 683 683
470 683 recurse_level--;
471 683 return ret;
472 }
« hr_implattr.c ↑ Summary hr_hrimpl.c »