1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
|
|
4 | |
|
|
5 | typedef CV *B__CV; |
4 | |
6 | |
5 | static OP *(*old_entersub)(pTHX); |
7 | static OP *(*old_entersub)(pTHX); |
6 | |
8 | |
7 | // this is, of course, a slower entersub |
9 | // this is, of course, a slower entersub |
8 | static OP * |
10 | static OP * |
… | |
… | |
19 | // only once for now |
21 | // only once for now |
20 | PL_op->op_ppaddr = old_entersub; |
22 | PL_op->op_ppaddr = old_entersub; |
21 | |
23 | |
22 | // only simple cv calls for now |
24 | // only simple cv calls for now |
23 | if (!PL_perldb && !PL_tainting |
25 | if (!PL_perldb && !PL_tainting |
24 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)) |
26 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
|
|
27 | && CvSTART (sv) // must exist |
|
|
28 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
25 | { |
29 | { |
26 | sv = newSViv (PTR2IV (sv)); |
30 | SV *bsv = newSViv (PTR2IV (sv)); |
27 | |
31 | |
28 | ENTER; |
32 | ENTER; |
29 | SAVETMPS; |
33 | SAVETMPS; |
30 | PUSHMARK (SP); |
34 | PUSHMARK (SP); |
31 | // emulate B::CV typemap entry we don't have |
35 | // emulate B::CV typemap entry we don't have |
32 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (sv), gv_stashpv ("B::CV", 1)))); |
36 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1)))); |
33 | PUTBACK; |
37 | PUTBACK; |
34 | call_pv ("Faster::entersub", G_VOID|G_DISCARD); |
38 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
35 | SPAGAIN; |
39 | SPAGAIN; |
36 | FREETMPS; |
40 | FREETMPS; |
37 | LEAVE; |
41 | LEAVE; |
38 | } |
42 | } |
39 | } |
43 | } |
… | |
… | |
47 | |
51 | |
48 | IV |
52 | IV |
49 | ppaddr (int optype) |
53 | ppaddr (int optype) |
50 | CODE: |
54 | CODE: |
51 | RETVAL = optype == OP_ENTERSUB |
55 | RETVAL = optype == OP_ENTERSUB |
52 | ? old_entersub |
56 | ? (IV)old_entersub |
53 | : PL_ppaddr [optype]; |
57 | : (IV)PL_ppaddr [optype]; |
54 | OUTPUT: |
58 | OUTPUT: |
55 | RETVAL |
59 | RETVAL |
56 | |
60 | |
57 | void |
61 | void |
58 | hook_entersub () |
62 | hook_entersub () |
59 | CODE: |
63 | CODE: |
60 | old_entersub = PL_ppaddr [OP_ENTERSUB]; |
64 | old_entersub = PL_ppaddr [OP_ENTERSUB]; |
61 | PL_ppaddr [OP_ENTERSUB] = faster_entersub; |
65 | PL_ppaddr [OP_ENTERSUB] = faster_entersub; |
62 | |
66 | |
|
|
67 | void |
|
|
68 | patch_cv (B::CV cv, void *ptr) |
|
|
69 | CODE: |
|
|
70 | { |
|
|
71 | OP *op; |
63 | |
72 | |
|
|
73 | NewOp (0, op, 1, OP); |
|
|
74 | |
|
|
75 | op->op_sibling = CvSTART (cv); |
|
|
76 | op->op_type = OP_NULL; |
|
|
77 | op->op_ppaddr = ptr; |
|
|
78 | |
|
|
79 | CvSTART (cv) = op; |
|
|
80 | } |
|
|
81 | |
|
|
82 | |