| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "embed.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #define NEED_sv_2pv_flags_GLOBAL |
| 6 |
|
| #include "ppport.h" |
| 7 |
|
| |
| 8 |
|
| #include "hook_op_check.h" |
| 9 |
|
| |
| 10 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 16 |
| 11 |
|
| #define pad_findmy(a,b,c) Perl_pad_findmy_pvn(aTHX_ a, b, c) |
| 12 |
|
| #else |
| 13 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 15 && PERL_SUBVERSION >= 1 |
| 14 |
|
| #define pad_findmy(a,b,c) Perl_pad_findmy_pvn(aTHX_ a, b, c) |
| 15 |
|
| |
| 16 |
|
| #else |
| 17 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 13 |
| 18 |
|
| |
| 19 |
|
| #else |
| 20 |
|
| |
| 21 |
|
| #define op_append_elem(a,b,c) Perl_append_elem(aTHX_ a,b,c) |
| 22 |
|
| |
| 23 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 12 |
| 24 |
|
| |
| 25 |
|
| #else |
| 26 |
|
| #define pad_findmy(a,b,c) Perl_pad_findmy(aTHX_ a) |
| 27 |
|
| #endif |
| 28 |
|
| #endif |
| 29 |
|
| #endif |
| 30 |
|
| #endif |
| 31 |
|
| |
| 32 |
|
| typedef struct userdata_St { |
| 33 |
|
| hook_op_check_id eval_hook; |
| 34 |
|
| SV *class; |
| 35 |
|
| } userdata_t; |
| 36 |
|
| |
| 37 |
|
| static OP * |
| 38 |
0 |
| invoker_ck_entersub(pTHX_ OP *o, void *ud) { |
| 39 |
|
| |
| 40 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 26 |
| 41 |
|
| |
| 42 |
0 |
| OP *f = (OpHAS_SIBLING(cUNOPo->op_first) |
| 43 |
0 |
▶ | ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first; // pushmark |
Branch: 1 branch
| Branch | True | False | Total |
| ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first; // pushmark |
0 |
0 |
0 |
|
| 44 |
0 |
▶ | OP *arg = OpSIBLING(f); // the actual first argument |
Branch: 1 branch
| Branch | True | False | Total |
| OP *arg = OpSIBLING(f); // the actual first argument |
0 |
0 |
0 |
|
| 45 |
|
| |
| 46 |
|
| #else |
| 47 |
|
| |
| 48 |
|
| OP *f = ((cUNOPo->op_first->op_sibling) |
| 49 |
|
| ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first; // pushmark |
| 50 |
|
| OP *arg = f->op_sibling; // the actual first argument |
| 51 |
|
| |
| 52 |
|
| #endif |
| 53 |
|
| |
| 54 |
0 |
▶ | if (arg->op_type == OP_RV2SV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (arg->op_type == OP_RV2SV) { |
0 |
0 |
0 |
|
| 55 |
|
| GV *gv; |
| 56 |
0 |
| OP *gvop = cUNOPx(arg)->op_first; |
| 57 |
0 |
▶ | if (gvop->op_type == OP_GV && |
Branch: 1 branch
| Branch | True | False | Total |
| if (gvop->op_type == OP_GV && |
0 |
0 |
0 |
|
| 58 |
0 |
▶ | (gv = cGVOPx_gv(gvop)) && |
Branch: 1 branch
| Branch | True | False | Total |
| (gv = cGVOPx_gv(gvop)) && |
0 |
0 |
0 |
|
| 59 |
0 |
▶ | !strcmp(GvNAME_get(gv), "-")) { |
Branch: 1 branch
| Branch | True | False | Total |
| !strcmp(GvNAME_get(gv), "-")) { |
0 |
0 |
0 |
|
| 60 |
|
| |
| 61 |
0 |
| const PADOFFSET tmp = pad_findmy("$self", 5, 0); |
| 62 |
0 |
▶ | if (tmp == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tmp == -1) { |
0 |
0 |
0 |
|
| 63 |
0 |
| gv = gv_fetchpvn_flags("self", 4, GV_NOINIT, SVt_PV); |
| 64 |
0 |
▶ | if (SvOK(gv) && SvTYPE(gv) == SVt_PVGV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvOK(gv) && SvTYPE(gv) == SVt_PVGV) { |
0 |
0 |
0 |
| if (SvOK(gv) && SvTYPE(gv) == SVt_PVGV) { |
0 |
0 |
0 |
|
| 65 |
|
| // "$self" was defined as a package variable -- use it |
| 66 |
0 |
| cUNOPx(arg)->op_first = newGVOP( |
| 67 |
|
| gvop->op_type, |
| 68 |
|
| gvop->op_flags, |
| 69 |
|
| gv |
| 70 |
|
| ); |
| 71 |
|
| } |
| 72 |
|
| else { |
| 73 |
0 |
| croak("$self not found"); |
| 74 |
|
| } |
| 75 |
|
| } |
| 76 |
|
| else { |
| 77 |
0 |
| OP * const self = newOP(OP_PADSV, 0); |
| 78 |
0 |
| self->op_targ = tmp; |
| 79 |
|
| |
| 80 |
|
| #if PERL_REVISION == 5 && PERL_VERSION >= 26 |
| 81 |
|
| |
| 82 |
0 |
| f->op_sibparent = self; |
| 83 |
0 |
| self->op_sibparent = arg->op_sibparent; |
| 84 |
0 |
| self->op_moresib = 1; |
| 85 |
|
| |
| 86 |
|
| #else |
| 87 |
|
| f->op_sibling = self; |
| 88 |
|
| self->op_sibling = arg->op_sibling; |
| 89 |
|
| #endif |
| 90 |
0 |
| op_free(arg); |
| 91 |
|
| } |
| 92 |
|
| } |
| 93 |
|
| } |
| 94 |
0 |
| return o; |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
|
| MODULE = invoker PACKAGE = invoker |
| 98 |
|
| PROTOTYPES: ENABLE |
| 99 |
|
| |
| 100 |
|
| hook_op_check_id |
| 101 |
|
| setup (class) |
| 102 |
|
| SV *class; |
| 103 |
|
| PREINIT: |
| 104 |
|
| userdata_t *ud; |
| 105 |
|
| INIT: |
| 106 |
0 |
| Newx (ud, 1, userdata_t); |
| 107 |
|
| CODE: |
| 108 |
0 |
| ud->class = newSVsv (class); |
| 109 |
0 |
| RETVAL = hook_op_check (OP_ENTERSUB, invoker_ck_entersub, ud); |
| 110 |
|
| OUTPUT: |
| 111 |
|
| RETVAL |
| 112 |
|
| |
| 113 |
|
| void |
| 114 |
|
| teardown (class, hook) |
| 115 |
|
| hook_op_check_id hook |
| 116 |
|
| PREINIT: |
| 117 |
|
| userdata_t *ud; |
| 118 |
|
| CODE: |
| 119 |
0 |
| ud = (userdata_t *)hook_op_check_remove (OP_ENTERSUB, hook); |
| 120 |
0 |
▶ | if (ud) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ud) { |
0 |
0 |
0 |
|
| 121 |
0 |
| SvREFCNT_dec (ud->class); |
| 122 |
0 |
| Safefree (ud); |
| 123 |
|
| } |