xs/test.xs

filter: Statementstmt 100% 31 / 31 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.3% 36 / 39 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hamt/hamt_ops.h ↑ Summary xs/set_transient.xs »
1 # Doors for the tests and for nobody else. Each name starts with an
2 # underscore, none is documented, and any may change in any release.
3  
4 MODULE = HAMT PACKAGE = HAMT
5  
6 # Pin the seed, so a test can ask for the same layout twice.
7 void
8 _seed(n)
9 UV n
10 CODE:
11 3 hamt_seed = (uint64_t)n;
12  
13 # Keep only the low `bits` bits of every hash from here on: 0 makes every key
14 # collide, 5 fills one level and then collides. 64 puts the whole hash back.
15 # A container built under one setting must not be read under another.
16 void
17 _hash_bits(bits)
18 UV bits
19 CODE:
20 46 ▶ hamt_hash_set_bits(bits > 64 ? 64 : (unsigned)bits);
Branch: 1 branch
BranchTrueFalseTotal
hamt_hash_set_bits(bits > 64 ? 64 : (unsigned)bits); 45 1 46
21  
22 # The hash of a key that has already been through the key rule, as sixteen
23 # hex digits: a 64-bit number does not fit an IV on every perl.
24 SV *
25 _hash_of(bytes, utf8 = 0)
26 SV *bytes
27 int utf8
28 PREINIT:
29 STRLEN len;
30 const char *p;
31 uint64_t h;
32 CODE:
33 1217 p = SvPVbyte(bytes, len);
34 1217 h = hamt_hash(p, (size_t)len, utf8);
35 1217 RETVAL = newSVpvf("%08lx%08lx",
36 (unsigned long)(h >> 32),
37 (unsigned long)(h & 0xffffffffUL));
38 OUTPUT:
39 RETVAL
40  
41 # An entry made and released in C, reporting what it held on the way: the
42 # key's length, its flag, and whether the key compares equal to itself and
43 # unequal to the same bytes under the other flag. The value's reference count
44 # is the caller's to check before and after.
45 void
46 _entry_probe(bytes, utf8, value)
47 SV *bytes
48 int utf8
49 SV *value
50 PREINIT:
51 STRLEN len;
52 const char *p;
53 uint64_t h;
54 hamt_entry *e;
55 IV held, self_eq, flag_eq;
56 PPCODE:
57 5 p = SvPVbyte(bytes, len);
58 5 h = hamt_hash(p, (size_t)len, utf8);
59 5 e = hamt_entry_new(HAMT_CX, p, (size_t)len, utf8, h, (void *)value);
60 5 ▶ if (!e) croak("HAMT::_entry_probe: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!e) croak("HAMT::_entry_probe: out of memory"); 0 5 5
61 5 hamt_entry_retain(e);
62 5 hamt_entry_release(HAMT_CX, e);
63 5 held = (IV)SvREFCNT(value);
64 5 self_eq = hamt_entry_key_eq(e, p, (size_t)len, utf8, h);
65 5 flag_eq = hamt_entry_key_eq(e, p, (size_t)len, !utf8,
66 hamt_hash(p, (size_t)len, !utf8));
67 5 hamt_entry_release(HAMT_CX, e);
68 5 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 5 5
69 5 mPUSHi(held);
70 5 mPUSHi(self_eq);
71 5 mPUSHi(flag_eq);
72  
73 # An object blessed into `klass` that carries ext magic, but not this
74 # library's: what a handle from some other extension looks like. Every
75 # method has to refuse it, since its magic points at somebody else's struct.
76 void
77 _foreign_handle(klass)
78 SV *klass
79 PREINIT:
80 static MGVTBL other = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
81 static char payload[64];
82 SV *inner, *rv;
83 CODE:
84 3 inner = newSV(0);
85 3 sv_magicext(inner, NULL, PERL_MAGIC_ext, &other, payload, 0);
86 3 rv = sv_2mortal(newRV_noinc(inner));
87 3 sv_bless(rv, gv_stashsv(klass, GV_ADD));
88 3 ST(0) = rv;
89 3 XSRETURN(1);
90  
91 # How many temporaries perl is holding right now. A walk that calls a sub
92 # for every entry must not let this grow with the walk.
93 void
94 _tmps_ix()
95 CODE:
96 4500 ST(0) = sv_2mortal(newSViv((IV)PL_tmps_ix));
97 4500 XSRETURN(1);
98  
99 # How many blocks the library holds: every node, every entry, every handle's
100 # struct. Back to where it started means nothing was leaked.
101 void
102 _live_blocks()
103 CODE:
104 33 ST(0) = sv_2mortal(newSViv((IV)hamt_live_blocks));
105 33 XSRETURN(1);
106  
107 # How many freed blocks the allocator is holding for reuse. -1 in a build
108 # that has no pool, and -2 in one that has but where it is not open, which
109 # is a fault and must not read as the first.
110 void
111 _pool_held()
112 CODE:
113 #ifndef HAMT_NO_POOL
114 20005 ▶ ST(0) = sv_2mortal(newSViv(hamt_pool_one.open
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = sv_2mortal(newSViv(hamt_pool_one.open 20005 0 20005
115 ? (IV)hamt_pool_held(&hamt_pool_one) : -2));
116 #else
117 ST(0) = sv_2mortal(newSViv(-1));
118 #endif
119 20005 XSRETURN(1);
« include/hamt/hamt_ops.h ↑ Summary xs/set_transient.xs »