| 1 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 2 |
|
| /// Ref::Store API implementation (attributes) /// |
| 3 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 4 |
|
| |
| 5 |
|
| #include "hreg.h" |
| 6 |
|
| #include "hrpriv.h" |
| 7 |
|
| #include "hrdefs.h" |
| 8 |
|
| #include "hr_duputil.h" |
| 9 |
|
| |
| 10 |
|
| #include <string.h> |
| 11 |
|
| #include <stdlib.h> |
| 12 |
|
| |
| 13 |
|
| |
| 14 |
|
| #define ATTR_FIELDS_COMMON \ |
| 15 |
|
| LOOKUP_FIELDS_COMMON \ |
| 16 |
|
| SV *table; \ |
| 17 |
|
| HV *attrhash; \ |
| 18 |
|
| unsigned char encap; |
| 19 |
|
| |
| 20 |
|
| typedef struct { |
| 21 |
|
| ATTR_FIELDS_COMMON |
| 22 |
|
| } hrattr_simple; |
| 23 |
|
| |
| 24 |
|
| typedef struct { |
| 25 |
|
| ATTR_FIELDS_COMMON; |
| 26 |
|
| SV *obj_rv; |
| 27 |
|
| char *obj_paddr; |
| 28 |
|
| } hrattr_encap; |
| 29 |
|
| |
| 30 |
|
| #define attr_parent_tbl(attr) (HR_Table_t)(attr->table) |
| 31 |
|
| |
| 32 |
|
| #define attr_from_sv(sv) (hrattr_simple*)(SvPVX(sv)) |
| 33 |
|
| /*Declare a function which will be our trigger and proxy deletion/checking |
| 34 |
|
| of the hash*/ |
| 35 |
|
| |
| 36 |
|
| #define attr_strkey(aobj, sz) ((char*)(((char*)(aobj))+sz)) |
| 37 |
|
| |
| 38 |
|
| #define attr_getsize(attr) \ |
| 39 |
|
| ((attr->encap) ? sizeof(hrattr_encap) : sizeof(hrattr_simple)) |
| 40 |
|
| |
| 41 |
|
| #define attr_encap_cast(attr) ((hrattr_encap*)attr) |
| 42 |
|
| |
| 43 |
|
| static inline SV *attr_get(SV *self, SV *attr, char *t, int options); |
| 44 |
|
| static inline SV *attr_new_common(char *pkg, char *key, SV *table, int attrsize); |
| 45 |
|
| |
| 46 |
|
| static void attr_destroy_trigger(SV *self, SV *encap_obj, HR_Action *action_list); |
| 47 |
|
| static void encap_attr_destroy_hook(SV *encap_obj, SV *attr_sv, HR_Action *action_list); |
| 48 |
|
| |
| 49 |
|
| static inline SV* attr_simple_new(char *pkg, char *astr, SV *table); |
| 50 |
|
| static inline SV* attr_encap_new(char *pkg, char *astr, SV *encapped, SV *table); |
| 51 |
|
| static inline SV* attr_new_common(char *pkg, char *astr, SV *table, int attrsz); |
| 52 |
|
| static inline void attr_delete_from_vhash(SV *self, SV *value); |
| 53 |
|
| static inline void attr_delete_value_from_attrhash(SV *self, SV *value); |
| 54 |
|
| |
| 55 |
|
| static inline SV* |
| 56 |
20 |
| attr_new_common(char *pkg, char *key, SV *table, int attrsize) |
| 57 |
|
| { |
| 58 |
20 |
| int keylen = strlen(key) + 1; |
| 59 |
20 |
| int bloblen = attrsize + keylen; |
| 60 |
20 |
| SV *self = mk_blessed_blob(pkg, bloblen); |
| 61 |
20 |
| hrattr_simple *attr = attr_from_sv(SvRV(self)); |
| 62 |
20 |
| char *key_offset = attr_strkey(attr, attrsize); |
| 63 |
20 |
▶ | Copy(key, key_offset, keylen, char); |
Branch: 2 branches
| Branch | True | False | Total |
| Copy(key, key_offset, keylen, char); |
0 |
20 |
20 |
| Copy(key, key_offset, keylen, char); |
0 |
20 |
20 |
|
| 64 |
20 |
| attr->table = SvRV(table); |
| 65 |
20 |
| attr->attrhash = newHV(); |
| 66 |
20 |
| attr->encap = 0; |
| 67 |
|
| |
| 68 |
20 |
| HR_Action destroy_action[] = { |
| 69 |
20 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(self), &attr_destroy_trigger), |
| 70 |
|
| HR_ACTION_LIST_TERMINATOR |
| 71 |
|
| }; |
| 72 |
|
| |
| 73 |
20 |
| HR_add_actions_real(self, destroy_action); |
| 74 |
20 |
| return self; |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
|
| static inline SV |
| 78 |
8 |
| *attr_encap_new(char *pkg, char *key, SV *obj, SV *table) |
| 79 |
|
| { |
| 80 |
8 |
| SV *self = attr_new_common(pkg, key, table, sizeof(hrattr_encap)); |
| 81 |
8 |
| hrattr_encap *attr = attr_encap_cast(attr_from_sv(SvRV(self))); |
| 82 |
8 |
| attr->obj_rv = newSVsv(obj); |
| 83 |
8 |
| attr->obj_paddr = (char*)SvRV(obj); |
| 84 |
8 |
| attr->encap = 1; |
| 85 |
8 |
| HR_Action encap_destroy_action[] = { |
| 86 |
8 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(self), (SV*)&encap_attr_destroy_hook), |
| 87 |
|
| HR_ACTION_LIST_TERMINATOR |
| 88 |
|
| }; |
| 89 |
8 |
| HR_add_actions_real(obj, encap_destroy_action); |
| 90 |
8 |
| return self; |
| 91 |
|
| } |
| 92 |
|
| |
| 93 |
|
| static inline SV |
| 94 |
12 |
| *attr_simple_new(char *pkg, char *key, SV *table) |
| 95 |
|
| { |
| 96 |
12 |
| return attr_new_common(pkg, key, table, sizeof(hrattr_simple)); |
| 97 |
|
| } |
| 98 |
|
| |
| 99 |
|
| |
| 100 |
1 |
| SV *HRXSATTR_get_hash(SV *self) |
| 101 |
|
| { |
| 102 |
1 |
| hrattr_simple *attr = attr_from_sv(SvRV(self)); |
| 103 |
1 |
▶ | if(attr->attrhash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attr->attrhash) { |
1 |
0 |
1 |
|
| 104 |
1 |
| return newRV_inc((SV*)attr->attrhash); |
| 105 |
|
| } else { |
| 106 |
0 |
| return &PL_sv_undef; |
| 107 |
|
| } |
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
1 |
| char *HRXSATTR_kstring(SV *self) |
| 111 |
|
| { |
| 112 |
1 |
| hrattr_simple *attr = attr_from_sv(SvRV(self)); |
| 113 |
1 |
▶ | char *ret = attr_strkey(attr, attr_getsize(attr)); |
Branch: 1 branch
| Branch | True | False | Total |
| char *ret = attr_strkey(attr, attr_getsize(attr)); |
1 |
0 |
1 |
|
| 114 |
1 |
| return ret; |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
1 |
| SV *HRXSATTR_encap_ukey(SV *self) |
| 118 |
|
| { |
| 119 |
1 |
| return newSVsv(attr_encap_cast(attr_from_sv(SvRV(self)))->obj_rv); |
| 120 |
|
| } |
| 121 |
|
| |
| 122 |
2 |
| UV HRXSATTR_prefix_len(SV *self) |
| 123 |
|
| { |
| 124 |
2 |
| return (attr_from_sv(SvRV(self)))->prefix_len; |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
|
| static inline SV* |
| 128 |
464 |
| attr_get(SV *self, SV *attr, char *t, int options) |
| 129 |
|
| { |
| 130 |
464 |
| char *attr_ustr = NULL, *attr_fullstr = NULL; |
| 131 |
464 |
| char smallbuf[128] = { '\0' }; |
| 132 |
464 |
| char ptr_buf[128] = { '\0' }; |
| 133 |
|
| SV *kt_lookup, *attr_lookup; |
| 134 |
|
| SV **kt_ent; |
| 135 |
464 |
| SV *aobj = NULL; |
| 136 |
|
| SV **a_ent; |
| 137 |
|
| SV *my_stashcache_ref; |
| 138 |
|
| |
| 139 |
|
| HR_BlessParams stash_params; |
| 140 |
|
| |
| 141 |
464 |
| int attrlen = 0; |
| 142 |
464 |
| int on_heap = 0; |
| 143 |
464 |
| int prefix_len = 0; |
| 144 |
|
| |
| 145 |
464 |
| get_hashes(REF2TABLE(self), |
| 146 |
|
| HR_HKEY_LOOKUP_ATTR, &attr_lookup, |
| 147 |
|
| HR_HKEY_LOOKUP_KT, &kt_lookup, |
| 148 |
|
| HR_HKEY_LOOKUP_PRIVDATA, &my_stashcache_ref, |
| 149 |
|
| HR_HKEY_LOOKUP_NULL |
| 150 |
|
| ); |
| 151 |
|
| |
| 152 |
464 |
| blessparam_init(stash_params); |
| 153 |
|
| |
| 154 |
464 |
▶ | if(! (kt_ent = hv_fetch(REF2HASH(kt_lookup), t, strlen(t), 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(! (kt_ent = hv_fetch(REF2HASH(kt_lookup), t, strlen(t), 0))) { |
0 |
464 |
464 |
|
| 155 |
0 |
| die("Couldn't determine keytype '%s'", t); |
| 156 |
|
| } |
| 157 |
|
| |
| 158 |
464 |
| attrlen = strlen(SvPV_nolen(*kt_ent)) + 1; |
| 159 |
|
| |
| 160 |
464 |
▶ | if(SvROK(attr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvROK(attr)) { |
15 |
449 |
464 |
|
| 161 |
15 |
| attrlen += sprintf(ptr_buf, "%lu", SvRV(attr)); |
| 162 |
15 |
| attr_ustr = ptr_buf; |
| 163 |
|
| } else { |
| 164 |
449 |
▶ | attrlen += strlen(SvPV_nolen(attr)); |
Branch: 1 branch
| Branch | True | False | Total |
| attrlen += strlen(SvPV_nolen(attr)); |
6 |
443 |
449 |
|
| 165 |
449 |
| attr_ustr = SvPV_nolen(attr); |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
464 |
| attrlen += sizeof(HR_PREFIX_DELIM) - 1; |
| 169 |
|
| |
| 170 |
464 |
▶ | if(attrlen > 128) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attrlen > 128) { |
0 |
464 |
464 |
|
| 171 |
0 |
| on_heap = 1; |
| 172 |
0 |
| Newx(attr_fullstr, attrlen, char); |
| 173 |
|
| } else { |
| 174 |
464 |
| attr_fullstr = smallbuf; |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
464 |
| *attr_fullstr = '\0'; |
| 178 |
|
| |
| 179 |
464 |
| sprintf(attr_fullstr, "%s%s%s", SvPV_nolen(*kt_ent), HR_PREFIX_DELIM, attr_ustr); |
| 180 |
464 |
▶ | HR_DEBUG("ATTRKEY=%s", attr_fullstr); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("ATTRKEY=%s", attr_fullstr); |
462 |
2 |
464 |
| HR_DEBUG("ATTRKEY=%s", attr_fullstr); |
0 |
464 |
464 |
|
| 181 |
|
| |
| 182 |
464 |
| a_ent = hv_fetch(REF2HASH(attr_lookup), attr_fullstr, attrlen-1, 0); |
| 183 |
464 |
▶ | if(!a_ent) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!a_ent) { |
26 |
438 |
464 |
|
| 184 |
|
| |
| 185 |
26 |
| prefix_len = strlen(t); |
| 186 |
|
| |
| 187 |
26 |
▶ | if( (options & STORE_OPT_O_CREAT) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (options & STORE_OPT_O_CREAT) == 0) { |
6 |
20 |
26 |
|
| 188 |
6 |
▶ | HR_DEBUG("Could not locate attribute and O_CREAT not specified"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Could not locate attribute and O_CREAT not specified"); |
6 |
0 |
6 |
| HR_DEBUG("Could not locate attribute and O_CREAT not specified"); |
0 |
6 |
6 |
|
| 189 |
6 |
| goto GT_RET; |
| 190 |
20 |
▶ | } else if(SvROK(attr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(SvROK(attr)) { |
8 |
12 |
20 |
|
| 191 |
8 |
| blessparam_setstash(stash_params, |
| 192 |
|
| stash_from_cache_nocheck(my_stashcache_ref, HR_STASH_ATTR_ENCAP)); |
| 193 |
|
| |
| 194 |
8 |
| aobj = attr_encap_new(blessparam2chrp(stash_params), |
| 195 |
|
| attr_fullstr, attr, self); |
| 196 |
8 |
▶ | if( (options & STORE_OPT_STRONG_KEY) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (options & STORE_OPT_STRONG_KEY) == 0) { |
7 |
1 |
8 |
|
| 197 |
7 |
| sv_rvweaken( ((hrattr_encap*)attr_from_sv(SvRV(aobj)))->obj_rv ); |
| 198 |
|
| } |
| 199 |
|
| } else { |
| 200 |
12 |
| blessparam_setstash(stash_params, |
| 201 |
|
| stash_from_cache_nocheck(my_stashcache_ref,HR_STASH_ATTR_SCALAR)); |
| 202 |
12 |
| aobj = attr_simple_new(blessparam2chrp(stash_params), attr_fullstr, self); |
| 203 |
|
| } |
| 204 |
|
| |
| 205 |
20 |
| a_ent = hv_store(REF2HASH(attr_lookup), |
| 206 |
|
| attr_fullstr, attrlen-1, |
| 207 |
|
| newSVsv(aobj), 0); |
| 208 |
|
| |
| 209 |
|
| /*Actual attribute entry is ALWAYS weak and is entirely dependent on vhash |
| 210 |
|
| entries*/ |
| 211 |
20 |
| (attr_from_sv(SvRV(aobj)))->prefix_len = prefix_len; |
| 212 |
20 |
▶ | assert(a_ent); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(a_ent); |
0 |
20 |
20 |
|
| 213 |
20 |
| sv_rvweaken(*a_ent); |
| 214 |
|
| } else { |
| 215 |
438 |
| aobj = *a_ent; |
| 216 |
|
| } |
| 217 |
|
| |
| 218 |
464 |
| GT_RET: |
| 219 |
464 |
▶ | if(on_heap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(on_heap) { |
0 |
464 |
464 |
|
| 220 |
0 |
| Safefree(attr_fullstr); |
| 221 |
|
| } |
| 222 |
464 |
▶ | HR_DEBUG("Returning %p", aobj); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Returning %p", aobj); |
464 |
0 |
464 |
| HR_DEBUG("Returning %p", aobj); |
0 |
464 |
464 |
|
| 223 |
464 |
| return aobj; |
| 224 |
|
| } |
| 225 |
|
| |
| 226 |
440 |
| void HRA_store_a(SV *self, SV *attr, char *t, SV *value, ...) |
| 227 |
|
| { |
| 228 |
440 |
| SV *vstring = newSVuv((UV)SvRV(value)); //reverse lookup key |
| 229 |
440 |
| SV *aobj = NULL; //primary attribute entry, from attr_lookup |
| 230 |
440 |
| SV *vref = NULL; //value's entry in attribute hash |
| 231 |
440 |
| SV *attrhash_ref = NULL; //reference for attribute hash, for adding actions |
| 232 |
|
| |
| 233 |
440 |
| SV **a_r_ent = NULL; //lval-type HE for looking/storing attr in vhash |
| 234 |
440 |
| char *astring = NULL; |
| 235 |
|
| |
| 236 |
|
| hrattr_simple *aptr; //our private attribute structure |
| 237 |
|
| |
| 238 |
440 |
| int options = STORE_OPT_O_CREAT; |
| 239 |
|
| int i; |
| 240 |
|
| |
| 241 |
440 |
| dXSARGS; |
| 242 |
440 |
▶ | if ((items-4) % 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items-4) % 2) { |
0 |
440 |
440 |
|
| 243 |
0 |
| die("Expected hash options or nothing (got %d)", items-3); |
| 244 |
|
| } |
| 245 |
444 |
▶ | for(i=4;i<items;i+=2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=4;i<items;i+=2) { |
4 |
440 |
444 |
|
| 246 |
8 |
▶ | _chkopt(STRONG_ATTR, i, options); |
Branch: 4 branches
| Branch | True | False | Total |
| _chkopt(STRONG_ATTR, i, options); |
2 |
2 |
4 |
| _chkopt(STRONG_ATTR, i, options); |
2 |
0 |
2 |
| _chkopt(STRONG_ATTR, i, options); |
2 |
0 |
2 |
| _chkopt(STRONG_ATTR, i, options); |
0 |
2 |
2 |
|
| 247 |
4 |
▶ | _chkopt(STRONG_VALUE, i, options); |
Branch: 4 branches
| Branch | True | False | Total |
| _chkopt(STRONG_VALUE, i, options); |
2 |
0 |
2 |
| _chkopt(STRONG_VALUE, i, options); |
2 |
0 |
2 |
| _chkopt(STRONG_VALUE, i, options); |
2 |
0 |
2 |
| _chkopt(STRONG_VALUE, i, options); |
0 |
2 |
2 |
|
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
440 |
| aobj = attr_get(self, attr, t, options); |
| 251 |
440 |
▶ | if(!aobj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!aobj) { |
0 |
440 |
440 |
|
| 252 |
0 |
| die("attr_get() failed to return anything"); |
| 253 |
|
| } |
| 254 |
|
| |
| 255 |
440 |
| aptr = attr_from_sv(SvRV(aobj)); |
| 256 |
440 |
▶ | assert(SvROK(aobj)); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(SvROK(aobj)); |
0 |
440 |
440 |
|
| 257 |
440 |
▶ | astring = attr_strkey(aptr, attr_getsize(aptr)); |
Branch: 1 branch
| Branch | True | False | Total |
| astring = attr_strkey(aptr, attr_getsize(aptr)); |
8 |
432 |
440 |
|
| 258 |
|
| |
| 259 |
440 |
▶ | if(!insert_into_vhash(value, aobj, astring, REF2TABLE(self), NULL)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!insert_into_vhash(value, aobj, astring, REF2TABLE(self), NULL)) { |
200 |
240 |
440 |
|
| 260 |
200 |
| goto GT_RET; /*No new insertions*/ |
| 261 |
|
| } |
| 262 |
|
| |
| 263 |
240 |
▶ | if(!HvKEYS(aptr->attrhash)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(!HvKEYS(aptr->attrhash)) { |
0 |
240 |
240 |
| if(!HvKEYS(aptr->attrhash)) { |
20 |
220 |
240 |
|
| 264 |
|
| /*First entry and we've already inserted our reverse entry*/ |
| 265 |
20 |
| SvREFCNT_dec(SvRV(aobj)); |
| 266 |
|
| } |
| 267 |
|
| |
| 268 |
240 |
| vref = newSVsv(value); |
| 269 |
240 |
▶ | if(hv_store_ent(aptr->attrhash, vstring, vref, 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_store_ent(aptr->attrhash, vstring, vref, 0)) { |
240 |
0 |
240 |
|
| 270 |
240 |
▶ | if( (options & STORE_OPT_STRONG_VALUE) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (options & STORE_OPT_STRONG_VALUE) == 0) { |
238 |
2 |
240 |
|
| 271 |
238 |
| sv_rvweaken(vref); |
| 272 |
|
| } |
| 273 |
|
| } else { |
| 274 |
0 |
| SvREFCNT_dec(vref); |
| 275 |
|
| } |
| 276 |
|
| |
| 277 |
240 |
| RV_Newtmp(attrhash_ref, (SV*)aptr->attrhash); |
| 278 |
|
| |
| 279 |
240 |
| HR_Action v_actions[] = { |
| 280 |
240 |
| HR_DREF_FLDS_ptr_from_hv(SvRV(value), attrhash_ref), |
| 281 |
|
| HR_ACTION_LIST_TERMINATOR |
| 282 |
|
| }; |
| 283 |
|
| |
| 284 |
240 |
| HR_add_actions_real(value, v_actions); |
| 285 |
|
| |
| 286 |
440 |
| GT_RET: |
| 287 |
440 |
| SvREFCNT_dec(vstring); |
| 288 |
440 |
▶ | if(attrhash_ref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attrhash_ref) { |
240 |
200 |
440 |
|
| 289 |
240 |
▶ | RV_Freetmp(attrhash_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(attrhash_ref); |
0 |
240 |
240 |
| RV_Freetmp(attrhash_ref); |
0 |
240 |
240 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
240 |
240 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
|
| 290 |
|
| } |
| 291 |
440 |
▶ | XSRETURN(0); |
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN(0); |
0 |
440 |
440 |
|
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
17 |
| void HRA_fetch_a(SV *self, SV *attr, char *t) |
| 295 |
|
| { |
| 296 |
17 |
| dXSARGS; |
| 297 |
17 |
| SP -= 3; |
| 298 |
|
| |
| 299 |
17 |
▶ | if(GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_VOID) { |
0 |
17 |
17 |
|
| 300 |
0 |
▶ | XSRETURN(0); |
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN(0); |
0 |
0 |
0 |
|
| 301 |
|
| } |
| 302 |
|
| |
| 303 |
17 |
| SV *aobj = attr_get(self, attr, t, 0); |
| 304 |
17 |
▶ | if(!aobj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!aobj) { |
2 |
15 |
17 |
|
| 305 |
2 |
▶ | HR_DEBUG("Can't find attribute!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Can't find attribute!"); |
2 |
0 |
2 |
| HR_DEBUG("Can't find attribute!"); |
0 |
2 |
2 |
|
| 306 |
2 |
▶ | XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN_EMPTY; |
0 |
2 |
2 |
|
| 307 |
|
| } else { |
| 308 |
15 |
▶ | HR_DEBUG("Found aobj=%p", aobj); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Found aobj=%p", aobj); |
15 |
0 |
15 |
| HR_DEBUG("Found aobj=%p", aobj); |
0 |
15 |
15 |
|
| 309 |
|
| } |
| 310 |
15 |
| hrattr_simple *aptr = attr_from_sv(SvRV(aobj)); |
| 311 |
|
| |
| 312 |
15 |
▶ | HR_DEBUG("Attrhash=%p", aptr->attrhash); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Attrhash=%p", aptr->attrhash); |
15 |
0 |
15 |
| HR_DEBUG("Attrhash=%p", aptr->attrhash); |
0 |
15 |
15 |
|
| 313 |
15 |
| int nkeys = hv_iterinit(aptr->attrhash); |
| 314 |
15 |
▶ | HR_DEBUG("We have %d keys", nkeys); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("We have %d keys", nkeys); |
15 |
0 |
15 |
| HR_DEBUG("We have %d keys", nkeys); |
0 |
15 |
15 |
|
| 315 |
15 |
▶ | if(GIMME_V == G_SCALAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_SCALAR) { |
3 |
12 |
15 |
|
| 316 |
3 |
▶ | HR_DEBUG("Scalar return value requested"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Scalar return value requested"); |
3 |
0 |
3 |
| HR_DEBUG("Scalar return value requested"); |
0 |
3 |
3 |
|
| 317 |
3 |
▶ | XSRETURN_IV(nkeys); |
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN_IV(nkeys); |
0 |
3 |
3 |
|
| 318 |
|
| } |
| 319 |
12 |
▶ | HR_DEBUG("Will do some stack voodoo"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Will do some stack voodoo"); |
12 |
0 |
12 |
| HR_DEBUG("Will do some stack voodoo"); |
0 |
12 |
12 |
|
| 320 |
12 |
▶ | EXTEND(sp, nkeys); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(sp, nkeys); |
12 |
0 |
12 |
| EXTEND(sp, nkeys); |
0 |
12 |
12 |
|
| 321 |
12 |
| HE *cur = hv_iternext(aptr->attrhash); |
| 322 |
241 |
▶ | for(; cur != NULL; cur = hv_iternext(aptr->attrhash)) |
Branch: 1 branch
| Branch | True | False | Total |
| for(; cur != NULL; cur = hv_iternext(aptr->attrhash)) |
229 |
12 |
241 |
|
| 323 |
|
| { |
| 324 |
229 |
▶ | XPUSHs(sv_mortalcopy(hv_iterval(aptr->attrhash, cur))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(hv_iterval(aptr->attrhash, cur))); |
0 |
229 |
229 |
|
| 325 |
|
| } |
| 326 |
12 |
| PUTBACK; |
| 327 |
|
| } |
| 328 |
|
| |
| 329 |
4 |
| SV* HRA_attr_get(SV *self, SV *attr, char *t) |
| 330 |
|
| { |
| 331 |
4 |
| SV *ret = attr_get(self, attr, t, 0); |
| 332 |
4 |
▶ | if(ret) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(ret) { |
0 |
4 |
4 |
|
| 333 |
0 |
| ret = newSVsv(ret); |
| 334 |
|
| } else { |
| 335 |
4 |
| return &PL_sv_undef; |
| 336 |
|
| } |
| 337 |
0 |
| } |
| 338 |
|
| |
| 339 |
2 |
| void HRA_dissoc_a(SV *self, SV *attr, char *t, SV *value) |
| 340 |
|
| { |
| 341 |
2 |
| SV *aobj = attr_get(self, attr, t, 0); |
| 342 |
2 |
▶ | if(!aobj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!aobj) { |
0 |
2 |
2 |
|
| 343 |
0 |
| return; |
| 344 |
|
| } |
| 345 |
2 |
▶ | HR_DEBUG("Dissoc called"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Dissoc called"); |
2 |
0 |
2 |
| HR_DEBUG("Dissoc called"); |
0 |
2 |
2 |
|
| 346 |
2 |
| attr_delete_value_from_attrhash(aobj, value); |
| 347 |
2 |
| attr_delete_from_vhash(aobj, value); |
| 348 |
|
| } |
| 349 |
|
| |
| 350 |
1 |
| void HRA_unlink_a(SV *self, SV* attr, char *t) |
| 351 |
|
| { |
| 352 |
1 |
▶ | HR_DEBUG("UNLINK_ATTR"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("UNLINK_ATTR"); |
1 |
0 |
1 |
| HR_DEBUG("UNLINK_ATTR"); |
0 |
1 |
1 |
|
| 353 |
1 |
| SV *aobj = attr_get(self, attr, t, 0); |
| 354 |
1 |
▶ | if(!aobj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!aobj) { |
0 |
1 |
1 |
|
| 355 |
0 |
| return; |
| 356 |
|
| } |
| 357 |
1 |
| attr_destroy_trigger(SvRV(aobj), NULL, NULL); |
| 358 |
1 |
▶ | HR_DEBUG("UNLINK_ATTR DONE"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("UNLINK_ATTR DONE"); |
1 |
0 |
1 |
| HR_DEBUG("UNLINK_ATTR DONE"); |
0 |
1 |
1 |
|
| 359 |
|
| } |
| 360 |
|
| |
| 361 |
|
| |
| 362 |
33 |
| static inline void attr_delete_from_vhash(SV *self, SV *value) |
| 363 |
|
| { |
| 364 |
33 |
| hrattr_simple *attr = attr_from_sv(SvRV((self))); |
| 365 |
|
| //UN_del_action(value, SvRV(self)); |
| 366 |
33 |
| SV *vaddr = newSVuv((UV)SvRV(value)); |
| 367 |
|
| SV *rlookup; |
| 368 |
|
| SV *vhash; |
| 369 |
|
| |
| 370 |
33 |
▶ | char *astr = attr_strkey(attr, attr_getsize(attr)); |
Branch: 1 branch
| Branch | True | False | Total |
| char *astr = attr_strkey(attr, attr_getsize(attr)); |
8 |
25 |
33 |
|
| 371 |
|
| |
| 372 |
33 |
| get_hashes((HR_Table_t)attr_parent_tbl(attr), |
| 373 |
|
| HR_HKEY_LOOKUP_REVERSE, &rlookup, HR_HKEY_LOOKUP_NULL); |
| 374 |
|
| |
| 375 |
33 |
| vhash = get_vhash_from_rlookup(rlookup, vaddr, 0); |
| 376 |
|
| |
| 377 |
33 |
| U32 old_refcount = refcnt_ka_begin(value); |
| 378 |
33 |
▶ | if(vhash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(vhash) { |
21 |
12 |
33 |
|
| 379 |
21 |
▶ | HR_DEBUG("vhash has %d keys", HvKEYS(REF2HASH(vhash))); |
Branch: 3 branches
| Branch | True | False | Total |
| HR_DEBUG("vhash has %d keys", HvKEYS(REF2HASH(vhash))); |
21 |
0 |
21 |
| HR_DEBUG("vhash has %d keys", HvKEYS(REF2HASH(vhash))); |
0 |
21 |
21 |
| HR_DEBUG("vhash has %d keys", HvKEYS(REF2HASH(vhash))); |
0 |
0 |
0 |
|
| 380 |
|
| |
| 381 |
21 |
▶ | HR_DEBUG("Deleting '%s' from vhash=%p", astr, SvRV(vhash)); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleting '%s' from vhash=%p", astr, SvRV(vhash)); |
21 |
0 |
21 |
| HR_DEBUG("Deleting '%s' from vhash=%p", astr, SvRV(vhash)); |
0 |
21 |
21 |
|
| 382 |
21 |
| hv_delete(REF2HASH(vhash), astr, strlen(astr), G_DISCARD); |
| 383 |
21 |
▶ | if(!HvKEYS(REF2HASH(vhash))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(!HvKEYS(REF2HASH(vhash))) { |
0 |
21 |
21 |
| if(!HvKEYS(REF2HASH(vhash))) { |
8 |
13 |
21 |
|
| 384 |
8 |
▶ | HR_DEBUG("Vhash empty"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Vhash empty"); |
8 |
0 |
8 |
| HR_DEBUG("Vhash empty"); |
0 |
8 |
8 |
|
| 385 |
8 |
| HR_PL_del_action_container(value, rlookup); |
| 386 |
8 |
| hv_delete_ent(REF2HASH(rlookup), vaddr, G_DISCARD, 0); |
| 387 |
|
| } else { |
| 388 |
13 |
▶ | HR_DEBUG("Vhash still has %d keys", HvKEYS(REF2HASH(vhash))); |
Branch: 3 branches
| Branch | True | False | Total |
| HR_DEBUG("Vhash still has %d keys", HvKEYS(REF2HASH(vhash))); |
13 |
0 |
13 |
| HR_DEBUG("Vhash still has %d keys", HvKEYS(REF2HASH(vhash))); |
0 |
13 |
13 |
| HR_DEBUG("Vhash still has %d keys", HvKEYS(REF2HASH(vhash))); |
0 |
0 |
0 |
|
| 389 |
|
| } |
| 390 |
|
| } |
| 391 |
33 |
| refcnt_ka_end(value, old_refcount); |
| 392 |
33 |
| } |
| 393 |
|
| |
| 394 |
33 |
| static inline void attr_delete_value_from_attrhash(SV *self, SV *value) |
| 395 |
|
| { |
| 396 |
33 |
| hrattr_simple *attr = attr_from_sv(SvRV((self))); |
| 397 |
33 |
| SV *vaddr = newSVuv((UV)SvRV(value)); |
| 398 |
|
| SV *attrhash_ref; |
| 399 |
33 |
| RV_Newtmp(attrhash_ref, (SV*)attr->attrhash); |
| 400 |
|
| |
| 401 |
33 |
▶ | HR_DEBUG("Deleting action vobj=%p :: attrhash=%p", |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleting action vobj=%p :: attrhash=%p", |
33 |
0 |
33 |
| HR_DEBUG("Deleting action vobj=%p :: attrhash=%p", |
0 |
33 |
33 |
|
| 402 |
|
| SvRV(value), SvRV(attrhash_ref)); |
| 403 |
33 |
| HR_PL_del_action_container(value, attrhash_ref); |
| 404 |
33 |
| hv_delete_ent(attr->attrhash, vaddr, G_DISCARD, 0); |
| 405 |
|
| |
| 406 |
33 |
▶ | RV_Freetmp(attrhash_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(attrhash_ref); |
0 |
33 |
33 |
| RV_Freetmp(attrhash_ref); |
0 |
33 |
33 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
33 |
33 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
|
| 407 |
33 |
| SvREFCNT_dec(vaddr); |
| 408 |
33 |
▶ | HR_DEBUG("Done!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Done!"); |
33 |
0 |
33 |
| HR_DEBUG("Done!"); |
0 |
33 |
33 |
|
| 409 |
33 |
| } |
| 410 |
|
| |
| 411 |
14 |
| void HRXSATTR_unlink_value(SV *self, SV *value) |
| 412 |
|
| { |
| 413 |
14 |
| attr_delete_value_from_attrhash(self, value); |
| 414 |
14 |
| attr_delete_from_vhash(self, value); |
| 415 |
14 |
| } |
| 416 |
|
| |
| 417 |
|
| |
| 418 |
|
| /*This function is called when the attribute object is destroyed. This can |
| 419 |
|
| happen in the following cases: |
| 420 |
|
| |
| 421 |
|
| All value entries have deleted us from their vhashes: |
| 422 |
|
| * Entries in the attribute hash will be deleted at the end of this function. |
| 423 |
|
| * Values are still alive, but their possibly weak references are undef'd, |
| 424 |
|
| so we convert the stringified pointer into a real one |
| 425 |
|
| * If encapsulated object is still alive, the obj_paddr field should be true, |
| 426 |
|
| in which case, we delete actions tied to it, check the weakref to see |
| 427 |
|
| if that is defined, and decrease its refcount |
| 428 |
|
| |
| 429 |
|
| Encapsulated object has been deleted |
| 430 |
|
| * Value entries may possibly still be alive, in which case we check if they |
| 431 |
|
| need to have their vhashes deleted |
| 432 |
|
| * Delete our actions from the encapsulated object |
| 433 |
|
| */ |
| 434 |
|
| |
| 435 |
|
| /*First argument is the object, second is the argument */ |
| 436 |
|
| |
| 437 |
3 |
| static void encap_attr_destroy_hook(SV *encap_obj, SV *attr_sv, HR_Action *action_list) |
| 438 |
|
| { |
| 439 |
3 |
▶ | HR_DEBUG("Encap hook called. Attribute is %p", attr_sv); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Encap hook called. Attribute is %p", attr_sv); |
3 |
0 |
3 |
| HR_DEBUG("Encap hook called. Attribute is %p", attr_sv); |
0 |
3 |
3 |
|
| 440 |
3 |
| hrattr_encap *aencap = attr_encap_cast(attr_from_sv(attr_sv)); |
| 441 |
3 |
| aencap->obj_paddr = NULL; |
| 442 |
3 |
| SvREFCNT_dec(aencap->obj_rv); |
| 443 |
3 |
| aencap->obj_rv = NULL; |
| 444 |
|
| |
| 445 |
3 |
| SvREFCNT_inc(attr_sv); |
| 446 |
3 |
| attr_destroy_trigger(attr_sv, NULL, NULL); |
| 447 |
3 |
| SvREFCNT_dec(attr_sv); |
| 448 |
3 |
| } |
| 449 |
|
| |
| 450 |
20 |
| static void attr_destroy_trigger(SV *self_sv, SV *encap_obj, HR_Action *action_list) |
| 451 |
|
| { |
| 452 |
20 |
▶ | HR_DEBUG("self_sv=%p", self_sv); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("self_sv=%p", self_sv); |
20 |
0 |
20 |
| HR_DEBUG("self_sv=%p", self_sv); |
0 |
20 |
20 |
|
| 453 |
|
| |
| 454 |
20 |
▶ | HR_DEBUG("Attr destroy hook"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Attr destroy hook"); |
20 |
0 |
20 |
| HR_DEBUG("Attr destroy hook"); |
0 |
20 |
20 |
|
| 455 |
20 |
▶ | HR_DEBUG("We are ATTR=%p", self_sv); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("We are ATTR=%p", self_sv); |
20 |
0 |
20 |
| HR_DEBUG("We are ATTR=%p", self_sv); |
0 |
20 |
20 |
|
| 456 |
|
| //sv_dump(self_sv); |
| 457 |
20 |
| hrattr_simple *attr = attr_from_sv(self_sv); |
| 458 |
20 |
▶ | HR_DEBUG("hrattr=%p", attr); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("hrattr=%p", attr); |
20 |
0 |
20 |
| HR_DEBUG("hrattr=%p", attr); |
0 |
20 |
20 |
|
| 459 |
20 |
| HR_Table_t parent = attr_parent_tbl(attr); |
| 460 |
20 |
▶ | HR_DEBUG("Parent=%p", parent); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Parent=%p", parent); |
20 |
0 |
20 |
| HR_DEBUG("Parent=%p", parent); |
0 |
20 |
20 |
|
| 461 |
20 |
| SV *rlookup = NULL, *attr_lookup = NULL; |
| 462 |
|
| |
| 463 |
20 |
▶ | if(SvREFCNT(parent)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvREFCNT(parent)) { |
20 |
0 |
20 |
|
| 464 |
20 |
| get_hashes(parent, |
| 465 |
|
| HR_HKEY_LOOKUP_REVERSE, &rlookup, |
| 466 |
|
| HR_HKEY_LOOKUP_ATTR, &attr_lookup, |
| 467 |
|
| HR_HKEY_LOOKUP_NULL); |
| 468 |
20 |
▶ | HR_DEBUG("rlookup=%p, attr_lookup=%p", rlookup, attr_lookup); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("rlookup=%p, attr_lookup=%p", rlookup, attr_lookup); |
20 |
0 |
20 |
| HR_DEBUG("rlookup=%p, attr_lookup=%p", rlookup, attr_lookup); |
0 |
20 |
20 |
|
| 469 |
|
| } else { |
| 470 |
0 |
▶ | HR_DEBUG("Main lookup table being destroyed?"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Main lookup table being destroyed?"); |
0 |
0 |
0 |
| HR_DEBUG("Main lookup table being destroyed?"); |
0 |
0 |
0 |
|
| 471 |
0 |
| parent = NULL; |
| 472 |
|
| } |
| 473 |
|
| |
| 474 |
|
| |
| 475 |
|
| char *ktmp; |
| 476 |
20 |
▶ | int attrsz = attr_getsize(attr); |
Branch: 1 branch
| Branch | True | False | Total |
| int attrsz = attr_getsize(attr); |
8 |
12 |
20 |
|
| 477 |
|
| SV *vtmp, *vhash; |
| 478 |
|
| I32 tmplen; |
| 479 |
|
| |
| 480 |
20 |
| mk_ptr_string(oaddr, self_sv); |
| 481 |
20 |
| int oaddr_len = strlen(oaddr); |
| 482 |
|
| |
| 483 |
20 |
| SV *attrhash_ref = NULL, *self_ref = NULL; |
| 484 |
20 |
| RV_Newtmp( attrhash_ref, ((SV*)attr->attrhash) ); |
| 485 |
20 |
| RV_Newtmp( self_ref, self_sv ); |
| 486 |
|
| |
| 487 |
20 |
▶ | if(action_list) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(action_list) { |
16 |
4 |
20 |
|
| 488 |
32 |
| while( (HR_nullify_action(action_list, |
| 489 |
|
| (SV*)&attr_destroy_trigger, |
| 490 |
|
| NULL, |
| 491 |
|
| HR_KEY_TYPE_NULL|HR_KEY_SFLAG_HASHREF_OPAQUE) |
| 492 |
32 |
▶ | == HR_ACTION_DELETED) ); |
Branch: 1 branch
| Branch | True | False | Total |
| == HR_ACTION_DELETED) ); |
16 |
16 |
32 |
|
| 493 |
|
| /*No body*/ |
| 494 |
|
| } else { |
| 495 |
4 |
| HR_PL_del_action_container(self_ref, (SV*)&attr_destroy_trigger); |
| 496 |
|
| } |
| 497 |
|
| |
| 498 |
20 |
▶ | HR_DEBUG("Deleted self destroy hook"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleted self destroy hook"); |
20 |
0 |
20 |
| HR_DEBUG("Deleted self destroy hook"); |
0 |
20 |
20 |
|
| 499 |
|
| |
| 500 |
|
| |
| 501 |
20 |
▶ | if(attr->encap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attr->encap) { |
8 |
12 |
20 |
|
| 502 |
8 |
| hrattr_encap *aencap = (hrattr_encap*)attr; |
| 503 |
|
| |
| 504 |
8 |
▶ | if(aencap->obj_paddr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(aencap->obj_paddr) { |
5 |
3 |
8 |
|
| 505 |
5 |
| SV *encap_ref = NULL; |
| 506 |
5 |
| RV_Newtmp(encap_ref, (SV*)aencap->obj_paddr); |
| 507 |
5 |
| HR_PL_del_action_container(encap_ref, |
| 508 |
|
| (SV*)&encap_attr_destroy_hook); |
| 509 |
5 |
▶ | RV_Freetmp(encap_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(encap_ref); |
0 |
5 |
5 |
| RV_Freetmp(encap_ref); |
0 |
5 |
5 |
| RV_Freetmp(encap_ref); |
0 |
0 |
0 |
| RV_Freetmp(encap_ref); |
0 |
0 |
0 |
| RV_Freetmp(encap_ref); |
0 |
5 |
5 |
| RV_Freetmp(encap_ref); |
0 |
0 |
0 |
|
| 510 |
5 |
▶ | HR_DEBUG("Deleted encap destroy hook"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleted encap destroy hook"); |
5 |
0 |
5 |
| HR_DEBUG("Deleted encap destroy hook"); |
0 |
5 |
5 |
|
| 511 |
|
| } |
| 512 |
|
| |
| 513 |
8 |
▶ | if(aencap->obj_rv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(aencap->obj_rv) { |
5 |
3 |
8 |
|
| 514 |
5 |
| SvREFCNT_dec( aencap->obj_rv ); |
| 515 |
|
| } |
| 516 |
|
| |
| 517 |
|
| } |
| 518 |
|
| |
| 519 |
20 |
▶ | if(attr_lookup) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attr_lookup) { |
20 |
0 |
20 |
|
| 520 |
20 |
▶ | HR_DEBUG("Deleting our attr_lookup entry.."); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleting our attr_lookup entry.."); |
20 |
0 |
20 |
| HR_DEBUG("Deleting our attr_lookup entry.."); |
0 |
20 |
20 |
|
| 521 |
20 |
| hv_delete(REF2HASH(attr_lookup), |
| 522 |
|
| attr_strkey(attr, attrsz), |
| 523 |
|
| strlen(attr_strkey(attr, attrsz)), |
| 524 |
|
| G_DISCARD); |
| 525 |
20 |
▶ | HR_DEBUG("attr_lookup entry deleted"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("attr_lookup entry deleted"); |
20 |
0 |
20 |
| HR_DEBUG("attr_lookup entry deleted"); |
0 |
20 |
20 |
|
| 526 |
|
| } |
| 527 |
|
| |
| 528 |
20 |
| U32 old_refcount = refcnt_ka_begin(self_sv); |
| 529 |
20 |
| I32 attrvals = hv_iterinit(attr->attrhash); |
| 530 |
20 |
▶ | HR_DEBUG("We have %d values", attrvals); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("We have %d values", attrvals); |
20 |
0 |
20 |
| HR_DEBUG("We have %d values", attrvals); |
0 |
20 |
20 |
|
| 531 |
|
| |
| 532 |
37 |
▶ | while( (vtmp = hv_iternextsv(attr->attrhash, &ktmp, &tmplen)) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| while( (vtmp = hv_iternextsv(attr->attrhash, &ktmp, &tmplen)) ) { |
17 |
20 |
37 |
|
| 533 |
|
| SV *vptr, *vref; |
| 534 |
17 |
| sscanf(ktmp, "%lu", &vptr); /*Don't ask.. also, uses slightly less memory*/ |
| 535 |
17 |
| RV_Newtmp(vref, vptr); |
| 536 |
|
| |
| 537 |
17 |
| U32 old_v_refcount = refcnt_ka_begin(vptr); |
| 538 |
|
| |
| 539 |
17 |
| attr_delete_value_from_attrhash(self_ref, vref); |
| 540 |
17 |
▶ | if(SvROK(vref) && parent) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvROK(vref) && parent) { |
17 |
0 |
17 |
| if(SvROK(vref) && parent) { |
17 |
0 |
17 |
|
| 541 |
17 |
▶ | HR_DEBUG("Deleting vhash entry"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleting vhash entry"); |
17 |
0 |
17 |
| HR_DEBUG("Deleting vhash entry"); |
0 |
17 |
17 |
|
| 542 |
17 |
| attr_delete_from_vhash(self_ref, vref); |
| 543 |
|
| } else { |
| 544 |
0 |
▶ | HR_DEBUG("Eh?"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Eh?"); |
0 |
0 |
0 |
| HR_DEBUG("Eh?"); |
0 |
0 |
0 |
|
| 545 |
|
| } |
| 546 |
17 |
▶ | RV_Freetmp(vref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(vref); |
0 |
17 |
17 |
| RV_Freetmp(vref); |
0 |
17 |
17 |
| RV_Freetmp(vref); |
0 |
0 |
0 |
| RV_Freetmp(vref); |
0 |
0 |
0 |
| RV_Freetmp(vref); |
0 |
17 |
17 |
| RV_Freetmp(vref); |
0 |
0 |
0 |
|
| 547 |
|
| |
| 548 |
17 |
| refcnt_ka_end(vptr, old_v_refcount); |
| 549 |
|
| } |
| 550 |
|
| |
| 551 |
20 |
| SvREFCNT_dec(attr->attrhash); |
| 552 |
20 |
▶ | RV_Freetmp(self_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(self_ref); |
0 |
20 |
20 |
| RV_Freetmp(self_ref); |
0 |
20 |
20 |
| RV_Freetmp(self_ref); |
0 |
0 |
0 |
| RV_Freetmp(self_ref); |
0 |
0 |
0 |
| RV_Freetmp(self_ref); |
0 |
20 |
20 |
| RV_Freetmp(self_ref); |
0 |
0 |
0 |
|
| 553 |
20 |
▶ | RV_Freetmp(attrhash_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(attrhash_ref); |
0 |
20 |
20 |
| RV_Freetmp(attrhash_ref); |
0 |
20 |
20 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
20 |
20 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
|
| 554 |
|
| |
| 555 |
20 |
| refcnt_ka_end(self_sv, old_refcount); |
| 556 |
20 |
▶ | HR_DEBUG("Attr destroy done"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Attr destroy done"); |
20 |
0 |
20 |
| HR_DEBUG("Attr destroy done"); |
0 |
20 |
20 |
|
| 557 |
20 |
| } |
| 558 |
|
| |
| 559 |
0 |
| void HRXSATTR_ithread_predup(SV *self, SV *table, HV *ptr_map) |
| 560 |
|
| { |
| 561 |
0 |
| hrattr_simple *attr = attr_from_sv(SvRV(self)); |
| 562 |
|
| |
| 563 |
|
| /*Make sure our attribute hash is visible to perl space*/ |
| 564 |
|
| SV *attrhash_ref; |
| 565 |
0 |
| RV_Newtmp(attrhash_ref, (SV*)attr->attrhash); |
| 566 |
|
| |
| 567 |
0 |
| hr_dup_store_rv(ptr_map, attrhash_ref); |
| 568 |
|
| |
| 569 |
0 |
▶ | RV_Freetmp(attrhash_ref); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
| RV_Freetmp(attrhash_ref); |
0 |
0 |
0 |
|
| 570 |
|
| |
| 571 |
|
| char *ktmp; |
| 572 |
|
| I32 tmplen; |
| 573 |
|
| SV *vtmp; |
| 574 |
|
| SV *rlookup; |
| 575 |
|
| |
| 576 |
0 |
| get_hashes(REF2TABLE(table), |
| 577 |
|
| HR_HKEY_LOOKUP_REVERSE, &rlookup, |
| 578 |
|
| HR_HKEY_LOOKUP_NULL); |
| 579 |
|
| |
| 580 |
0 |
| hv_iterinit(attr->attrhash); |
| 581 |
0 |
▶ | while( (vtmp = hv_iternextsv(attr->attrhash, &ktmp, &tmplen))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while( (vtmp = hv_iternextsv(attr->attrhash, &ktmp, &tmplen))) { |
0 |
0 |
0 |
|
| 582 |
0 |
| HR_Dup_Vinfo *vi = hr_dup_get_vinfo(ptr_map, SvRV(vtmp), 1); |
| 583 |
0 |
▶ | if(!vi->vhash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!vi->vhash) { |
0 |
0 |
0 |
|
| 584 |
0 |
| SV *vaddr = newSVuv((UV)SvRV(vtmp)); |
| 585 |
0 |
| SV *vhash = get_vhash_from_rlookup(rlookup, vaddr, 0); |
| 586 |
0 |
| vi->vhash = vhash; |
| 587 |
0 |
| SvREFCNT_dec(vaddr); |
| 588 |
|
| } |
| 589 |
|
| } |
| 590 |
|
| |
| 591 |
0 |
▶ | if(attr->encap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attr->encap) { |
0 |
0 |
0 |
|
| 592 |
0 |
| hrattr_encap *aencap = attr_encap_cast(attr); |
| 593 |
|
| |
| 594 |
0 |
| hr_dup_store_rv(ptr_map, aencap->obj_rv); |
| 595 |
0 |
| char *ai = (char*)hr_dup_store_kinfo( |
| 596 |
0 |
| ptr_map, HR_DUPKEY_AENCAP, aencap->obj_paddr, 1); |
| 597 |
|
| |
| 598 |
0 |
▶ | if(SvWEAKREF(aencap->obj_rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvWEAKREF(aencap->obj_rv)) { |
0 |
0 |
0 |
|
| 599 |
0 |
| *ai = HRK_DUP_WEAK_ENCAP; |
| 600 |
|
| } else { |
| 601 |
0 |
| *ai = 0; |
| 602 |
|
| } |
| 603 |
|
| } |
| 604 |
0 |
| } |
| 605 |
|
| |
| 606 |
0 |
| void HRXSATTR_ithread_postdup(SV *newself, SV *newtable, HV *ptr_map) |
| 607 |
|
| { |
| 608 |
0 |
| hrattr_simple *attr = attr_from_sv(SvRV(newself)); |
| 609 |
|
| |
| 610 |
0 |
▶ | HR_DEBUG("Fetching new attrhash_ref"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Fetching new attrhash_ref"); |
0 |
0 |
0 |
| HR_DEBUG("Fetching new attrhash_ref"); |
0 |
0 |
0 |
|
| 611 |
|
| |
| 612 |
0 |
| SV *new_attrhash_ref = hr_dup_newsv_for_oldsv(ptr_map, attr->attrhash, 0); |
| 613 |
|
| |
| 614 |
0 |
| attr->attrhash = (HV*)SvRV(new_attrhash_ref); |
| 615 |
0 |
| SvREFCNT_inc(attr->attrhash); /*Because the copy hash will soon be deleted*/ |
| 616 |
|
| |
| 617 |
0 |
| attr->table = SvRV(newtable); |
| 618 |
|
| |
| 619 |
0 |
▶ | HR_DEBUG("New attrhash: %p", attr->attrhash); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("New attrhash: %p", attr->attrhash); |
0 |
0 |
0 |
| HR_DEBUG("New attrhash: %p", attr->attrhash); |
0 |
0 |
0 |
|
| 620 |
|
| |
| 621 |
|
| /*Now do the equivalent of: my @keys = keys %attrhash; foreach my $key (@keys)*/ |
| 622 |
0 |
| int n_keys = hv_iterinit(attr->attrhash); |
| 623 |
|
| |
| 624 |
0 |
▶ | if(n_keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(n_keys) { |
0 |
0 |
0 |
|
| 625 |
0 |
| char **keylist = NULL; |
| 626 |
0 |
| char **klist_head = NULL; |
| 627 |
|
| int tmp_len, i; |
| 628 |
0 |
▶ | HR_DEBUG("Have %d keys", n_keys); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Have %d keys", n_keys); |
0 |
0 |
0 |
| HR_DEBUG("Have %d keys", n_keys); |
0 |
0 |
0 |
|
| 629 |
0 |
| Newx(keylist, n_keys, char*); |
| 630 |
0 |
| klist_head = keylist; |
| 631 |
|
| |
| 632 |
0 |
▶ | while(hv_iternextsv(attr->attrhash, keylist++, &tmp_len)); |
Branch: 1 branch
| Branch | True | False | Total |
| while(hv_iternextsv(attr->attrhash, keylist++, &tmp_len)); |
0 |
0 |
0 |
|
| 633 |
|
| /*No body*/ |
| 634 |
|
| |
| 635 |
0 |
▶ | for(i=0, keylist = klist_head; i < n_keys; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0, keylist = klist_head; i < n_keys; i++) { |
0 |
0 |
0 |
|
| 636 |
0 |
▶ | HR_DEBUG("Key: %s", keylist[i]); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Key: %s", keylist[i]); |
0 |
0 |
0 |
| HR_DEBUG("Key: %s", keylist[i]); |
0 |
0 |
0 |
|
| 637 |
0 |
| SV *stored = hv_delete(attr->attrhash, keylist[i], strlen(keylist[i]), 0); |
| 638 |
0 |
▶ | assert(stored); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(stored); |
0 |
0 |
0 |
|
| 639 |
0 |
▶ | assert(SvROK(stored)); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(SvROK(stored)); |
0 |
0 |
0 |
|
| 640 |
|
| |
| 641 |
0 |
| mk_ptr_string(new_s, SvRV(stored)); |
| 642 |
0 |
| hv_store(attr->attrhash, new_s, strlen(new_s), stored, 0); |
| 643 |
0 |
| HR_Action v_actions[] = { |
| 644 |
0 |
| HR_DREF_FLDS_ptr_from_hv(SvRV(stored), new_attrhash_ref), |
| 645 |
|
| HR_ACTION_LIST_TERMINATOR |
| 646 |
|
| }; |
| 647 |
0 |
▶ | HR_DEBUG("Will add new actions for value in attrhash"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Will add new actions for value in attrhash"); |
0 |
0 |
0 |
| HR_DEBUG("Will add new actions for value in attrhash"); |
0 |
0 |
0 |
|
| 648 |
0 |
| HR_add_actions_real(stored, v_actions); |
| 649 |
|
| } |
| 650 |
0 |
| Safefree(klist_head); |
| 651 |
|
| } |
| 652 |
|
| |
| 653 |
0 |
| HR_Action attr_actions[] = { |
| 654 |
0 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(newself), &attr_destroy_trigger), |
| 655 |
|
| HR_ACTION_LIST_TERMINATOR |
| 656 |
|
| }; |
| 657 |
|
| |
| 658 |
0 |
▶ | HR_DEBUG("Will add new actions for attribute object"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Will add new actions for attribute object"); |
0 |
0 |
0 |
| HR_DEBUG("Will add new actions for attribute object"); |
0 |
0 |
0 |
|
| 659 |
0 |
| HR_add_actions_real(newself, attr_actions); |
| 660 |
|
| |
| 661 |
0 |
▶ | if(attr->encap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(attr->encap) { |
0 |
0 |
0 |
|
| 662 |
0 |
| hrattr_encap *aencap = attr_encap_cast(attr); |
| 663 |
0 |
| SV *new_encap = hr_dup_newsv_for_oldsv(ptr_map, aencap->obj_paddr, 1); |
| 664 |
0 |
| char *ainfo = (char*)hr_dup_get_kinfo( |
| 665 |
0 |
| ptr_map, HR_DUPKEY_AENCAP, aencap->obj_paddr); |
| 666 |
0 |
▶ | if(*ainfo == HRK_DUP_WEAK_ENCAP) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(*ainfo == HRK_DUP_WEAK_ENCAP) { |
0 |
0 |
0 |
|
| 667 |
0 |
| sv_rvweaken(new_encap); |
| 668 |
|
| } |
| 669 |
0 |
| HR_Action encap_actions[] = { |
| 670 |
0 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(newself), (SV*)&encap_attr_destroy_hook), |
| 671 |
|
| HR_ACTION_LIST_TERMINATOR |
| 672 |
|
| }; |
| 673 |
0 |
▶ | HR_DEBUG("Will add actions for new encapsulated object"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Will add actions for new encapsulated object"); |
0 |
0 |
0 |
| HR_DEBUG("Will add actions for new encapsulated object"); |
0 |
0 |
0 |
|
| 674 |
0 |
| HR_add_actions_real(new_encap, encap_actions); |
| 675 |
|
| |
| 676 |
0 |
| aencap->obj_rv = new_encap; |
| 677 |
0 |
| aencap->obj_paddr = (char*)SvRV(new_encap); |
| 678 |
|
| |
| 679 |
|
| /*We also need to change our key string...*/ |
| 680 |
0 |
| char *oldstr = attr_strkey(aencap, sizeof(hrattr_encap)); |
| 681 |
|
| |
| 682 |
0 |
| char *oldptr = strrchr(oldstr, HR_PREFIX_DELIM[0]); |
| 683 |
|
| |
| 684 |
0 |
▶ | assert(oldptr); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(oldptr); |
0 |
0 |
0 |
|
| 685 |
0 |
▶ | HR_DEBUG("Old attr string: %s", oldstr); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Old attr string: %s", oldstr); |
0 |
0 |
0 |
| HR_DEBUG("Old attr string: %s", oldstr); |
0 |
0 |
0 |
|
| 686 |
0 |
| oldptr++; |
| 687 |
0 |
| *(oldptr) = '\0'; |
| 688 |
0 |
| mk_ptr_string(newptr, aencap->obj_paddr); |
| 689 |
0 |
▶ | SvGROW(SvRV(newself), sizeof(hrattr_encap) |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(SvRV(newself), sizeof(hrattr_encap) |
0 |
0 |
0 |
| SvGROW(SvRV(newself), sizeof(hrattr_encap) |
0 |
0 |
0 |
|
| 690 |
|
| +strlen(oldstr)+strlen(newptr)+1); |
| 691 |
0 |
| strcat(oldstr, newptr); |
| 692 |
0 |
▶ | HR_DEBUG("New string: %s", oldstr); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("New string: %s", oldstr); |
0 |
0 |
0 |
| HR_DEBUG("New string: %s", oldstr); |
0 |
0 |
0 |
|
| 693 |
|
| } |
| 694 |
|
| |
| 695 |
0 |
| } |