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 | #include <fcntl.h> |
|
|
6 | #include <unistd.h> |
4 | |
7 | |
5 | typedef CV *B__CV; |
8 | typedef CV *B__CV; |
6 | |
9 | |
7 | static OP *(*old_entersub)(pTHX); |
10 | static OP *(*old_entersub)(pTHX); |
8 | |
11 | |
9 | int count = 1; |
|
|
10 | |
|
|
11 | // this is, of course, a slower entersub |
12 | // this is, of course, a slower entersub |
12 | static OP * |
13 | static OP * |
13 | faster_entersub (pTHX) |
14 | faster_entersub (pTHX) |
14 | { |
15 | { |
15 | dSP; |
16 | static int in_perl; |
16 | dTOPss; |
|
|
17 | |
17 | |
18 | if (SvTYPE (sv) == SVt_PVGV) |
18 | if (!PL_compcv || in_perl) // only when not compiling, reduces recompiling due to op-address-shift |
19 | sv = (SV *)GvCV (sv); |
19 | { |
|
|
20 | dSP; |
|
|
21 | dTOPss; |
20 | |
22 | |
21 | if (sv) |
23 | ++in_perl; |
22 | { |
|
|
23 | // only once for now |
|
|
24 | PL_op->op_ppaddr = old_entersub; |
|
|
25 | |
24 | |
26 | // only simple cv calls for now |
25 | if (SvTYPE (sv) == SVt_PVGV) |
27 | if (!PL_perldb && !PL_tainting |
26 | sv = (SV *)GvCV (sv); |
28 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
27 | |
29 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
28 | if (sv) |
30 | { |
29 | { |
31 | SV *bsv = newSViv (PTR2IV (sv)); |
30 | // only once for now |
|
|
31 | PL_op->op_ppaddr = old_entersub; |
32 | |
32 | |
|
|
33 | // only simple cv calls for now |
|
|
34 | if (!PL_perldb && !PL_tainting |
|
|
35 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
|
|
36 | && CvSTART (sv) // must exist |
|
|
37 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
|
|
38 | { |
|
|
39 | SV *bsv = newSViv (PTR2IV (sv)); |
|
|
40 | |
33 | ENTER; |
41 | ENTER; |
34 | SAVETMPS; |
42 | SAVETMPS; |
35 | PUSHMARK (SP); |
43 | PUSHMARK (SP); |
36 | // emulate B::CV typemap entry we don't have |
44 | // emulate B::CV typemap entry we don't have |
37 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1)))); |
45 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1)))); |
38 | PUTBACK; |
46 | PUTBACK; |
39 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
47 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
40 | SPAGAIN; |
48 | SPAGAIN; |
41 | FREETMPS; |
49 | FREETMPS; |
42 | LEAVE; |
50 | LEAVE; |
|
|
51 | } |
43 | } |
52 | } |
|
|
53 | |
|
|
54 | --in_perl; |
44 | } |
55 | } |
45 | |
56 | |
46 | return old_entersub (aTHX); |
57 | return old_entersub (aTHX); |
47 | } |
58 | } |
48 | |
59 | |
… | |
… | |
52 | |
63 | |
53 | IV |
64 | IV |
54 | ppaddr (int optype) |
65 | ppaddr (int optype) |
55 | CODE: |
66 | CODE: |
56 | RETVAL = optype == OP_ENTERSUB |
67 | RETVAL = optype == OP_ENTERSUB |
57 | ? old_entersub |
68 | ? (IV)old_entersub |
58 | : PL_ppaddr [optype]; |
69 | : (IV)PL_ppaddr [optype]; |
59 | OUTPUT: |
70 | OUTPUT: |
60 | RETVAL |
71 | RETVAL |
61 | |
72 | |
62 | void |
73 | void |
63 | hook_entersub () |
74 | hook_entersub () |
… | |
… | |
69 | patch_cv (B::CV cv, void *ptr) |
80 | patch_cv (B::CV cv, void *ptr) |
70 | CODE: |
81 | CODE: |
71 | { |
82 | { |
72 | OP *op; |
83 | OP *op; |
73 | |
84 | |
|
|
85 | if (!ptr) |
|
|
86 | croak ("NULL not allowed as code address for patch_cv"); |
|
|
87 | |
74 | NewOp (0, op, 1, OP); |
88 | NewOp (0, op, 1, OP); |
75 | |
89 | |
76 | op->op_sibling = CvSTART (cv); |
90 | op->op_sibling = CvSTART (cv); |
77 | op->op_type = OP_NULL; |
91 | op->op_type = OP_NULL; |
78 | op->op_ppaddr = ptr; |
92 | op->op_ppaddr = ptr; |
79 | |
93 | |
80 | CvSTART (cv) = op; |
94 | CvSTART (cv) = op; |
81 | } |
95 | } |
82 | |
96 | |
|
|
97 | bool |
|
|
98 | fcntl_lock (int fd) |
|
|
99 | CODE: |
|
|
100 | { |
|
|
101 | struct flock lck; |
|
|
102 | lck.l_type = F_WRLCK; |
|
|
103 | lck.l_whence = SEEK_SET; |
|
|
104 | lck.l_start = 0; |
|
|
105 | lck.l_len = 0; |
83 | |
106 | |
|
|
107 | RETVAL = fcntl (fd, F_SETLKW, &lck) == 0; |
|
|
108 | } |
|
|
109 | OUTPUT: |
|
|
110 | RETVAL |
|
|
111 | |
|
|
112 | |
|
|
113 | |