1 | #ifndef SCHMORP_PERL_H_ |
1 | #ifndef SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
3 | |
3 | |
|
|
4 | /* WARNING |
|
|
5 | * This header file is a shared resource between many modules. |
|
|
6 | */ |
|
|
7 | |
4 | /* useful stuff, used by schmorp mostly */ |
8 | /* useful stuff, used by schmorp mostly */ |
|
|
9 | |
|
|
10 | #include "patchlevel.h" |
5 | |
11 | |
6 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
12 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
7 | (PERL_REVISION > (a) \ |
13 | (PERL_REVISION > (a) \ |
8 | || (PERL_REVISION == (a) \ |
14 | || (PERL_REVISION == (a) \ |
9 | && (PERL_VERSION > (b) \ |
15 | && (PERL_VERSION > (b) \ |
… | |
… | |
68 | #ifndef SIG_SIZE |
74 | #ifndef SIG_SIZE |
69 | /* kudos to Slaven Rezic for the idea */ |
75 | /* kudos to Slaven Rezic for the idea */ |
70 | static char sig_size [] = { SIG_NUM }; |
76 | static char sig_size [] = { SIG_NUM }; |
71 | # define SIG_SIZE (sizeof (sig_size) + 1) |
77 | # define SIG_SIZE (sizeof (sig_size) + 1) |
72 | #endif |
78 | #endif |
|
|
79 | dTHX; |
73 | int signum; |
80 | int signum; |
74 | |
81 | |
75 | SvGETMAGIC (sig); |
82 | SvGETMAGIC (sig); |
76 | |
83 | |
77 | for (signum = 1; signum < SIG_SIZE; ++signum) |
84 | for (signum = 1; signum < SIG_SIZE; ++signum) |
… | |
… | |
90 | s_signum_croak (SV *sig) |
97 | s_signum_croak (SV *sig) |
91 | { |
98 | { |
92 | int signum = s_signum (sig); |
99 | int signum = s_signum (sig); |
93 | |
100 | |
94 | if (signum < 0) |
101 | if (signum < 0) |
|
|
102 | { |
|
|
103 | dTHX; |
95 | croak ("%s: invalid signal name or number", SvPV_nolen (sig)); |
104 | croak ("%s: invalid signal name or number", SvPV_nolen (sig)); |
|
|
105 | } |
96 | |
106 | |
97 | return signum; |
107 | return signum; |
98 | } |
108 | } |
99 | |
109 | |
100 | static int |
110 | static int |
101 | s_fileno (SV *fh, int wr) |
111 | s_fileno (SV *fh, int wr) |
102 | { |
112 | { |
|
|
113 | dTHX; |
103 | SvGETMAGIC (fh); |
114 | SvGETMAGIC (fh); |
104 | |
115 | |
105 | if (SvROK (fh)) |
116 | if (SvROK (fh)) |
106 | { |
117 | { |
107 | fh = SvRV (fh); |
118 | fh = SvRV (fh); |
… | |
… | |
121 | s_fileno_croak (SV *fh, int wr) |
132 | s_fileno_croak (SV *fh, int wr) |
122 | { |
133 | { |
123 | int fd = s_fileno (fh, wr); |
134 | int fd = s_fileno (fh, wr); |
124 | |
135 | |
125 | if (fd < 0) |
136 | if (fd < 0) |
|
|
137 | { |
|
|
138 | dTHX; |
126 | croak ("%s: illegal fh argument, either not an OS file or read/write mode mismatch", SvPV_nolen (fh)); |
139 | croak ("%s: illegal fh argument, either not an OS file or read/write mode mismatch", SvPV_nolen (fh)); |
|
|
140 | } |
127 | |
141 | |
128 | return fd; |
142 | return fd; |
129 | } |
143 | } |
130 | |
144 | |
131 | static SV * |
145 | static SV * |
132 | s_get_cv (SV *cb_sv) |
146 | s_get_cv (SV *cb_sv) |
133 | { |
147 | { |
|
|
148 | dTHX; |
134 | HV *st; |
149 | HV *st; |
135 | GV *gvp; |
150 | GV *gvp; |
136 | CV *cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
137 | |
151 | |
138 | return (SV *)cv; |
152 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
139 | } |
153 | } |
140 | |
154 | |
141 | static SV * |
155 | static SV * |
142 | s_get_cv_croak (SV *cb_sv) |
156 | s_get_cv_croak (SV *cb_sv) |
143 | { |
157 | { |
144 | cb_sv = s_get_cv (cb_sv); |
158 | SV *cv = s_get_cv (cb_sv); |
145 | |
159 | |
146 | if (!cb_sv) |
160 | if (!cv) |
|
|
161 | { |
|
|
162 | dTHX; |
147 | croak ("%s: callback must be a CODE reference or another callable object", SvPV_nolen (cb_sv)); |
163 | croak ("%s: callback must be a CODE reference or another callable object", SvPV_nolen (cb_sv)); |
|
|
164 | } |
148 | |
165 | |
149 | return cb_sv; |
166 | return cv; |
150 | } |
167 | } |
151 | |
168 | |
152 | /*****************************************************************************/ |
169 | /*****************************************************************************/ |
153 | /* gensub: simple closure generation utility */ |
170 | /* gensub: simple closure generation utility */ |
154 | |
171 | |