| 1 |
|
| MODULE = Punk PACKAGE = Punk |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # Address of Punk's own C ABI table (pk_abi.h). A consumer XS module fetches |
| 6 |
|
| # this once at boot, INT2PTRs it to a `const pk_abi *`, and checks |
| 7 |
|
| # ->abi_version before using it. Not part of the public Perl API. |
| 8 |
|
| # |
| 9 |
|
| # Unsigned, not IV: where the loader maps this object decides the sign bit. |
| 10 |
|
| # A 32-bit perl above 0x7fffffff, or illumos putting shared objects up at |
| 11 |
|
| # 0xfffffd7f..., would hand back a negative number from PTR2IV. |
| 12 |
|
| UV |
| 13 |
|
| _abi_ptr() |
| 14 |
|
| CODE: |
| 15 |
1 |
▶ | RETVAL = PTR2UV(&PK_ABI); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PTR2UV(&PK_ABI); |
0 |
1 |
1 |
|
| 16 |
|
| OUTPUT: |
| 17 |
|
| RETVAL |
| 18 |
|
| |
| 19 |
|
| # ---- the self-test consumer ------------------------------------------------- |
| 20 |
|
| # |
| 21 |
|
| # Exercise the whole pk_abi table the way a C consumer would - register through |
| 22 |
|
| # the table's own on_request/on_response, then read the request back through |
| 23 |
|
| # its accessors - so the test suite proves the FUNCTION POINTERS work and not |
| 24 |
|
| # just the static functions behind them. Open::API's _abi_selftest is the same |
| 25 |
|
| # idea. Private. |
| 26 |
|
| |
| 27 |
|
| # Install the observers, once. Returns 1 when both registered. |
| 28 |
|
| IV |
| 29 |
|
| _abi_selftest_install() |
| 30 |
|
| CODE: |
| 31 |
|
| { |
| 32 |
3 |
| const pk_abi *A = INT2PTR(const pk_abi *, PTR2IV(&PK_ABI)); |
| 33 |
3 |
▶ | if (!A || A->abi_version != PK_ABI_VERSION) XSRETURN_IV(0); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!A || A->abi_version != PK_ABI_VERSION) XSRETURN_IV(0); |
3 |
0 |
3 |
| if (!A || A->abi_version != PK_ABI_VERSION) XSRETURN_IV(0); |
0 |
3 |
3 |
|
| 34 |
3 |
▶ | if (PK_SELFTEST_ON) XSRETURN_IV(1); /* idempotent */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (PK_SELFTEST_ON) XSRETURN_IV(1); /* idempotent */ |
1 |
2 |
3 |
|
| 35 |
2 |
| PK_SELFTEST_ON = |
| 36 |
2 |
| A->on_request(aTHX_ pk_selftest_req, NULL) |
| 37 |
2 |
▶ | && A->on_response(aTHX_ pk_selftest_res, NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| && A->on_response(aTHX_ pk_selftest_res, NULL) |
2 |
0 |
2 |
|
| 38 |
4 |
▶ | && A->on_query(aTHX_ pk_selftest_query, pk_selftest_query_done, |
Branch: 2 branches
| Branch | True | False | Total |
| && A->on_query(aTHX_ pk_selftest_query, pk_selftest_query_done, |
2 |
0 |
2 |
| && A->on_query(aTHX_ pk_selftest_query, pk_selftest_query_done, |
2 |
0 |
2 |
|
| 39 |
|
| NULL); |
| 40 |
2 |
▶ | RETVAL = PK_SELFTEST_ON; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PK_SELFTEST_ON; |
0 |
2 |
2 |
|
| 41 |
|
| } |
| 42 |
|
| OUTPUT: |
| 43 |
|
| RETVAL |
| 44 |
|
| |
| 45 |
|
| # Everything the observers recorded since the last call, and reset. |
| 46 |
|
| # An arrayref of hashrefs; see pk_selftest_event in punk_obs_selftest.h. |
| 47 |
|
| SV * |
| 48 |
|
| _abi_selftest_events() |
| 49 |
|
| CODE: |
| 50 |
|
| { |
| 51 |
39 |
| AV *ev = pk_selftest_av(aTHX); |
| 52 |
39 |
| AV *out = newAV(); |
| 53 |
39 |
| SSize_t i, n = av_len(ev) + 1; |
| 54 |
79 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
40 |
39 |
79 |
|
| 55 |
40 |
| SV **e = av_fetch(ev, i, 0); |
| 56 |
40 |
▶ | if (e && *e) av_push(out, newSVsv(*e)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (e && *e) av_push(out, newSVsv(*e)); |
40 |
0 |
40 |
| if (e && *e) av_push(out, newSVsv(*e)); |
40 |
0 |
40 |
|
| 57 |
|
| } |
| 58 |
39 |
| av_clear(ev); |
| 59 |
39 |
| RETVAL = newRV_noinc((SV *)out); |
| 60 |
|
| } |
| 61 |
|
| OUTPUT: |
| 62 |
|
| RETVAL |
| 63 |
|
| |
| 64 |
|
| # v5 current_of, read THROUGH the table. Returns the context of the dispatch |
| 65 |
|
| # frame running right now, or undef. |
| 66 |
|
| # |
| 67 |
|
| # A copy of the reference, not the context: the test compares what it addresses |
| 68 |
|
| # (refaddr) against the $c its handler was given, which is the only check that |
| 69 |
|
| # tells "the current context" apart from "a current context". |
| 70 |
|
| SV * |
| 71 |
|
| _abi_current() |
| 72 |
|
| CODE: |
| 73 |
|
| { |
| 74 |
12 |
| const pk_abi *A = INT2PTR(const pk_abi *, PTR2IV(&PK_ABI)); |
| 75 |
12 |
▶ | SV *c = (A && A->abi_version >= 5) ? A->current_of(aTHX) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *c = (A && A->abi_version >= 5) ? A->current_of(aTHX) : NULL; |
12 |
0 |
12 |
| SV *c = (A && A->abi_version >= 5) ? A->current_of(aTHX) : NULL; |
12 |
0 |
12 |
|
| 76 |
12 |
▶ | if (!c) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!c) XSRETURN_UNDEF; |
7 |
5 |
12 |
|
| 77 |
5 |
| RETVAL = newSVsv(c); |
| 78 |
|
| } |
| 79 |
|
| OUTPUT: |
| 80 |
|
| RETVAL |
| 81 |
|
| |
| 82 |
|
| # v2 on_query: (starts, dones, ok, nbind, sql) since load. |
| 83 |
|
| void |
| 84 |
|
| _abi_selftest_queries() |
| 85 |
|
| PPCODE: |
| 86 |
26 |
▶ | EXTEND(SP, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 5); |
0 |
26 |
26 |
|
| 87 |
26 |
| mPUSHi(PK_SELFTEST_Q_STARTS); |
| 88 |
26 |
| mPUSHi(PK_SELFTEST_Q_DONES); |
| 89 |
26 |
| mPUSHi(PK_SELFTEST_Q_OK); |
| 90 |
26 |
| mPUSHi(PK_SELFTEST_Q_BIND); |
| 91 |
26 |
| mPUSHp(PK_SELFTEST_Q_SQL, strlen(PK_SELFTEST_Q_SQL)); |