| 1 |
|
| # Test doors onto the context core. Each begins with an underscore and is |
| 2 |
|
| # documented nowhere: they are how t/ reaches the core before there is a |
| 3 |
|
| # public way to, and how it counts what a leak would leave behind. |
| 4 |
|
| # |
| 5 |
|
| # A context is handed to Perl here as a bare address. That is safe only |
| 6 |
|
| # because a test holds it for a few lines and gives it back; the public |
| 7 |
|
| # object arrives with its own class. |
| 8 |
|
| |
| 9 |
|
| MODULE = Context::Vars PACKAGE = Context::Vars |
| 10 |
|
| |
| 11 |
|
| IV |
| 12 |
|
| _selftest_core() |
| 13 |
|
| CODE: |
| 14 |
2 |
▶ | RETVAL = (IV)context_vars_ctx_selftest(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (IV)context_vars_ctx_selftest(aTHX); |
0 |
2 |
2 |
|
| 15 |
|
| OUTPUT: |
| 16 |
|
| RETVAL |
| 17 |
|
| |
| 18 |
|
| # Holders handed out and not yet given back. The empty context is not one. |
| 19 |
|
| IV |
| 20 |
|
| _live_holders() |
| 21 |
|
| CODE: |
| 22 |
|
| { |
| 23 |
|
| dMY_CXT; |
| 24 |
49 |
▶ | RETVAL = MY_CXT.live; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.live; |
23 |
26 |
49 |
|
| 25 |
|
| } |
| 26 |
|
| OUTPUT: |
| 27 |
|
| RETVAL |
| 28 |
|
| |
| 29 |
|
| # Enters whose restore has not run. |
| 30 |
|
| IV |
| 31 |
|
| _depth() |
| 32 |
|
| CODE: |
| 33 |
|
| { |
| 34 |
|
| dMY_CXT; |
| 35 |
52 |
▶ | RETVAL = MY_CXT.depth; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.depth; |
23 |
29 |
52 |
|
| 36 |
|
| } |
| 37 |
|
| OUTPUT: |
| 38 |
|
| RETVAL |
| 39 |
|
| |
| 40 |
|
| # References held on the empty context. Each capture taken with nothing |
| 41 |
|
| # entered is one. |
| 42 |
|
| UV |
| 43 |
|
| _empty_refcnt() |
| 44 |
|
| CODE: |
| 45 |
|
| { |
| 46 |
|
| dMY_CXT; |
| 47 |
2 |
▶ | RETVAL = MY_CXT.empty->refcnt; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.empty->refcnt; |
0 |
2 |
2 |
|
| 48 |
|
| } |
| 49 |
|
| OUTPUT: |
| 50 |
|
| RETVAL |
| 51 |
|
| |
| 52 |
|
| IV |
| 53 |
|
| _free_holders() |
| 54 |
|
| CODE: |
| 55 |
|
| { |
| 56 |
|
| dMY_CXT; |
| 57 |
1 |
▶ | RETVAL = MY_CXT.free_n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.free_n; |
0 |
1 |
1 |
|
| 58 |
|
| } |
| 59 |
|
| OUTPUT: |
| 60 |
|
| RETVAL |
| 61 |
|
| |
| 62 |
|
| UV |
| 63 |
|
| _t_current() |
| 64 |
|
| CODE: |
| 65 |
25 |
▶ | RETVAL = PTR2UV(context_vars_current(aTHX)); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PTR2UV(context_vars_current(aTHX)); |
22 |
3 |
25 |
|
| 66 |
|
| OUTPUT: |
| 67 |
|
| RETVAL |
| 68 |
|
| |
| 69 |
|
| int |
| 70 |
|
| _t_is_empty() |
| 71 |
|
| CODE: |
| 72 |
4 |
| RETVAL = context_vars_is_empty(aTHX_ context_vars_current(aTHX)); |
| 73 |
|
| OUTPUT: |
| 74 |
|
| RETVAL |
| 75 |
|
| |
| 76 |
|
| UV |
| 77 |
|
| _t_count() |
| 78 |
|
| CODE: |
| 79 |
15 |
| RETVAL = (UV)context_vars_count(aTHX); |
| 80 |
|
| OUTPUT: |
| 81 |
|
| RETVAL |
| 82 |
|
| |
| 83 |
|
| # A copy of the stored value, or undef when the name is not set. The second |
| 84 |
|
| # return says which, since a stored undef and no value read the same. |
| 85 |
|
| void |
| 86 |
|
| _t_fetch(name) |
| 87 |
|
| SV *name |
| 88 |
|
| PPCODE: |
| 89 |
|
| { |
| 90 |
|
| STRLEN len; |
| 91 |
263 |
| const char *p = SvPV(name, len); |
| 92 |
263 |
| SV *sv = context_vars_fetch(aTHX_ p, len); |
| 93 |
263 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
263 |
263 |
|
| 94 |
263 |
▶ | PUSHs(sv ? sv_2mortal(newSVsv(sv)) : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sv ? sv_2mortal(newSVsv(sv)) : &PL_sv_undef); |
254 |
9 |
263 |
|
| 95 |
263 |
▶ | PUSHs(sv ? &PL_sv_yes : &PL_sv_no); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sv ? &PL_sv_yes : &PL_sv_no); |
254 |
9 |
263 |
|
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
|
| void |
| 99 |
|
| _t_store(name, value) |
| 100 |
|
| SV *name |
| 101 |
|
| SV *value |
| 102 |
|
| CODE: |
| 103 |
|
| { |
| 104 |
|
| STRLEN len; |
| 105 |
722 |
| const char *p = SvPV(name, len); |
| 106 |
|
| dMY_CXT; |
| 107 |
722 |
▶ | if (MY_CXT.depth > 0) context_vars_writable(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.depth > 0) context_vars_writable(aTHX); |
721 |
1 |
722 |
|
| 108 |
722 |
| context_vars_store(aTHX_ p, len, value); |
| 109 |
|
| } |
| 110 |
|
| |
| 111 |
|
| void |
| 112 |
|
| _t_remove(name) |
| 113 |
|
| SV *name |
| 114 |
|
| CODE: |
| 115 |
|
| { |
| 116 |
|
| STRLEN len; |
| 117 |
5 |
| const char *p = SvPV(name, len); |
| 118 |
|
| dMY_CXT; |
| 119 |
5 |
▶ | if (MY_CXT.depth > 0) context_vars_writable(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.depth > 0) context_vars_writable(aTHX); |
4 |
1 |
5 |
|
| 120 |
5 |
| context_vars_remove(aTHX_ p, len); |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
|
| # Runs the code in a fresh context onto the current one. A die in the code |
| 124 |
|
| # goes straight through this frame: nothing here catches it, so the only |
| 125 |
|
| # thing that can put the context back is the save stack. |
| 126 |
|
| void |
| 127 |
|
| _t_scope(code) |
| 128 |
|
| SV *code |
| 129 |
|
| CODE: |
| 130 |
|
| { |
| 131 |
226 |
| dSP; |
| 132 |
226 |
| ENTER; |
| 133 |
226 |
| context_vars_scope(aTHX); |
| 134 |
226 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
226 |
226 |
|
| 135 |
226 |
| PUTBACK; |
| 136 |
226 |
| call_sv(code, G_DISCARD | G_VOID); |
| 137 |
223 |
| LEAVE; |
| 138 |
|
| } |
| 139 |
|
| |
| 140 |
|
| # What the current context holds, kept. The caller gives it back to |
| 141 |
|
| # _t_release exactly once. |
| 142 |
|
| UV |
| 143 |
|
| _t_capture() |
| 144 |
|
| CODE: |
| 145 |
209 |
▶ | RETVAL = PTR2UV(context_vars_capture(aTHX)); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PTR2UV(context_vars_capture(aTHX)); |
1 |
208 |
209 |
|
| 146 |
|
| OUTPUT: |
| 147 |
|
| RETVAL |
| 148 |
|
| |
| 149 |
|
| void |
| 150 |
|
| _t_release(addr) |
| 151 |
|
| UV addr |
| 152 |
|
| CODE: |
| 153 |
209 |
| context_vars_release(aTHX_ INT2PTR(context_vars_ctx *, addr)); |
| 154 |
|
| |
| 155 |
|
| # Runs the code with the kept context itself current. |
| 156 |
|
| void |
| 157 |
|
| _t_enter(addr, code) |
| 158 |
|
| UV addr |
| 159 |
|
| SV *code |
| 160 |
|
| CODE: |
| 161 |
|
| { |
| 162 |
16 |
| dSP; |
| 163 |
16 |
| ENTER; |
| 164 |
16 |
| context_vars_enter(aTHX_ INT2PTR(context_vars_ctx *, addr)); |
| 165 |
16 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
16 |
16 |
|
| 166 |
16 |
| PUTBACK; |
| 167 |
16 |
| call_sv(code, G_DISCARD | G_VOID); |
| 168 |
15 |
| LEAVE; |
| 169 |
|
| } |
| 170 |
|
| |
| 171 |
|
| # Runs the code in a fresh context onto the kept one. |
| 172 |
|
| void |
| 173 |
|
| _t_enter_copy(addr, code) |
| 174 |
|
| UV addr |
| 175 |
|
| SV *code |
| 176 |
|
| CODE: |
| 177 |
|
| { |
| 178 |
204 |
| dSP; |
| 179 |
204 |
| ENTER; |
| 180 |
204 |
| context_vars_enter_copy(aTHX_ INT2PTR(context_vars_ctx *, addr)); |
| 181 |
204 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
204 |
204 |
|
| 182 |
204 |
| PUTBACK; |
| 183 |
204 |
| call_sv(code, G_DISCARD | G_VOID); |
| 184 |
204 |
| LEAVE; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
|
| # 1 when the sub opens a scope with its first statement, 2 when with an op of |
| 188 |
|
| # its own, 0 when it opens none. |
| 189 |
|
| int |
| 190 |
|
| _scope_kind(code) |
| 191 |
|
| SV *code |
| 192 |
|
| CODE: |
| 193 |
68 |
▶ | RETVAL = (SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV) |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = (SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV) |
34 |
0 |
34 |
| RETVAL = (SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV) |
23 |
11 |
34 |
|
| 194 |
68 |
▶ | ? context_vars_scope_kind((CV *)SvRV(code)) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| ? context_vars_scope_kind((CV *)SvRV(code)) : 0; |
34 |
0 |
34 |
|
| 195 |
|
| OUTPUT: |
| 196 |
|
| RETVAL |
| 197 |
|
| |
| 198 |
|
| # Scopes opened in this interpreter, by any means. |
| 199 |
|
| IV |
| 200 |
|
| _scopes() |
| 201 |
|
| CODE: |
| 202 |
|
| { |
| 203 |
|
| dMY_CXT; |
| 204 |
26 |
▶ | RETVAL = MY_CXT.scopes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.scopes; |
18 |
8 |
26 |
|
| 205 |
|
| } |
| 206 |
|
| OUTPUT: |
| 207 |
|
| RETVAL |
| 208 |
|
| |
| 209 |
|
| # True once the async hooks are registered with Future::AsyncAwait. |
| 210 |
|
| int |
| 211 |
|
| _async_hooks() |
| 212 |
|
| CODE: |
| 213 |
0 |
▶ | RETVAL = context_vars_faa_registered; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = context_vars_faa_registered; |
0 |
0 |
0 |
|
| 214 |
|
| OUTPUT: |
| 215 |
|
| RETVAL |
| 216 |
|
| |
| 217 |
|
| # For bench/: `n` turns of what a loop does for one callback, in C, with no |
| 218 |
|
| # Perl call: capture, enter a copy inside ENTER and LEAVE, release. With |
| 219 |
|
| # `kind` 0, only the ENTER and LEAVE, to subtract. |
| 220 |
|
| void |
| 221 |
|
| _bench_cycle(n, kind) |
| 222 |
|
| IV n |
| 223 |
|
| int kind |
| 224 |
|
| CODE: |
| 225 |
|
| { |
| 226 |
|
| IV i; |
| 227 |
0 |
▶ | if (kind == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (kind == 0) { |
0 |
0 |
0 |
|
| 228 |
0 |
▶ | for (i = 0; i < n; i++) { ENTER; LEAVE; } |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { ENTER; LEAVE; } |
0 |
0 |
0 |
|
| 229 |
|
| } |
| 230 |
|
| else { |
| 231 |
0 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
0 |
0 |
0 |
|
| 232 |
0 |
| context_vars_ctx *c = context_vars_capture(aTHX); |
| 233 |
0 |
| ENTER; |
| 234 |
0 |
| context_vars_enter_copy(aTHX_ c); |
| 235 |
0 |
| LEAVE; |
| 236 |
0 |
| context_vars_release(aTHX_ c); |
| 237 |
|
| } |
| 238 |
|
| } |
| 239 |
|
| } |