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 | // this is, of course, a slower entersub |
12 | // this is, of course, a slower entersub |
10 | static OP * |
13 | static OP * |
11 | faster_entersub (pTHX) |
14 | faster_entersub (pTHX) |
12 | { |
15 | { |
13 | dSP; |
16 | static int in_perl; |
14 | dTOPss; |
|
|
15 | |
17 | |
16 | if (SvTYPE (sv) == SVt_PVGV) |
18 | if (!PL_compcv || in_perl) // only when not compiling, reduces recompiling due to op-address-shift |
17 | sv = (SV *)GvCV (sv); |
19 | { |
|
|
20 | dSP; |
|
|
21 | dTOPss; |
18 | |
22 | |
19 | if (sv) |
23 | ++in_perl; |
20 | { |
|
|
21 | // only once for now |
|
|
22 | PL_op->op_ppaddr = old_entersub; |
|
|
23 | |
24 | |
24 | // only simple cv calls for now |
25 | if (SvTYPE (sv) == SVt_PVGV) |
25 | if (!PL_perldb && !PL_tainting |
26 | sv = (SV *)GvCV (sv); |
26 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
27 | |
27 | && CvSTART (sv) // must exist |
28 | if (sv) |
28 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
|
|
29 | { |
29 | { |
30 | SV *bsv = newSViv (PTR2IV (sv)); |
30 | // only once for now |
|
|
31 | PL_op->op_ppaddr = old_entersub; |
31 | |
32 | |
|
|
33 | // only simple cv calls for now |
|
|
34 | if (!PL_perldb && !PL_tainting |
|
|
35 | && SvTYPE (sv) == SVt_PVCV && !CvISXSUB (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 | |
32 | ENTER; |
41 | ENTER; |
33 | SAVETMPS; |
42 | SAVETMPS; |
34 | PUSHMARK (SP); |
43 | PUSHMARK (SP); |
35 | // emulate B::CV typemap entry we don't have |
44 | // emulate B::CV typemap entry we don't have |
36 | 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)))); |
37 | PUTBACK; |
46 | PUTBACK; |
38 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
47 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
39 | SPAGAIN; |
48 | SPAGAIN; |
40 | FREETMPS; |
49 | FREETMPS; |
41 | LEAVE; |
50 | LEAVE; |
|
|
51 | } |
42 | } |
52 | } |
|
|
53 | |
|
|
54 | --in_perl; |
43 | } |
55 | } |
44 | |
56 | |
45 | return old_entersub (aTHX); |
57 | return old_entersub (aTHX); |
46 | } |
58 | } |
47 | |
59 | |
… | |
… | |
80 | op->op_ppaddr = ptr; |
92 | op->op_ppaddr = ptr; |
81 | |
93 | |
82 | CvSTART (cv) = op; |
94 | CvSTART (cv) = op; |
83 | } |
95 | } |
84 | |
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; |
85 | |
106 | |
|
|
107 | RETVAL = fcntl (fd, F_SETLKW, &lck) == 0; |
|
|
108 | } |
|
|
109 | OUTPUT: |
|
|
110 | RETVAL |
|
|
111 | |
|
|
112 | |
|
|
113 | |