| 1 |
|
| #ifndef PQ_HM_H |
| 2 |
|
| #define PQ_HM_H |
| 3 |
|
| |
| 4 |
|
| /* The Hyperman C ABI, resolved lazily and optionally. |
| 5 |
|
| * |
| 6 |
|
| * Hyperman is a SOFT dependency: the worker has a complete poll(2) path |
| 7 |
|
| * without it, and the loop's only job is letting task code await futures in |
| 8 |
|
| * loop mode. Hence the DBIx::Loop consumption pattern rather than Punk's - |
| 9 |
|
| * a vendored include/hm_abi.h pinned at version 2 and no build-time |
| 10 |
|
| * dependency at all, resolved at runtime through Hyperman::_abi_ptr with a |
| 11 |
|
| * `>=` gate (hm_abi documents its table as append-only, so a newer provider |
| 12 |
|
| * keeps working against our older header). |
| 13 |
|
| * |
| 14 |
|
| * pq_hm() returns NULL to degrade, never croaks. PUNK_QUEUE_NO_HM_ABI=1 |
| 15 |
|
| * forces NULL, which is the test seam for the degraded path. |
| 16 |
|
| * |
| 17 |
|
| * Include after pq_compat.h and hm_abi.h. */ |
| 18 |
|
| |
| 19 |
|
| static const hm_abi *PQ_HM = NULL; |
| 20 |
|
| static int PQ_HM_TRIED = 0; |
| 21 |
|
| |
| 22 |
90 |
| static const hm_abi *pq_hm(pTHX) { |
| 23 |
90 |
▶ | if (!PQ_HM && !PQ_HM_TRIED) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!PQ_HM && !PQ_HM_TRIED) { |
42 |
48 |
90 |
| if (!PQ_HM && !PQ_HM_TRIED) { |
27 |
15 |
42 |
|
| 24 |
27 |
| dSP; int count; IV p = 0; |
| 25 |
27 |
| PQ_HM_TRIED = 1; |
| 26 |
|
| { |
| 27 |
27 |
| const char *no = PerlEnv_getenv("PUNK_QUEUE_NO_HM_ABI"); |
| 28 |
27 |
▶ | if (no && *no && strNE(no, "0")) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (no && *no && strNE(no, "0")) return NULL; |
14 |
13 |
27 |
| if (no && *no && strNE(no, "0")) return NULL; |
14 |
0 |
14 |
| if (no && *no && strNE(no, "0")) return NULL; |
14 |
0 |
14 |
|
| 29 |
|
| } |
| 30 |
13 |
| eval_pv("require Hyperman;", FALSE); |
| 31 |
|
| /* The require runs arbitrary Perl. If that grew the value stack it |
| 32 |
|
| * was reallocated, and the SP captured by dSP above now points into |
| 33 |
|
| * the freed block - which the PUTBACK below would publish as |
| 34 |
|
| * PL_stack_sp. */ |
| 35 |
13 |
| SPAGAIN; |
| 36 |
13 |
▶ | if (!SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV)) { |
13 |
0 |
13 |
| if (!SvTRUE(ERRSV)) { |
13 |
0 |
13 |
|
| 37 |
13 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; |
0 |
13 |
13 |
|
| 38 |
13 |
| count = call_pv("Hyperman::_abi_ptr", G_SCALAR | G_EVAL); |
| 39 |
13 |
| SPAGAIN; |
| 40 |
13 |
▶ | if (!SvTRUE(ERRSV) && count > 0) p = POPi; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV) && count > 0) p = POPi; |
13 |
0 |
13 |
| if (!SvTRUE(ERRSV) && count > 0) p = POPi; |
13 |
0 |
13 |
| if (!SvTRUE(ERRSV) && count > 0) p = POPi; |
13 |
0 |
13 |
|
| 41 |
0 |
▶ | else if (count > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (count > 0) (void)POPs; |
0 |
0 |
0 |
|
| 42 |
13 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
13 |
0 |
13 |
|
| 43 |
13 |
▶ | if (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p) { |
13 |
0 |
13 |
|
| 44 |
13 |
| const hm_abi *a = INT2PTR(const hm_abi *, p); |
| 45 |
13 |
▶ | if (a && a->abi_version >= HM_ABI_VERSION) PQ_HM = a; |
Branch: 2 branches
| Branch | True | False | Total |
| if (a && a->abi_version >= HM_ABI_VERSION) PQ_HM = a; |
13 |
0 |
13 |
| if (a && a->abi_version >= HM_ABI_VERSION) PQ_HM = a; |
13 |
0 |
13 |
|
| 46 |
|
| } |
| 47 |
|
| } |
| 48 |
|
| } |
| 49 |
76 |
| return PQ_HM; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
|
| #endif /* PQ_HM_H */ |