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