| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| #include "BUtils.h" |
| 5 |
|
| |
| 6 |
|
| /* Stolen from pp_ctl.c (with modifications) */ |
| 7 |
|
| |
| 8 |
|
| static I32 |
| 9 |
0 |
| BUtils_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock) |
| 10 |
|
| { |
| 11 |
|
| dTHR; |
| 12 |
|
| I32 i; |
| 13 |
|
| PERL_CONTEXT *cx; |
| 14 |
0 |
▶ | for (i = startingblock; i >= 0; i--) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = startingblock; i >= 0; i--) { |
0 |
0 |
0 |
|
| 15 |
0 |
| cx = &cxstk[i]; |
| 16 |
0 |
▶ | switch (CxTYPE(cx)) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (CxTYPE(cx)) { |
0 |
0 |
0 |
|
| 17 |
0 |
| default: |
| 18 |
0 |
| continue; |
| 19 |
|
| /*case CXt_EVAL:*/ |
| 20 |
0 |
| case CXt_SUB: |
| 21 |
|
| /* In Perl 5.005, formats just used CXt_SUB */ |
| 22 |
|
| #ifdef CXt_FORMAT |
| 23 |
|
| case CXt_FORMAT: |
| 24 |
|
| #endif |
| 25 |
|
| DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i)); |
| 26 |
0 |
| return i; |
| 27 |
|
| } |
| 28 |
|
| } |
| 29 |
0 |
| return i; |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
|
| static I32 |
| 33 |
0 |
| BUtils_dopoptosub(pTHX_ I32 startingblock) |
| 34 |
|
| { |
| 35 |
|
| dTHR; |
| 36 |
0 |
| return BUtils_dopoptosub_at(aTHX_ cxstack, startingblock); |
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
|
| /* This function is based on the code of pp_caller */ |
| 40 |
|
| PERL_CONTEXT* |
| 41 |
0 |
| BUtils_op_upcontext(pTHX_ I32 count, COP **cop_p, PERL_CONTEXT **ccstack_p, |
| 42 |
|
| I32 *cxix_from_p, I32 *cxix_to_p) |
| 43 |
|
| { |
| 44 |
0 |
| PERL_SI *top_si = PL_curstackinfo; |
| 45 |
0 |
| I32 cxix = BUtils_dopoptosub(aTHX_ cxstack_ix); |
| 46 |
0 |
| PERL_CONTEXT *ccstack = cxstack; |
| 47 |
|
| |
| 48 |
0 |
▶ | if (cxix_from_p) *cxix_from_p = cxstack_ix+1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxix_from_p) *cxix_from_p = cxstack_ix+1; |
0 |
0 |
0 |
|
| 49 |
0 |
▶ | if (cxix_to_p) *cxix_to_p = cxix; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxix_to_p) *cxix_to_p = cxix; |
0 |
0 |
0 |
|
| 50 |
|
| for (;;) { |
| 51 |
|
| /* we may be in a higher stacklevel, so dig down deeper */ |
| 52 |
0 |
▶ | while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { |
0 |
0 |
0 |
| while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { |
0 |
0 |
0 |
|
| 53 |
0 |
| top_si = top_si->si_prev; |
| 54 |
0 |
| ccstack = top_si->si_cxstack; |
| 55 |
0 |
| cxix = BUtils_dopoptosub_at(aTHX_ ccstack, top_si->si_cxix); |
| 56 |
0 |
▶ | if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
0 |
0 |
0 |
| if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
0 |
0 |
0 |
|
| 57 |
0 |
▶ | if (cxix_to_p) *cxix_to_p = cxix; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxix_to_p) *cxix_to_p = cxix; |
0 |
0 |
0 |
|
| 58 |
|
| } |
| 59 |
0 |
▶ | if (cxix < 0 && count == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxix < 0 && count == 0) { |
0 |
0 |
0 |
| if (cxix < 0 && count == 0) { |
0 |
0 |
0 |
|
| 60 |
0 |
▶ | if (ccstack_p) *ccstack_p = ccstack; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ccstack_p) *ccstack_p = ccstack; |
0 |
0 |
0 |
|
| 61 |
0 |
| return (PERL_CONTEXT *)0; |
| 62 |
|
| } |
| 63 |
0 |
▶ | else if (cxix < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (cxix < 0) |
0 |
0 |
0 |
|
| 64 |
0 |
| return (PERL_CONTEXT *)-1; |
| 65 |
0 |
▶ | if (PL_DBsub && cxix >= 0 && |
Branch: 2 branches
| Branch | True | False | Total |
| if (PL_DBsub && cxix >= 0 && |
0 |
0 |
0 |
| if (PL_DBsub && cxix >= 0 && |
0 |
0 |
0 |
|
| 66 |
0 |
▶ | ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) |
Branch: 1 branch
| Branch | True | False | Total |
| ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) |
0 |
0 |
0 |
|
| 67 |
0 |
| count++; |
| 68 |
0 |
▶ | if (!count--) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!count--) |
0 |
0 |
0 |
|
| 69 |
0 |
| break; |
| 70 |
|
| |
| 71 |
0 |
▶ | if (cop_p) *cop_p = ccstack[cxix].blk_oldcop; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cop_p) *cop_p = ccstack[cxix].blk_oldcop; |
0 |
0 |
0 |
|
| 72 |
0 |
| cxix = BUtils_dopoptosub_at(aTHX_ ccstack, cxix - 1); |
| 73 |
0 |
▶ | if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
0 |
0 |
0 |
| if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; |
0 |
0 |
0 |
|
| 74 |
0 |
▶ | if (cxix_to_p) *cxix_to_p = cxix; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxix_to_p) *cxix_to_p = cxix; |
0 |
0 |
0 |
|
| 75 |
|
| } |
| 76 |
0 |
▶ | if (ccstack_p) *ccstack_p = ccstack; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ccstack_p) *ccstack_p = ccstack; |
0 |
0 |
0 |
|
| 77 |
0 |
| return &ccstack[cxix]; |
| 78 |
|
| } |
| 79 |
|
| |
| 80 |
|
| /* The most popular error message */ |
| 81 |
|
| #define TOO_FAR \ |
| 82 |
|
| croak("want: Called from outside a subroutine") |
| 83 |
|
| |
| 84 |
|
| /* Between 5.9.1 and 5.9.2 the retstack was removed, and the |
| 85 |
|
| return op is now stored on the cxstack. */ |
| 86 |
|
| #define HAS_RETSTACK (\ |
| 87 |
|
| PERL_REVISION < 5 || \ |
| 88 |
|
| (PERL_REVISION == 5 && PERL_VERSION < 9) || \ |
| 89 |
|
| (PERL_REVISION == 5 && PERL_VERSION == 9 && PERL_SUBVERSION < 2) \ |
| 90 |
|
| ) |
| 91 |
|
| |
| 92 |
|
| OP* |
| 93 |
0 |
| BUtils_find_return_op(pTHX_ I32 uplevel) |
| 94 |
|
| { |
| 95 |
0 |
| PERL_CONTEXT *cx = BUtils_op_upcontext(aTHX_ uplevel, 0, 0, 0, 0); |
| 96 |
0 |
▶ | if (!cx) TOO_FAR; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cx) TOO_FAR; |
0 |
0 |
0 |
|
| 97 |
|
| #if HAS_RETSTACK |
| 98 |
|
| return PL_retstack[cx->blk_oldretsp - 1]; |
| 99 |
|
| #else |
| 100 |
0 |
| return cx->blk_sub.retop; |
| 101 |
|
| #endif |
| 102 |
|
| } |
| 103 |
|
| |
| 104 |
|
| OP* |
| 105 |
0 |
| BUtils_find_oldcop(pTHX_ I32 uplevel) |
| 106 |
|
| { |
| 107 |
0 |
| PERL_CONTEXT *cx = BUtils_op_upcontext(aTHX_ uplevel, 0, 0, 0, 0); |
| 108 |
0 |
▶ | if (!cx) TOO_FAR; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cx) TOO_FAR; |
0 |
0 |
0 |
|
| 109 |
0 |
| return (OP*) cx->blk_oldcop; |
| 110 |
|
| } |
| 111 |
|
| |
| 112 |
|
| |
| 113 |
|
| MODULE = B::Utils::OP PACKAGE = B::Utils::OP PREFIX = BUtils_OP_ |
| 114 |
|
| PROTOTYPES: DISABLE |
| 115 |
|
| |
| 116 |
|
| B::OP |
| 117 |
|
| parent_op(I32 uplevel) |
| 118 |
|
| CODE: |
| 119 |
0 |
| RETVAL = BUtils_find_oldcop(aTHX_ uplevel); |
| 120 |
|
| OUTPUT: |
| 121 |
|
| RETVAL |
| 122 |
|
| |
| 123 |
|
| B::OP |
| 124 |
|
| return_op(I32 uplevel) |
| 125 |
|
| CODE: |
| 126 |
0 |
| RETVAL = BUtils_find_return_op(aTHX_ uplevel); |
| 127 |
|
| OUTPUT: |
| 128 |
|
| RETVAL |
| 129 |
|
| |