| 1 |
|
| MODE: INLINE |
| 2 |
|
| |
| 3 |
|
| namespace { |
| 4 |
|
| static OP* pp_padsv_proxy (pTHX) { |
| 5 |
|
| return PL_ppaddr[OP_PADSV](aTHX); |
| 6 |
|
| } |
| 7 |
|
| |
| 8 |
|
| // adds "return unless defined $weak_ref" perl code to the top of subroutine |
| 9 |
|
| static void add_weak_ref_check (const Sub& sub, PADOFFSET i) { |
| 10 |
|
| auto root = CvROOT(sub); |
| 11 |
|
| if (root->op_type != OP_LEAVESUB) throw "bad closure"; |
| 12 |
|
| auto lineseq = cUNOPx(root)->op_first; |
| 13 |
|
| if (lineseq->op_type != OP_LINESEQ) throw "bad closure"; |
| 14 |
|
| |
| 15 |
|
| OP* orig_start = CvSTART(sub); |
| 16 |
|
| |
| 17 |
|
| // return if this CV has already been injected |
| 18 |
|
| if (orig_start->op_ppaddr == pp_padsv_proxy) return; |
| 19 |
|
| |
| 20 |
|
| // check if we've already done this on another CVs with the same proto |
| 21 |
|
| auto check_op = cLISTOPx(lineseq)->op_first; |
| 22 |
|
| if (check_op && check_op->op_type == OP_NULL) { |
| 23 |
|
| check_op = cUNOPx(check_op)->op_first; |
| 24 |
|
| if (check_op->op_type == OP_OR) { |
| 25 |
|
| check_op = cLISTOPx(check_op)->op_first; |
| 26 |
|
| if (check_op && check_op->op_type == OP_DEFINED) { |
| 27 |
|
| check_op = cUNOPx(check_op)->op_first; |
| 28 |
|
| if (check_op->op_ppaddr == pp_padsv_proxy) { |
| 29 |
|
| CvSTART(sub) = check_op; |
| 30 |
|
| return; |
| 31 |
|
| } |
| 32 |
|
| } |
| 33 |
|
| } |
| 34 |
|
| } |
| 35 |
|
| |
| 36 |
|
| /* We're creating here the optree and insert it into the beginning |
| 37 |
|
| * |
| 38 |
|
| 5 or LOGOP(0x560e863d99d0) ===> 6 [nextstate 0x560e863d9df8] |
| 39 |
|
| PARENT ===> 7 [null 0x560e863d9998] |
| 40 |
|
| FLAGS = (VOID,KIDS,SLABBED) |
| 41 |
|
| PRIVATE = (0x1) |
| 42 |
|
| OTHER ===> 8 [pushmark 0x560e863d9ab8] |
| 43 |
|
| | |
| 44 |
|
| 4 +--defined UNOP(0x560e863d9a10) ===> 5 [or 0x560e863d99d0] |
| 45 |
|
| | FLAGS = (SCALAR,KIDS,SLABBED,MORESIB) |
| 46 |
|
| | PRIVATE = (0x1) |
| 47 |
|
| | | |
| 48 |
|
| 2 | +--padsv OP(0x560e863d9a48) ===> 4 [defined 0x560e863d9a10] |
| 49 |
|
| | TARG = 1 |
| 50 |
|
| | FLAGS = (SCALAR,SLABBED) |
| 51 |
|
| | |
| 52 |
|
| 9 +--return LISTOP(0x560e863d9a78) ===> 6 [nextstate 0x560e863d9df8] |
| 53 |
|
| FLAGS = (UNKNOWN,KIDS,SLABBED) |
| 54 |
|
| | |
| 55 |
|
| 8 +--pushmark OP(0x560e863d9ab8) ===> 9 [return 0x560e863d9a78] |
| 56 |
|
| FLAGS = (SCALAR,SLABBED) |
| 57 |
|
| */ |
| 58 |
|
| |
| 59 |
|
| auto old_PL_compcv = PL_compcv; |
| 60 |
|
| PL_compcv = sub; // older perls require compilation context during OP creation |
| 61 |
|
| |
| 62 |
|
| OP* op_pushmark = newOP(OP_PUSHMARK, 0); |
| 63 |
|
| OP* op_return = newLISTOP(OP_RETURN, 0, op_pushmark, nullptr); |
| 64 |
|
| op_pushmark->op_next = op_return; |
| 65 |
|
| |
| 66 |
|
| OP* op_padsv = newOP(OP_PADSV, 0); |
| 67 |
|
| op_padsv->op_targ = i; // set correct index in padlist |
| 68 |
|
| op_padsv->op_ppaddr = pp_padsv_proxy; // for marking that we've already done this |
| 69 |
|
| OP* op_defined = newUNOP(OP_DEFINED, 0, op_padsv); |
| 70 |
|
| op_padsv->op_next = op_defined; |
| 71 |
|
| |
| 72 |
|
| OP* op_null = newLOGOP(OP_OR, OPf_WANT_VOID, op_defined, op_return); |
| 73 |
|
| OP* op_or = cUNOPx(op_null)->op_first; |
| 74 |
|
| |
| 75 |
|
| op_defined->op_next = op_or; |
| 76 |
|
| op_or->op_next = orig_start; // this is the true case |
| 77 |
|
| op_return->op_next = orig_start; // doesnt matter what next |
| 78 |
|
| cLOGOPx(op_or)->op_other = op_pushmark; // this is the false case |
| 79 |
|
| |
| 80 |
|
| // add the whole generated tree to OP_LINESEQ (our top-op is op_null). It is not required for execution, but required for correct |
| 81 |
|
| // work of op_free and also debug modules like B::Concise and others. |
| 82 |
|
| op_sibling_splice(lineseq, NULL, 0, op_null); |
| 83 |
|
| |
| 84 |
|
| CvSTART(sub) = op_padsv; // set new entry op |
| 85 |
|
| |
| 86 |
|
| PL_compcv = old_PL_compcv; // restore orig value |
| 87 |
|
| } |
| 88 |
|
| } |
| 89 |
|
| |
| 90 |
|
| |
| 91 |
|
| MODULE = XS::Framework PACKAGE = XS::Framework::CallbackDispatcher |
| 92 |
|
| PROTOTYPES: DISABLE |
| 93 |
|
| |
| 94 |
12 |
▶ | void XSCallbackDispatcher::add (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::add (Sub cv) |
12 |
0 |
12 |
|
| 95 |
|
| |
| 96 |
|
| void XSCallbackDispatcher::add_weak (Ref ref, Sub sub) { |
| 97 |
14 |
▶ | if (!sub) throw "callback must be defined"; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sub) throw "callback must be defined"; |
1 |
13 |
14 |
|
| 98 |
13 |
▶ | if (!ref) throw "data to weaken must be defined"; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ref) throw "data to weaken must be defined"; |
1 |
12 |
13 |
|
| 99 |
|
| |
| 100 |
12 |
| auto refval = ref.value(); |
| 101 |
12 |
| SV** varptr = nullptr; |
| 102 |
12 |
| auto padlist = CvPADLIST(sub); |
| 103 |
|
| PADOFFSET i; |
| 104 |
12 |
▶ | if (padlist) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (padlist) { |
12 |
0 |
12 |
|
| 105 |
12 |
| SV** vars = AvARRAY(PadlistARRAY(padlist)[1]); |
| 106 |
12 |
| auto padlist_names = PadlistNAMES(padlist); |
| 107 |
12 |
| auto pnames = PadnamelistARRAY(padlist_names); |
| 108 |
28 |
▶ | for (i = 1; i <= PadnamelistMAX(padlist_names); ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i <= PadnamelistMAX(padlist_names); ++i) { |
26 |
2 |
28 |
|
| 109 |
26 |
| auto padname = pnames[i]; |
| 110 |
26 |
▶ | if (!padname || !PadnamePV(padname) || !PadnameOUTER(padname)) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!padname || !PadnamePV(padname) || !PadnameOUTER(padname)) continue; |
26 |
0 |
26 |
| if (!padname || !PadnamePV(padname) || !PadnameOUTER(padname)) continue; |
19 |
7 |
26 |
| if (!padname || !PadnamePV(padname) || !PadnameOUTER(padname)) continue; |
0 |
19 |
19 |
|
| 111 |
19 |
| auto var = vars[i]; |
| 112 |
19 |
▶ | if (SvROK(var) && SvRV(var) == refval) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvROK(var) && SvRV(var) == refval) { |
11 |
8 |
19 |
| if (SvROK(var) && SvRV(var) == refval) { |
10 |
1 |
11 |
| if (SvROK(var) && SvRV(var) == refval) { |
10 |
9 |
19 |
|
| 113 |
10 |
| varptr = &vars[i]; |
| 114 |
10 |
| break; |
| 115 |
|
| } |
| 116 |
|
| } |
| 117 |
|
| } |
| 118 |
12 |
▶ | if (!varptr) throw "passed argument is not captured by subroutine"; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!varptr) throw "passed argument is not captured by subroutine"; |
2 |
10 |
12 |
|
| 119 |
|
| |
| 120 |
10 |
▶ | if (!SvWEAKREF(*varptr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvWEAKREF(*varptr)) { |
7 |
3 |
10 |
|
| 121 |
7 |
▶ | SvREFCNT_dec_NN(*varptr); |
Branch: 1 branch
| Branch | True | False | Total |
| SvREFCNT_dec_NN(*varptr); |
7 |
0 |
7 |
|
| 122 |
7 |
▶ | *varptr = newRV(ref.value()); |
Branch: 1 branch
| Branch | True | False | Total |
| *varptr = newRV(ref.value()); |
7 |
0 |
7 |
|
| 123 |
7 |
▶ | sv_rvweaken(*varptr); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_rvweaken(*varptr); |
7 |
0 |
7 |
|
| 124 |
|
| } |
| 125 |
|
| |
| 126 |
10 |
▶ | add_weak_ref_check(sub, i); |
Branch: 1 branch
| Branch | True | False | Total |
| add_weak_ref_check(sub, i); |
10 |
0 |
10 |
|
| 127 |
|
| |
| 128 |
10 |
▶ | THIS->add(sub); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->add(sub); |
10 |
0 |
10 |
|
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
0 |
▶ | void XSCallbackDispatcher::prepend (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::prepend (Sub cv) |
0 |
0 |
0 |
|
| 132 |
|
| |
| 133 |
23 |
▶ | void XSCallbackDispatcher::add_event_listener (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::add_event_listener (Sub cv) |
23 |
0 |
23 |
|
| 134 |
|
| |
| 135 |
1 |
▶ | void XSCallbackDispatcher::prepend_event_listener (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::prepend_event_listener (Sub cv) |
1 |
0 |
1 |
|
| 136 |
|
| |
| 137 |
4 |
▶ | void XSCallbackDispatcher::remove (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::remove (Sub cv) |
4 |
0 |
4 |
|
| 138 |
|
| |
| 139 |
2 |
▶ | void XSCallbackDispatcher::remove_event_listener (Sub cv) |
Branch: 1 branch
| Branch | True | False | Total |
| void XSCallbackDispatcher::remove_event_listener (Sub cv) |
2 |
0 |
2 |
|
| 140 |
|
| |
| 141 |
23 |
| void XSCallbackDispatcher::remove_all () |
| 142 |
|
| |
| 143 |
10 |
▶ | bool XSCallbackDispatcher::has_listeners () |
Branch: 1 branch
| Branch | True | False | Total |
| bool XSCallbackDispatcher::has_listeners () |
5 |
5 |
10 |
|
| 144 |
|
| |
| 145 |
|
| Sv XSCallbackDispatcher::call (...) { |
| 146 |
39 |
▶ | RETVAL = THIS->call(&ST(1), items - 1); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = THIS->call(&ST(1), items - 1); |
34 |
5 |
39 |
|
| 147 |
34 |
▶ | if (!RETVAL) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) XSRETURN_EMPTY; |
23 |
11 |
34 |
|
| 148 |
|
| } |