| 1 |
|
| #include "hreg.h" |
| 2 |
|
| #include "hrdefs.h" |
| 3 |
|
| #include "hrpriv.h" |
| 4 |
|
| #include "hr_duputil.h" |
| 5 |
|
| |
| 6 |
|
| #include <string.h> |
| 7 |
|
| |
| 8 |
|
| HSpec HR_LookupKeys[] = { |
| 9 |
|
| {HR_HKEY_SLOOKUP, (char*)sizeof(HR_HKEY_SLOOKUP)-1}, |
| 10 |
|
| {HR_HKEY_FLOOKUP, (char*)sizeof(HR_HKEY_FLOOKUP)-1}, |
| 11 |
|
| {HR_HKEY_RLOOKUP, (char*)sizeof(HR_HKEY_RLOOKUP)-1}, |
| 12 |
|
| {HR_HKEY_KTYPES, (char*)sizeof(HR_HKEY_KTYPES)-1}, |
| 13 |
|
| {HR_HKEY_ALOOKUP, (char*)sizeof(HR_HKEY_ALOOKUP)-1} |
| 14 |
|
| }; |
| 15 |
|
| |
| 16 |
|
| typedef struct |
| 17 |
|
| __attribute__((packed)) |
| 18 |
|
| { |
| 19 |
|
| LOOKUP_FIELDS_COMMON; |
| 20 |
|
| } hrk_simple; |
| 21 |
|
| |
| 22 |
|
| typedef struct |
| 23 |
|
| __attribute__((packed)) |
| 24 |
|
| { |
| 25 |
|
| LOOKUP_FIELDS_COMMON; |
| 26 |
|
| HR_Table_t table; |
| 27 |
|
| SV* obj_ptr; |
| 28 |
|
| void* obj_paddr; |
| 29 |
|
| } hrk_encap; |
| 30 |
|
| |
| 31 |
|
| static inline HV* |
| 32 |
|
| get_v_hashref(hrk_encap *ke, SV* value); |
| 33 |
|
| |
| 34 |
|
| #define ketbl_from_ke(ke) (HR_Table_t)(ke->table) |
| 35 |
|
| |
| 36 |
|
| #define keptr_from_sv(svp) \ |
| 37 |
|
| ((hrk_encap*)(SvPVX(svp))) |
| 38 |
|
| |
| 39 |
|
| #define ksimple_from_sv(svp) \ |
| 40 |
|
| ((hrk_simple*)(SvPVX(svp))) |
| 41 |
|
| |
| 42 |
|
| #define ksimple_strkey(ksp) \ |
| 43 |
|
| (char*)(((char*)(ksp))+sizeof(hrk_simple)) |
| 44 |
|
| |
| 45 |
|
| /*We find our information about ourselves here, and place it inside our |
| 46 |
|
| private pointer table*/ |
| 47 |
|
| |
| 48 |
|
| static void k_encap_cleanup(SV *ksv, SV *_, HR_Action *action_list); |
| 49 |
|
| static void encap_destroy_hook(SV *encap_obj, SV *ksv, HR_Action *action_list); |
| 50 |
|
| static inline void k_encap_wire_actions(SV *ksv, SV *encap); |
| 51 |
|
| |
| 52 |
|
| typedef char* _stashspec[2]; |
| 53 |
|
| |
| 54 |
|
| #define stashspec_ent(name) \ |
| 55 |
|
| { (char*)HR_STASH_ ## name, HR_PKG_ ## name } |
| 56 |
|
| |
| 57 |
18 |
| void HRA_table_init(SV *self) |
| 58 |
|
| { |
| 59 |
18 |
| AV *my_stashcache = newAV(); |
| 60 |
|
| HV *stash; |
| 61 |
|
| |
| 62 |
18 |
| _stashspec classlist[] = { |
| 63 |
|
| stashspec_ent(KEY_SCALAR), |
| 64 |
|
| stashspec_ent(KEY_ENCAP), |
| 65 |
|
| stashspec_ent(ATTR_SCALAR), |
| 66 |
|
| stashspec_ent(ATTR_ENCAP), |
| 67 |
|
| { 0, 0 } |
| 68 |
|
| }; |
| 69 |
|
| |
| 70 |
|
| _stashspec *cspec; |
| 71 |
90 |
▶ | for(cspec = classlist; (*cspec)[1]; cspec++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(cspec = classlist; (*cspec)[1]; cspec++) { |
72 |
18 |
90 |
|
| 72 |
72 |
| stash = gv_stashpv((*cspec)[1], 0); |
| 73 |
72 |
▶ | if(!stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!stash) { |
0 |
72 |
72 |
|
| 74 |
0 |
| die("Couldn't get stash!"); |
| 75 |
|
| } |
| 76 |
72 |
| av_store(my_stashcache, (I32)((*cspec)[0]), newRV_inc((SV*)stash)); |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
18 |
| av_store((AV*)SvRV(self), HR_HKEY_LOOKUP_PRIVDATA, newRV_noinc(my_stashcache)); |
| 80 |
18 |
| } |
| 81 |
|
| |
| 82 |
7 |
| static void encap_destroy_hook(SV *encap_obj, SV *ksv, HR_Action *action_list) |
| 83 |
|
| { |
| 84 |
7 |
| U32 old_refcount = refcnt_ka_begin(encap_obj); |
| 85 |
7 |
▶ | HR_DEBUG("Called!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Called!"); |
7 |
0 |
7 |
| HR_DEBUG("Called!"); |
0 |
7 |
7 |
|
| 86 |
|
| SV *keyrv; |
| 87 |
7 |
| RV_Newtmp(keyrv, ksv); |
| 88 |
|
| |
| 89 |
7 |
| HR_XS_del_action_ext(keyrv, &k_encap_cleanup, NULL, |
| 90 |
|
| HR_KEY_TYPE_NULL|HR_KEY_SFLAG_HASHREF_OPAQUE); |
| 91 |
7 |
| k_encap_cleanup(ksv, NULL, NULL); |
| 92 |
7 |
| refcnt_ka_end(encap_obj, old_refcount); |
| 93 |
7 |
▶ | RV_Freetmp(keyrv); |
Branch: 6 branches
| Branch | True | False | Total |
| RV_Freetmp(keyrv); |
0 |
7 |
7 |
| RV_Freetmp(keyrv); |
0 |
7 |
7 |
| RV_Freetmp(keyrv); |
0 |
0 |
0 |
| RV_Freetmp(keyrv); |
0 |
0 |
0 |
| RV_Freetmp(keyrv); |
0 |
7 |
7 |
| RV_Freetmp(keyrv); |
0 |
0 |
0 |
|
| 94 |
7 |
| } |
| 95 |
|
| |
| 96 |
123 |
| static void k_encap_cleanup(SV *ksv, SV *_, HR_Action *action_list) |
| 97 |
|
| { |
| 98 |
|
| /*Find our forward entry from the stringified object pointer*/ |
| 99 |
123 |
| hrk_encap *ke = keptr_from_sv(ksv); |
| 100 |
123 |
| HR_Table_t table = ketbl_from_ke(ke); |
| 101 |
|
| SV *scalar_lookup, *forward, *reverse; |
| 102 |
123 |
| SV *encap_rv = ke->obj_ptr; |
| 103 |
123 |
| SV *value = NULL; |
| 104 |
123 |
| SV *vhash = NULL; |
| 105 |
|
| |
| 106 |
123 |
| SV **tmp_hashval = NULL; |
| 107 |
|
| |
| 108 |
123 |
| mk_ptr_string(obj_s, ke->obj_paddr); |
| 109 |
|
| |
| 110 |
123 |
▶ | if(!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!table) { |
0 |
123 |
123 |
|
| 111 |
0 |
| warn("Is table being destroyed?"); |
| 112 |
0 |
| goto GT_CLEANUP; |
| 113 |
|
| } |
| 114 |
|
| |
| 115 |
123 |
| ke->obj_paddr = NULL; |
| 116 |
123 |
| ke->obj_ptr = NULL; |
| 117 |
|
| |
| 118 |
123 |
▶ | HR_DEBUG("obj_s=%s", obj_s); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("obj_s=%s", obj_s); |
123 |
0 |
123 |
| HR_DEBUG("obj_s=%s", obj_s); |
0 |
123 |
123 |
|
| 119 |
|
| |
| 120 |
123 |
| get_hashes(table, |
| 121 |
|
| HR_HKEY_LOOKUP_REVERSE, &reverse, |
| 122 |
|
| HR_HKEY_LOOKUP_FORWARD, &forward, |
| 123 |
|
| HR_HKEY_LOOKUP_SCALAR, &scalar_lookup, |
| 124 |
|
| HR_HKEY_LOOKUP_NULL |
| 125 |
|
| ); |
| 126 |
|
| |
| 127 |
|
| |
| 128 |
123 |
▶ | if(!(scalar_lookup && forward && reverse)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if(!(scalar_lookup && forward && reverse)) { |
123 |
0 |
123 |
| if(!(scalar_lookup && forward && reverse)) { |
123 |
0 |
123 |
| if(!(scalar_lookup && forward && reverse)) { |
0 |
123 |
123 |
|
| 129 |
0 |
| die("Uhh...: (S=%p, F=%p, R=%p, REFCOUNT=%d", scalar_lookup, forward, reverse, |
| 130 |
|
| SvREFCNT(table)); |
| 131 |
|
| } |
| 132 |
|
| |
| 133 |
123 |
▶ | if(encap_rv && SvROK(encap_rv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(encap_rv && SvROK(encap_rv)) { |
123 |
0 |
123 |
| if(encap_rv && SvROK(encap_rv)) { |
116 |
7 |
123 |
|
| 134 |
116 |
| HR_XS_del_action_ext(encap_rv, &encap_destroy_hook, |
| 135 |
|
| ksv, HR_KEY_TYPE_PTR|HR_KEY_SFLAG_HASHREF_OPAQUE); |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
123 |
| tmp_hashval = hv_fetch( REF2HASH(forward), obj_s, strlen(obj_s), 0 ); |
| 139 |
123 |
▶ | if(!tmp_hashval) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!tmp_hashval) { |
0 |
123 |
123 |
|
| 140 |
0 |
▶ | HR_DEBUG("Can't find stored value in forward table"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Can't find stored value in forward table"); |
0 |
0 |
0 |
| HR_DEBUG("Can't find stored value in forward table"); |
0 |
0 |
0 |
|
| 141 |
0 |
| goto GT_CLEANUP; |
| 142 |
|
| } else { |
| 143 |
123 |
| value = *tmp_hashval; |
| 144 |
|
| } |
| 145 |
|
| |
| 146 |
|
| |
| 147 |
123 |
| mk_ptr_string(value_s, SvRV(value)); |
| 148 |
123 |
▶ | HR_DEBUG("value_s=%s", value_s); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("value_s=%s", value_s); |
123 |
0 |
123 |
| HR_DEBUG("value_s=%s", value_s); |
0 |
123 |
123 |
|
| 149 |
123 |
| tmp_hashval = hv_fetch( REF2HASH(reverse), value_s, strlen(value_s), 0); |
| 150 |
|
| |
| 151 |
123 |
▶ | if(tmp_hashval) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tmp_hashval) { |
8 |
115 |
123 |
|
| 152 |
8 |
| vhash = *tmp_hashval; |
| 153 |
8 |
▶ | HR_DEBUG("Deleting vfrom vhash %p", vhash); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Deleting vfrom vhash %p", vhash); |
8 |
0 |
8 |
| HR_DEBUG("Deleting vfrom vhash %p", vhash); |
0 |
8 |
8 |
|
| 154 |
|
| |
| 155 |
8 |
| hv_delete( REF2HASH(vhash), obj_s, strlen(obj_s), G_DISCARD ); |
| 156 |
|
| |
| 157 |
|
| /*Common value deletion operation*/ |
| 158 |
8 |
▶ | if(!HvKEYS(REF2HASH(vhash))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(!HvKEYS(REF2HASH(vhash))) { |
0 |
8 |
8 |
| if(!HvKEYS(REF2HASH(vhash))) { |
4 |
4 |
8 |
|
| 159 |
4 |
▶ | HR_DEBUG("Removing vhash"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Removing vhash"); |
4 |
0 |
4 |
| HR_DEBUG("Removing vhash"); |
0 |
4 |
4 |
|
| 160 |
4 |
| HR_PL_del_action_container(value, reverse); |
| 161 |
4 |
| hv_delete( REF2HASH(reverse), value_s, strlen(value_s), G_DISCARD); |
| 162 |
|
| } else { |
| 163 |
4 |
▶ | HR_DEBUG("Vhash still has %lu keys remaining", HvKEYS(REF2HASH(vhash))); |
Branch: 3 branches
| Branch | True | False | Total |
| HR_DEBUG("Vhash still has %lu keys remaining", HvKEYS(REF2HASH(vhash))); |
4 |
0 |
4 |
| HR_DEBUG("Vhash still has %lu keys remaining", HvKEYS(REF2HASH(vhash))); |
0 |
4 |
4 |
| HR_DEBUG("Vhash still has %lu keys remaining", HvKEYS(REF2HASH(vhash))); |
0 |
0 |
0 |
|
| 164 |
|
| } |
| 165 |
|
| } else { |
| 166 |
115 |
▶ | HR_DEBUG("Can't find anything!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Can't find anything!"); |
115 |
0 |
115 |
| HR_DEBUG("Can't find anything!"); |
0 |
115 |
115 |
|
| 167 |
|
| } |
| 168 |
|
| |
| 169 |
123 |
| hv_delete( REF2HASH(scalar_lookup), obj_s, strlen(obj_s), G_DISCARD ); |
| 170 |
123 |
| hv_delete( REF2HASH(forward), obj_s, strlen(obj_s), G_DISCARD ); |
| 171 |
|
| |
| 172 |
123 |
| GT_CLEANUP: |
| 173 |
123 |
▶ | if(encap_rv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(encap_rv) { |
123 |
0 |
123 |
|
| 174 |
123 |
| SvREFCNT_dec(encap_rv); |
| 175 |
|
| } |
| 176 |
123 |
▶ | HR_DEBUG("Returning..."); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Returning..."); |
123 |
0 |
123 |
| HR_DEBUG("Returning..."); |
0 |
123 |
123 |
|
| 177 |
123 |
| } |
| 178 |
|
| |
| 179 |
123 |
| static inline void k_encap_wire_actions(SV *ksv, SV *encap) |
| 180 |
|
| { |
| 181 |
123 |
| HR_Action key_actions[] = { |
| 182 |
123 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(ksv), &k_encap_cleanup), |
| 183 |
|
| HR_ACTION_LIST_TERMINATOR |
| 184 |
|
| }; |
| 185 |
123 |
| HR_Action encap_actions[] = { |
| 186 |
123 |
| HR_DREF_FLDS_arg_for_cfunc(SvRV(ksv), &encap_destroy_hook), |
| 187 |
|
| HR_ACTION_LIST_TERMINATOR |
| 188 |
|
| }; |
| 189 |
|
| |
| 190 |
123 |
| HR_add_actions_real(ksv, key_actions); |
| 191 |
123 |
| HR_add_actions_real(encap, encap_actions); |
| 192 |
123 |
| } |
| 193 |
|
| |
| 194 |
0 |
| void HRXSK_encap_link_value(SV *self, SV *value) |
| 195 |
|
| { |
| 196 |
|
| /*NOOP*/ |
| 197 |
0 |
| } |
| 198 |
|
| |
| 199 |
111 |
| void HRXSK_encap_weaken(SV *ksv_ref) |
| 200 |
|
| { |
| 201 |
111 |
| hrk_encap *ke = keptr_from_sv(SvRV(ksv_ref)); |
| 202 |
111 |
▶ | HR_DEBUG("Weakening encapsulated object reference"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Weakening encapsulated object reference"); |
111 |
0 |
111 |
| HR_DEBUG("Weakening encapsulated object reference"); |
0 |
111 |
111 |
|
| 203 |
111 |
| sv_rvweaken(ke->obj_ptr); |
| 204 |
111 |
| } |
| 205 |
|
| |
| 206 |
4 |
| UV HRXSK_encap_kstring(SV* ksv_ref) |
| 207 |
|
| { |
| 208 |
4 |
| hrk_encap *ke = keptr_from_sv(SvRV(ksv_ref)); |
| 209 |
4 |
| return (UV)SvRV(ke->obj_ptr); |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
1 |
| SV *HRXSK_encap_getencap(SV *ksv_ref) |
| 213 |
|
| { |
| 214 |
1 |
| hrk_encap *ke = keptr_from_sv(SvRV(ksv_ref)); |
| 215 |
|
| //die("Unsupported!"); |
| 216 |
1 |
| return newSVsv(ke->obj_ptr); |
| 217 |
|
| } |
| 218 |
|
| |
| 219 |
123 |
| SV* HRXSK_encap_new(char *package, SV* object, SV *table, SV* forward, SV* scalar_lookup) |
| 220 |
|
| { |
| 221 |
123 |
▶ | HR_DEBUG("Encap key"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Encap key"); |
123 |
0 |
123 |
| HR_DEBUG("Encap key"); |
0 |
123 |
123 |
|
| 222 |
123 |
| SV *ksv = mk_blessed_blob(package, sizeof(hrk_encap)); |
| 223 |
|
| |
| 224 |
123 |
▶ | if(!ksv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!ksv) { |
0 |
123 |
123 |
|
| 225 |
0 |
| die("couldn't create hrk_encap!"); |
| 226 |
|
| return NULL; |
| 227 |
|
| } |
| 228 |
123 |
| hrk_encap *keptr = keptr_from_sv(SvRV(ksv)); |
| 229 |
123 |
| keptr->obj_ptr = newRV_inc(SvRV(object)); |
| 230 |
123 |
| keptr->obj_paddr = (char*)SvRV(object); |
| 231 |
|
| |
| 232 |
123 |
| keptr->table = REF2TABLE(table); |
| 233 |
|
| |
| 234 |
|
| #ifdef HR_CONSTRUCTOR_STORES_KEY |
| 235 |
|
| mk_ptr_string(key_s, SvRV(object)); |
| 236 |
|
| HR_DEBUG("Have string key %s", key_s); |
| 237 |
|
| HR_DEBUG("Scalar lookup: %p", scalar_lookup); |
| 238 |
|
| |
| 239 |
|
| SV *self_hval = newSVsv(ksv); |
| 240 |
|
| sv_rvweaken(self_hval); |
| 241 |
|
| hv_store( REF2HASH(scalar_lookup), key_s, strlen(key_s), self_hval, 0); |
| 242 |
|
| #endif |
| 243 |
|
| |
| 244 |
123 |
| k_encap_wire_actions(ksv, object); |
| 245 |
|
| |
| 246 |
123 |
▶ | HR_DEBUG("Returning key %p", SvRV(ksv)); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Returning key %p", SvRV(ksv)); |
123 |
0 |
123 |
| HR_DEBUG("Returning key %p", SvRV(ksv)); |
0 |
123 |
123 |
|
| 247 |
123 |
| return ksv; |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
|
| |
| 251 |
|
| |
| 252 |
|
| static inline HV* |
| 253 |
0 |
| get_v_hashref(hrk_encap *ke, SV* value) |
| 254 |
|
| { |
| 255 |
0 |
| HR_Table_t table = ke->table; |
| 256 |
|
| SV *reverse; |
| 257 |
0 |
| get_hashes(table, |
| 258 |
|
| HR_HKEY_LOOKUP_REVERSE, &reverse, |
| 259 |
|
| HR_HKEY_LOOKUP_NULL); |
| 260 |
|
| |
| 261 |
0 |
▶ | if(!reverse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!reverse) { |
0 |
0 |
0 |
|
| 262 |
0 |
| return NULL; |
| 263 |
|
| } |
| 264 |
|
| |
| 265 |
0 |
▶ | HR_DEBUG("Have reverse!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Have reverse!"); |
0 |
0 |
0 |
| HR_DEBUG("Have reverse!"); |
0 |
0 |
0 |
|
| 266 |
0 |
| mk_ptr_string(vstring, SvRV(value)); |
| 267 |
0 |
| SV **privhash = hv_fetch(REF2HASH(reverse), vstring, strlen(vstring), 0); |
| 268 |
0 |
▶ | if(privhash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(privhash) { |
0 |
0 |
0 |
|
| 269 |
0 |
| return (HV*)SvRV(*privhash); |
| 270 |
|
| } else { |
| 271 |
0 |
▶ | HR_DEBUG("Can't get privhash from hv_fetch"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Can't get privhash from hv_fetch"); |
0 |
0 |
0 |
| HR_DEBUG("Can't get privhash from hv_fetch"); |
0 |
0 |
0 |
|
| 272 |
0 |
| return NULL; |
| 273 |
|
| } |
| 274 |
|
| } |
| 275 |
|
| |
| 276 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 277 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 278 |
|
| /// Scalar Key Functions /// |
| 279 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 280 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 281 |
|
| |
| 282 |
124 |
| SV* HRXSK_new(char *package, char *key, SV *forward, SV *scalar_lookup) |
| 283 |
|
| { |
| 284 |
|
| hrk_simple newkey; |
| 285 |
|
| |
| 286 |
124 |
| int keylen = strlen(key) + 1; |
| 287 |
124 |
| int bloblen = keylen + sizeof(newkey); |
| 288 |
|
| |
| 289 |
124 |
| SV *ksv = mk_blessed_blob(package, bloblen); |
| 290 |
|
| |
| 291 |
124 |
▶ | if(!ksv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!ksv) { |
0 |
124 |
124 |
|
| 292 |
0 |
| die("Couldn't create package!"); |
| 293 |
|
| return NULL; |
| 294 |
|
| } |
| 295 |
|
| |
| 296 |
|
| /* blob: [key data] [key string] */ |
| 297 |
124 |
| char *blob = SvPVX(SvRV(ksv)); |
| 298 |
124 |
| char *key_offset = blob + sizeof(newkey); |
| 299 |
|
| |
| 300 |
|
| /*Initialize the blob*/ |
| 301 |
124 |
▶ | Zero(blob, 1, hrk_simple); |
Branch: 1 branch
| Branch | True | False | Total |
| Zero(blob, 1, hrk_simple); |
0 |
124 |
124 |
|
| 302 |
124 |
▶ | Copy(key, key_offset, keylen, char); |
Branch: 2 branches
| Branch | True | False | Total |
| Copy(key, key_offset, keylen, char); |
0 |
124 |
124 |
| Copy(key, key_offset, keylen, char); |
0 |
124 |
124 |
|
| 303 |
|
| |
| 304 |
|
| #ifdef HR_CONSTRUCTOR_STORES_KEY |
| 305 |
|
| SV **scalar_entry = hv_store(REF2HASH(scalar_lookup), |
| 306 |
|
| key, keylen-1, |
| 307 |
|
| newSVsv(ksv), 0); |
| 308 |
|
| if(!scalar_entry) { |
| 309 |
|
| die("Couldn't add entry!"); |
| 310 |
|
| } |
| 311 |
|
| sv_rvweaken(*scalar_entry); |
| 312 |
|
| #endif |
| 313 |
|
| |
| 314 |
124 |
| HR_Action actions[] = { |
| 315 |
|
| HR_DREF_FLDS_Estr_from_hv(key_offset, scalar_lookup), |
| 316 |
|
| HR_DREF_FLDS_Estr_from_hv(key_offset, forward), |
| 317 |
|
| HR_ACTION_LIST_TERMINATOR |
| 318 |
|
| }; |
| 319 |
|
| |
| 320 |
124 |
| HR_add_actions_real(ksv, actions); |
| 321 |
124 |
| return ksv; |
| 322 |
|
| } |
| 323 |
|
| |
| 324 |
4 |
| char * HRXSK_kstring(SV *obj) |
| 325 |
|
| { |
| 326 |
4 |
| char *blob = ksimple_from_sv(SvRV(obj)); |
| 327 |
4 |
| char *ret = ksimple_strkey(blob); |
| 328 |
4 |
▶ | HR_DEBUG("Requested key=%s", ret); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Requested key=%s", ret); |
4 |
0 |
4 |
| HR_DEBUG("Requested key=%s", ret); |
0 |
4 |
4 |
|
| 329 |
4 |
| return ret; |
| 330 |
|
| } |
| 331 |
|
| |
| 332 |
1 |
| UV HRXSK_prefix_len(SV *obj) |
| 333 |
|
| { |
| 334 |
1 |
| return (ksimple_from_sv(SvRV(obj)))->prefix_len; |
| 335 |
|
| } |
| 336 |
|
| |
| 337 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 338 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 339 |
|
| /// Ref::Store API implementation (keys) /// |
| 340 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 341 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 342 |
482 |
| static inline SV* ukey2ikey( |
| 343 |
|
| SV* self, |
| 344 |
|
| SV* key, |
| 345 |
|
| SV** existing, /*PP: Argument to $options{O_EXCL}: $expected*/ |
| 346 |
|
| int options) |
| 347 |
|
| { |
| 348 |
482 |
| SV *slookup = NULL, *flookup = NULL; |
| 349 |
482 |
| SV *kobj = NULL; |
| 350 |
482 |
| SV *my_stashcache_ref = NULL; |
| 351 |
482 |
| HE *stored_key = NULL; |
| 352 |
|
| |
| 353 |
|
| HR_BlessParams stash_params; |
| 354 |
482 |
| int do_create = (options & STORE_OPT_O_CREAT); |
| 355 |
482 |
| int key_is_ref = SvROK(key); |
| 356 |
482 |
▶ | SV *our_key = (key_is_ref) ? newSVuv(SvUV(key)) : key; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *our_key = (key_is_ref) ? newSVuv(SvUV(key)) : key; |
236 |
246 |
482 |
|
| 357 |
482 |
| HE *stored_val = NULL; |
| 358 |
482 |
| char *kstring_p = NULL; |
| 359 |
|
| |
| 360 |
482 |
| get_hashes(REF2TABLE(self), |
| 361 |
|
| HR_HKEY_LOOKUP_SCALAR, &slookup, |
| 362 |
|
| HR_HKEY_LOOKUP_PRIVDATA, &my_stashcache_ref, |
| 363 |
|
| HR_HKEY_LOOKUP_FORWARD, &flookup, |
| 364 |
|
| HR_HKEY_LOOKUP_NULL); |
| 365 |
|
| |
| 366 |
482 |
▶ | HR_DEBUG("Using key %s", SvPV_nolen(our_key)); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Using key %s", SvPV_nolen(our_key)); |
480 |
2 |
482 |
| HR_DEBUG("Using key %s", SvPV_nolen(our_key)); |
0 |
482 |
482 |
|
| 367 |
|
| |
| 368 |
|
| /*PP: my $o = $self->scalar_lookup->{$ustr}; */ |
| 369 |
482 |
▶ | stored_key = hv_fetch_ent(REF2HASH(slookup), our_key, do_create, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| stored_key = hv_fetch_ent(REF2HASH(slookup), our_key, do_create, 0); |
248 |
234 |
482 |
|
| 370 |
|
| |
| 371 |
482 |
▶ | if(stored_key == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(stored_key == NULL) { |
11 |
471 |
482 |
|
| 372 |
11 |
▶ | HR_DEBUG("No key found and no creation requested"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("No key found and no creation requested"); |
11 |
0 |
11 |
| HR_DEBUG("No key found and no creation requested"); |
0 |
11 |
11 |
|
| 373 |
11 |
| goto GT_RET; /*No create requested*/ |
| 374 |
|
| } |
| 375 |
|
| |
| 376 |
471 |
| kobj = HeVAL(stored_key); |
| 377 |
471 |
▶ | if(SvROK(kobj)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvROK(kobj)) { |
224 |
247 |
471 |
|
| 378 |
|
| /*Have valid key, check if we have an existing pointer*/ |
| 379 |
224 |
▶ | if(existing) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(existing) { |
1 |
223 |
224 |
|
| 380 |
1 |
| stored_val = hv_fetch_ent(REF2HASH(flookup), our_key, 0, 0); |
| 381 |
1 |
▶ | if(!stored_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!stored_val) { |
0 |
1 |
1 |
|
| 382 |
0 |
| die("Found orphaned key without value"); |
| 383 |
|
| } |
| 384 |
1 |
▶ | if(SvRV(HeVAL(stored_val)) != SvRV(*existing)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvRV(HeVAL(stored_val)) != SvRV(*existing)) { |
1 |
0 |
1 |
|
| 385 |
2 |
| die("Requested key ('%s') for value=%p, but existing key " |
| 386 |
|
| "already stores %p", |
| 387 |
|
| SvPV_nolen(our_key), SvRV(HeVAL(stored_val)), SvRV(*existing)); |
| 388 |
|
| } |
| 389 |
0 |
| *existing = HeVAL(stored_val); |
| 390 |
0 |
▶ | HR_DEBUG("Have kobj=%p", SvRV(kobj)); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Have kobj=%p", SvRV(kobj)); |
0 |
0 |
0 |
| HR_DEBUG("Have kobj=%p", SvRV(kobj)); |
0 |
0 |
0 |
|
| 391 |
|
| } |
| 392 |
223 |
| goto GT_RET; |
| 393 |
|
| } |
| 394 |
|
| |
| 395 |
247 |
▶ | if(existing) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(existing) { |
247 |
0 |
247 |
|
| 396 |
247 |
| *existing = NULL; |
| 397 |
|
| } |
| 398 |
|
| /*New key creation*/ |
| 399 |
247 |
| blessparam_init(stash_params); |
| 400 |
247 |
▶ | if(key_is_ref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(key_is_ref) { |
123 |
124 |
247 |
|
| 401 |
123 |
| blessparam_setstash(stash_params, stash_from_cache_nocheck( |
| 402 |
|
| my_stashcache_ref, HR_STASH_KEY_ENCAP)); |
| 403 |
|
| |
| 404 |
123 |
| kobj = HRXSK_encap_new(blessparam2chrp(stash_params), |
| 405 |
|
| key, self, flookup, slookup); |
| 406 |
123 |
▶ | if( (options & STORE_OPT_STRONG_KEY) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (options & STORE_OPT_STRONG_KEY) == 0) { |
111 |
12 |
123 |
|
| 407 |
111 |
| HRXSK_encap_weaken(kobj); |
| 408 |
|
| } |
| 409 |
|
| } else { |
| 410 |
124 |
| blessparam_setstash(stash_params,stash_from_cache_nocheck( |
| 411 |
|
| my_stashcache_ref, HR_STASH_KEY_SCALAR)); |
| 412 |
|
| |
| 413 |
248 |
| kobj = HRXSK_new(blessparam2chrp(stash_params), |
| 414 |
|
| SvPV_nolen(our_key), flookup, slookup); |
| 415 |
|
| /*XS Simple key's weaken_encapsulated is nop*/ |
| 416 |
|
| } |
| 417 |
|
| |
| 418 |
|
| #ifndef HR_CONSTRUCTOR_STORES_KEY |
| 419 |
247 |
▶ | HR_DEBUG("Upgrading placeholder"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Upgrading placeholder"); |
247 |
0 |
247 |
| HR_DEBUG("Upgrading placeholder"); |
0 |
247 |
247 |
|
| 420 |
247 |
▶ | SvUPGRADE(HeVAL(stored_key), SVt_RV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(HeVAL(stored_key), SVt_RV); |
247 |
0 |
247 |
|
| 421 |
247 |
▶ | SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
Branch: 6 branches
| Branch | True | False | Total |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
247 |
247 |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
247 |
247 |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
0 |
0 |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
0 |
0 |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
247 |
247 |
| SvRV_set(HeVAL(stored_key), SvRV(kobj)); |
0 |
0 |
0 |
|
| 422 |
247 |
| SvROK_on(HeVAL(stored_key)); |
| 423 |
247 |
| SvREFCNT_inc(SvRV(kobj)); |
| 424 |
247 |
| sv_rvweaken(HeVAL(stored_key)); |
| 425 |
|
| #endif |
| 426 |
|
| |
| 427 |
481 |
| GT_RET: |
| 428 |
481 |
▶ | if(key_is_ref && our_key) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(key_is_ref && our_key) { |
236 |
245 |
481 |
| if(key_is_ref && our_key) { |
236 |
0 |
236 |
|
| 429 |
236 |
| SvREFCNT_dec(our_key); |
| 430 |
|
| } |
| 431 |
481 |
| return kobj; |
| 432 |
|
| } |
| 433 |
|
| |
| 434 |
|
| |
| 435 |
|
| |
| 436 |
|
| static inline void |
| 437 |
251 |
| store_helper(int *opt_p, SV **key_p, SV **vsv, char **prefix_p, int *prefix_len) |
| 438 |
|
| { |
| 439 |
251 |
| dXSARGS; |
| 440 |
251 |
| int opt_start = 3; |
| 441 |
|
| char *key_s; |
| 442 |
|
| |
| 443 |
251 |
▶ | if(!SvROK(*vsv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvROK(*vsv)) { |
4 |
247 |
251 |
|
| 444 |
4 |
▶ | if(items < 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(items < 3) { |
0 |
4 |
4 |
|
| 445 |
0 |
| die("Value must be reference"); |
| 446 |
|
| } |
| 447 |
|
| |
| 448 |
|
| else { |
| 449 |
4 |
▶ | if(!SvROK(*key_p)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvROK(*key_p)) { |
3 |
1 |
4 |
|
| 450 |
3 |
| *prefix_p = SvPV(*vsv, *prefix_len); |
| 451 |
3 |
▶ | if(!*prefix_p) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!*prefix_p) { |
0 |
3 |
3 |
|
| 452 |
0 |
| die("Couldn't get string key?"); |
| 453 |
|
| } |
| 454 |
3 |
| key_s = SvPV_nolen(*key_p); |
| 455 |
|
| |
| 456 |
3 |
| *key_p = newSVpvf("%s%s%s", |
| 457 |
|
| *prefix_p, HR_PREFIX_DELIM, key_s); |
| 458 |
|
| } else { |
| 459 |
1 |
| warn("Prefixed keys have no effect for object keys"); |
| 460 |
|
| } |
| 461 |
4 |
| *vsv = ST(3); |
| 462 |
4 |
| opt_start++; |
| 463 |
|
| } |
| 464 |
|
| } |
| 465 |
|
| |
| 466 |
251 |
▶ | if( (items - opt_start) % 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (items - opt_start) % 2 ) { |
0 |
251 |
251 |
|
| 467 |
0 |
| die("Odd number of option hash arguments"); |
| 468 |
|
| } |
| 469 |
|
| |
| 470 |
290 |
▶ | for(opt_start; opt_start < items; opt_start += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(opt_start; opt_start < items; opt_start += 2) { |
39 |
251 |
290 |
|
| 471 |
78 |
▶ | _chkopt(STRONG_VALUE, opt_start, (*opt_p)); |
Branch: 4 branches
| Branch | True | False | Total |
| _chkopt(STRONG_VALUE, opt_start, (*opt_p)); |
27 |
12 |
39 |
| _chkopt(STRONG_VALUE, opt_start, (*opt_p)); |
27 |
0 |
27 |
| _chkopt(STRONG_VALUE, opt_start, (*opt_p)); |
27 |
0 |
27 |
| _chkopt(STRONG_VALUE, opt_start, (*opt_p)); |
0 |
27 |
27 |
|
| 472 |
24 |
▶ | _chkopt(STRONG_KEY, opt_start, (*opt_p)); |
Branch: 4 branches
| Branch | True | False | Total |
| _chkopt(STRONG_KEY, opt_start, (*opt_p)); |
12 |
0 |
12 |
| _chkopt(STRONG_KEY, opt_start, (*opt_p)); |
12 |
0 |
12 |
| _chkopt(STRONG_KEY, opt_start, (*opt_p)); |
12 |
0 |
12 |
| _chkopt(STRONG_KEY, opt_start, (*opt_p)); |
0 |
12 |
12 |
|
| 473 |
|
| } |
| 474 |
251 |
▶ | XSRETURN(0); |
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN(0); |
0 |
251 |
251 |
|
| 475 |
|
| } |
| 476 |
|
| |
| 477 |
|
| |
| 478 |
4 |
| void HRA_store_kt(SV *self, SV *key, SV *t, SV *value, ...) |
| 479 |
|
| { |
| 480 |
|
| SV *kt_lookup; |
| 481 |
|
| HE *key_res; |
| 482 |
|
| |
| 483 |
4 |
| get_hashes(REF2TABLE(self), HR_HKEY_LOOKUP_KT, &kt_lookup, |
| 484 |
|
| HR_HKEY_LOOKUP_NULL); |
| 485 |
|
| |
| 486 |
4 |
| key_res = hv_fetch_ent(REF2HASH(kt_lookup), t, 0, 0); |
| 487 |
4 |
▶ | if(!key_res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!key_res) { |
0 |
4 |
4 |
|
| 488 |
0 |
| die("Couldn't fetch key for %s", SvPV_nolen(key)); |
| 489 |
|
| } |
| 490 |
|
| /*Value is unused, and is popped off the stack..*/ |
| 491 |
4 |
| HRA_store_sk(self, key, HeVAL(key_res)); |
| 492 |
4 |
| } |
| 493 |
|
| |
| 494 |
|
| /*The third argument is only the value for the perl-facing store/store_sk |
| 495 |
|
| functions. For store_kt, the value is actually the fourth argument, hence |
| 496 |
|
| the handling by store_helper() |
| 497 |
|
| */ |
| 498 |
|
| |
| 499 |
251 |
| void HRA_store_sk(SV *self, SV *key, SV *value, ...) |
| 500 |
|
| { |
| 501 |
251 |
| SV *flookup = NULL, *rlookup = NULL; //Lookup tables |
| 502 |
251 |
| SV *kobj = NULL, *kstring = NULL; // Key object and string |
| 503 |
251 |
| SV *vstring = NULL; //Value refaddr |
| 504 |
251 |
| SV *hval = NULL; //reference to store in the forward hash |
| 505 |
251 |
| SV *existing_ent = NULL; /* SV** to send/receive options for O_CREAT/O_EXCL*/ |
| 506 |
|
| SV *vhash; //Value's lookup references |
| 507 |
251 |
| char *prefix = NULL; |
| 508 |
251 |
| int prefix_len = 0; |
| 509 |
251 |
| int key_is_ref = SvROK(key); |
| 510 |
251 |
| int iopts = STORE_OPT_O_CREAT; |
| 511 |
|
| |
| 512 |
251 |
| store_helper(&iopts, &key, &value, &prefix, &prefix_len); |
| 513 |
251 |
| existing_ent = value; |
| 514 |
|
| |
| 515 |
251 |
| kobj = ukey2ikey(self, key, &existing_ent, iopts); |
| 516 |
|
| |
| 517 |
250 |
▶ | if(existing_ent) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(existing_ent) { |
3 |
247 |
250 |
|
| 518 |
3 |
▶ | HR_DEBUG("We're already stored"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("We're already stored"); |
3 |
0 |
3 |
| HR_DEBUG("We're already stored"); |
0 |
3 |
3 |
|
| 519 |
3 |
| goto GT_CLEANUP; |
| 520 |
|
| } |
| 521 |
|
| |
| 522 |
247 |
| vstring = newSVuv(SvUV(value)); |
| 523 |
247 |
| hval = newSVsv(value); |
| 524 |
|
| |
| 525 |
|
| /*Not stored yet*/ |
| 526 |
247 |
▶ | if(key_is_ref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(key_is_ref) { |
123 |
124 |
247 |
|
| 527 |
123 |
| kstring = newSVuv(SvUV(key)); |
| 528 |
123 |
| (ksimple_from_sv(SvRV(kobj)))->prefix_len = 0; |
| 529 |
|
| } else { |
| 530 |
124 |
| kstring = key; |
| 531 |
124 |
▶ | if(prefix_len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(prefix_len) { |
0 |
124 |
124 |
|
| 532 |
0 |
▶ | if(prefix_len > HR_PREFIX_LEN_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(prefix_len > HR_PREFIX_LEN_MAX) { |
0 |
0 |
0 |
|
| 533 |
0 |
| die("Prefixes longer than %d chars unsupported", HR_PREFIX_LEN_MAX); |
| 534 |
|
| } else { |
| 535 |
0 |
| (ksimple_from_sv(SvRV(kobj)))->prefix_len = prefix_len; |
| 536 |
|
| } |
| 537 |
|
| } |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
247 |
| get_hashes(REF2TABLE(self), |
| 541 |
|
| HR_HKEY_LOOKUP_FORWARD, &flookup, |
| 542 |
|
| HR_HKEY_LOOKUP_REVERSE, &rlookup, |
| 543 |
|
| HR_HKEY_LOOKUP_NULL); |
| 544 |
|
| /*Get value hashref*/ |
| 545 |
247 |
| vhash = get_vhash_from_rlookup(rlookup, vstring, 1); |
| 546 |
247 |
▶ | assert(vhash); |
Branch: 1 branch
| Branch | True | False | Total |
| assert(vhash); |
0 |
247 |
247 |
|
| 547 |
247 |
| hv_store_ent(REF2HASH(vhash), kstring, kobj, 0); |
| 548 |
|
| |
| 549 |
247 |
▶ | HR_DEBUG("Storing FLOOKUP{%s} (SV=%p) (RV=%p)", |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Storing FLOOKUP{%s} (SV=%p) (RV=%p)", |
247 |
0 |
247 |
| HR_DEBUG("Storing FLOOKUP{%s} (SV=%p) (RV=%p)", |
0 |
247 |
247 |
|
| 550 |
|
| SvPV_nolen(kstring), hval, SvRV(hval)); |
| 551 |
|
| |
| 552 |
247 |
| hv_store_ent(REF2HASH(flookup), kstring, hval, 0); |
| 553 |
|
| |
| 554 |
|
| /*PP: dref_add_ptr*/ |
| 555 |
247 |
| HR_PL_add_action_ptr(hval, rlookup); |
| 556 |
|
| |
| 557 |
|
| /*PP: if(!$options{StrongValue}) { weaken($self->forward->kstring)}*/ |
| 558 |
247 |
▶ | if( (iopts & STORE_OPT_STRONG_VALUE) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( (iopts & STORE_OPT_STRONG_VALUE) == 0) { |
27 |
220 |
247 |
|
| 559 |
220 |
▶ | HR_DEBUG("Weakening value"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Weakening value"); |
220 |
0 |
220 |
| HR_DEBUG("Weakening value"); |
0 |
220 |
220 |
|
| 560 |
220 |
| sv_rvweaken(hval); |
| 561 |
|
| } |
| 562 |
|
| |
| 563 |
27 |
| GT_CLEANUP: |
| 564 |
250 |
▶ | if(key_is_ref && kstring) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(key_is_ref && kstring) { |
123 |
127 |
250 |
| if(key_is_ref && kstring) { |
123 |
0 |
123 |
|
| 565 |
123 |
| SvREFCNT_dec(kstring); |
| 566 |
|
| } |
| 567 |
250 |
▶ | if(vstring) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(vstring) { |
247 |
3 |
250 |
|
| 568 |
247 |
| SvREFCNT_dec(vstring); |
| 569 |
|
| } |
| 570 |
250 |
▶ | if(prefix_len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(prefix_len) { |
3 |
247 |
250 |
|
| 571 |
3 |
| SvREFCNT_dec(key); |
| 572 |
|
| } |
| 573 |
250 |
| } |
| 574 |
|
| |
| 575 |
231 |
| SV *HRA_fetch_sk(SV *self, SV *key) |
| 576 |
|
| { |
| 577 |
231 |
| SV *kobj = ukey2ikey(self, key, NULL, 0); |
| 578 |
|
| SV *flookup; |
| 579 |
231 |
| SV *ret = NULL; |
| 580 |
231 |
▶ | if(!kobj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!kobj) { |
8 |
223 |
231 |
|
| 581 |
8 |
▶ | HR_DEBUG("Can't find key object!"); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Can't find key object!"); |
8 |
0 |
8 |
| HR_DEBUG("Can't find key object!"); |
0 |
8 |
8 |
|
| 582 |
8 |
| return &PL_sv_undef; |
| 583 |
|
| } |
| 584 |
223 |
| int key_is_ref = SvROK(key); |
| 585 |
223 |
▶ | key = (key_is_ref) ? newSVuv(SvUV(key)) : key; |
Branch: 1 branch
| Branch | True | False | Total |
| key = (key_is_ref) ? newSVuv(SvUV(key)) : key; |
112 |
111 |
223 |
|
| 586 |
223 |
| get_hashes(REF2TABLE(self), |
| 587 |
|
| HR_HKEY_LOOKUP_FORWARD, &flookup, |
| 588 |
|
| HR_HKEY_LOOKUP_NULL); |
| 589 |
|
| |
| 590 |
223 |
| HE *res = hv_fetch_ent(REF2HASH(flookup), key, 0, 0); |
| 591 |
223 |
▶ | if(res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(res) { |
223 |
0 |
223 |
|
| 592 |
223 |
▶ | HR_DEBUG("Got result for %p", key); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Got result for %p", key); |
223 |
0 |
223 |
| HR_DEBUG("Got result for %p", key); |
0 |
223 |
223 |
|
| 593 |
223 |
| ret = newSVsv(HeVAL(res)); |
| 594 |
|
| } else { |
| 595 |
0 |
▶ | HR_DEBUG("Nothing for %p", key); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Nothing for %p", key); |
0 |
0 |
0 |
| HR_DEBUG("Nothing for %p", key); |
0 |
0 |
0 |
|
| 596 |
|
| } |
| 597 |
223 |
▶ | HR_DEBUG("Refcount for key: %d", SvREFCNT(SvRV(kobj))); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Refcount for key: %d", SvREFCNT(SvRV(kobj))); |
223 |
0 |
223 |
| HR_DEBUG("Refcount for key: %d", SvREFCNT(SvRV(kobj))); |
0 |
223 |
223 |
|
| 598 |
223 |
▶ | if(key_is_ref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(key_is_ref) { |
112 |
111 |
223 |
|
| 599 |
112 |
| SvREFCNT_dec(key); |
| 600 |
|
| } |
| 601 |
223 |
| return ret; |
| 602 |
|
| } |
| 603 |
|
| |
| 604 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 605 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 606 |
|
| /// iThread Duplication Handlers /// |
| 607 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 608 |
|
| //////////////////////////////////////////////////////////////////////////////// |
| 609 |
0 |
| void HRA_ithread_store_lookup_info(SV *self, HV *ptr_map) |
| 610 |
|
| { |
| 611 |
0 |
| hr_dup_store_old_lookups(ptr_map, REF2TABLE(self)); |
| 612 |
0 |
| } |
| 613 |
|
| |
| 614 |
0 |
| void HRXSK_encap_ithread_predup(SV *self, SV *table, HV *ptr_map, SV *value) |
| 615 |
|
| { |
| 616 |
0 |
| hrk_encap *ke = keptr_from_sv(SvRV(self)); |
| 617 |
0 |
| HR_Dup_Kinfo *ki = hr_dup_store_kinfo(ptr_map, HR_DUPKEY_KENCAP, |
| 618 |
|
| ke->obj_paddr, 0); |
| 619 |
|
| |
| 620 |
0 |
▶ | if(SvWEAKREF(ke->obj_ptr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvWEAKREF(ke->obj_ptr)) { |
0 |
0 |
0 |
|
| 621 |
0 |
| ki->flags = HRK_DUP_WEAK_ENCAP; |
| 622 |
|
| } else { |
| 623 |
0 |
| ki->flags = 0; |
| 624 |
|
| } |
| 625 |
|
| |
| 626 |
0 |
| HV *vhash = get_v_hashref(ke, value); |
| 627 |
0 |
| ki->vhash = vhash; |
| 628 |
|
| |
| 629 |
0 |
| hr_dup_store_rv(ptr_map, ke->obj_ptr); |
| 630 |
0 |
| } |
| 631 |
|
| |
| 632 |
0 |
| void HRXSK_encap_ithread_postdup(SV *newself, SV *newtable, HV *ptr_map, UV old_table) |
| 633 |
|
| { |
| 634 |
0 |
| hrk_encap *ke = keptr_from_sv(SvRV(newself)); |
| 635 |
|
| |
| 636 |
0 |
| HR_Dup_OldLookups *old_lookups = hr_dup_get_old_lookups(ptr_map, ke->table); |
| 637 |
0 |
| HR_Dup_Kinfo *ki = hr_dup_get_kinfo(ptr_map, HR_DUPKEY_KENCAP, ke->obj_paddr); |
| 638 |
|
| |
| 639 |
0 |
▶ | HR_DEBUG("Old vhash was %p, old obj_paddr was %p", ki->vhash, ke->obj_paddr); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Old vhash was %p, old obj_paddr was %p", ki->vhash, ke->obj_paddr); |
0 |
0 |
0 |
| HR_DEBUG("Old vhash was %p, old obj_paddr was %p", ki->vhash, ke->obj_paddr); |
0 |
0 |
0 |
|
| 640 |
|
| |
| 641 |
0 |
| SV *new_encap = hr_dup_newsv_for_oldsv(ptr_map, ke->obj_paddr, 0); |
| 642 |
0 |
| k_encap_wire_actions(newself, new_encap); |
| 643 |
0 |
| ke->obj_paddr = SvRV(new_encap); |
| 644 |
0 |
| ke->obj_ptr = newSVsv(new_encap); |
| 645 |
0 |
▶ | if(ki->flags & HRK_DUP_WEAK_ENCAP) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(ki->flags & HRK_DUP_WEAK_ENCAP) { |
0 |
0 |
0 |
|
| 646 |
0 |
| sv_rvweaken(ke->obj_ptr); |
| 647 |
|
| } |
| 648 |
0 |
| ke->table = SvRV(newtable); |
| 649 |
0 |
▶ | HR_DEBUG("Reassigned %p", SvRV(newtable)); |
Branch: 2 branches
| Branch | True | False | Total |
| HR_DEBUG("Reassigned %p", SvRV(newtable)); |
0 |
0 |
0 |
| HR_DEBUG("Reassigned %p", SvRV(newtable)); |
0 |
0 |
0 |
|
| 650 |
0 |
| } |
| 651 |
|
| |
| 652 |
|
| |
| 653 |
|
| /*Postdup for simple keys*/ |
| 654 |
0 |
| void HRXSK_ithread_postdup(SV *newself, SV *newtable, HV *ptr_map, UV old_table) |
| 655 |
|
| { |
| 656 |
0 |
| hrk_simple *ksp = ksimple_from_sv(SvRV(newself)); |
| 657 |
|
| |
| 658 |
0 |
| char *key = ksimple_strkey(ksp); |
| 659 |
|
| SV *slookup, *flookup; |
| 660 |
|
| |
| 661 |
0 |
| get_hashes(REF2TABLE(newtable), |
| 662 |
|
| HR_HKEY_LOOKUP_SCALAR, &slookup, |
| 663 |
|
| HR_HKEY_LOOKUP_FORWARD, &flookup, |
| 664 |
|
| HR_HKEY_LOOKUP_NULL); |
| 665 |
|
| |
| 666 |
0 |
| HR_Action key_actions[] = { |
| 667 |
|
| HR_DREF_FLDS_Estr_from_hv(key, slookup), |
| 668 |
|
| HR_DREF_FLDS_Estr_from_hv(key, flookup), |
| 669 |
|
| HR_ACTION_LIST_TERMINATOR |
| 670 |
|
| }; |
| 671 |
0 |
| HR_add_actions_real(newself, key_actions); |
| 672 |
0 |
| } |