This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Various updates and fixes to some of the SysV IPC ops and their tests
[perl5.git] / feature.h
CommitLineData
f2c01b15
FC
1/* -*- buffer-read-only: t -*-
2 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 This file is built by regen/feature.pl.
4 Any changes made here will be lost!
5 */
6
7
3dd7db29
JK
8#ifndef PERL_FEATURE_H_
9#define PERL_FEATURE_H_
10
f2c01b15
FC
11#if defined(PERL_CORE) || defined (PERL_EXT)
12
13#define HINT_FEATURE_SHIFT 26
14
1ad5a39c
TC
15#define FEATURE_BITWISE_BIT 0x0001
16#define FEATURE___SUB___BIT 0x0002
17#define FEATURE_MYREF_BIT 0x0004
18#define FEATURE_EVALBYTES_BIT 0x0008
19#define FEATURE_FC_BIT 0x0010
20#define FEATURE_INDIRECT_BIT 0x0020
21#define FEATURE_ISA_BIT 0x0040
22#define FEATURE_MULTIDIMENSIONAL_BIT 0x0080
23#define FEATURE_POSTDEREF_QQ_BIT 0x0100
24#define FEATURE_REFALIASING_BIT 0x0200
25#define FEATURE_SAY_BIT 0x0400
26#define FEATURE_SIGNATURES_BIT 0x0800
27#define FEATURE_STATE_BIT 0x1000
28#define FEATURE_SWITCH_BIT 0x2000
29#define FEATURE_UNIEVAL_BIT 0x4000
30#define FEATURE_UNICODE_BIT 0x8000
9f601cf3 31
f2c01b15
FC
32#define FEATURE_BUNDLE_DEFAULT 0
33#define FEATURE_BUNDLE_510 1
34#define FEATURE_BUNDLE_511 2
35#define FEATURE_BUNDLE_515 3
2ad792cd 36#define FEATURE_BUNDLE_523 4
401d2aaa 37#define FEATURE_BUNDLE_527 5
2b9e0ab7 38#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
f2c01b15 39
d1fd0100
FC
40#define CURRENT_HINTS \
41 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
035b6821
FC
42#define CURRENT_FEATURE_BUNDLE \
43 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
d1fd0100 44
9f601cf3
TC
45#define FEATURE_IS_ENABLED_MASK(mask) \
46 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
47 ? (PL_curcop->cop_features & (mask)) : FALSE)
48
7d058bc9 49/* The longest string we pass in. */
1ad5a39c 50#define MAX_FEATURE_LEN (sizeof("multidimensional")-1)
7d058bc9 51
2a4315f8
BF
52#define FEATURE_FC_IS_ENABLED \
53 ( \
2ad792cd 54 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 55 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 56 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 57 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
58 )
59
813e85a0
PLE
60#define FEATURE_ISA_IS_ENABLED \
61 ( \
62 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
63 FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
64 )
65
03222170
FC
66#define FEATURE_SAY_IS_ENABLED \
67 ( \
68 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 69 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 70 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 71 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
72 )
73
74#define FEATURE_STATE_IS_ENABLED \
75 ( \
76 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 77 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 78 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 79 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
03222170
FC
80 )
81
82#define FEATURE_SWITCH_IS_ENABLED \
83 ( \
84 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 85 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 86 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 87 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
03222170
FC
88 )
89
cec892e7
FC
90#define FEATURE_BITWISE_IS_ENABLED \
91 ( \
401d2aaa
FC
92 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
93 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 94 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
95 )
96
0b657b19
DIM
97#define FEATURE_INDIRECT_IS_ENABLED \
98 ( \
99 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
100 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
101 FEATURE_IS_ENABLED_MASK(FEATURE_INDIRECT_BIT)) \
102 )
103
03222170
FC
104#define FEATURE_EVALBYTES_IS_ENABLED \
105 ( \
2ad792cd 106 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 107 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 108 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 109 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
110 )
111
30d9c59b
Z
112#define FEATURE_SIGNATURES_IS_ENABLED \
113 ( \
114 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 115 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
116 )
117
03222170
FC
118#define FEATURE___SUB___IS_ENABLED \
119 ( \
2ad792cd 120 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 121 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 122 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 123 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
124 )
125
baabe3fb 126#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
127 ( \
128 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 129 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
130 )
131
158becca
FC
132#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
133 ( \
401d2aaa
FC
134 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
135 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 136 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 137 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
138 )
139
03222170
FC
140#define FEATURE_UNIEVAL_IS_ENABLED \
141 ( \
2ad792cd 142 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 143 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 144 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 145 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
146 )
147
82d83da3
FC
148#define FEATURE_MYREF_IS_ENABLED \
149 ( \
150 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 151 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
152 )
153
03222170
FC
154#define FEATURE_UNICODE_IS_ENABLED \
155 ( \
156 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 157 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 158 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 159 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
160 )
161
1ad5a39c
TC
162#define FEATURE_MULTIDIMENSIONAL_IS_ENABLED \
163 ( \
164 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
165 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
166 FEATURE_IS_ENABLED_MASK(FEATURE_MULTIDIMENSIONAL_BIT)) \
167 )
168
03222170 169
9f601cf3
TC
170#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
171
172#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
173
174#define STOREFEATUREBITSHH(hh) \
175 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
176
177#define FETCHFEATUREBITSHH(hh) \
178 STMT_START { \
179 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
180 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
181 } STMT_END
182
f2c01b15
FC
183#endif /* PERL_CORE or PERL_EXT */
184
4160ddbd
FC
185#ifdef PERL_IN_OP_C
186PERL_STATIC_INLINE void
187S_enable_feature_bundle(pTHX_ SV *ver)
188{
189 SV *comp_ver = sv_newmortal();
190 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
191 | (
401d2aaa
FC
192 (sv_setnv(comp_ver, 5.027),
193 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
194 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
195 (sv_setnv(comp_ver, 5.023),
196 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
197 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
198 (sv_setnv(comp_ver, 5.015),
199 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
200 ? FEATURE_BUNDLE_515 :
201 (sv_setnv(comp_ver, 5.011),
202 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
203 ? FEATURE_BUNDLE_511 :
204 (sv_setnv(comp_ver, 5.009005),
205 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
206 ? FEATURE_BUNDLE_510 :
207 FEATURE_BUNDLE_DEFAULT
208 ) << HINT_FEATURE_SHIFT;
6389c777
FC
209 /* special case */
210 assert(PL_curcop == &PL_compiling);
211 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
212 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
213}
214#endif /* PERL_IN_OP_C */
215
b34c1a7e
TC
216#ifdef PERL_IN_MG_C
217
218#define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \
219 S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
220PERL_STATIC_INLINE void
221S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
222 SV *valsv, bool valbool) {
223 if (keysv)
224 keypv = SvPV_const(keysv, keylen);
225
226 if (memBEGINs(keypv, keylen, "feature_")) {
227 const char *subf = keypv + (sizeof("feature_")-1);
228 U32 mask = 0;
229 switch (*subf) {
230 case '_':
231 if (keylen == sizeof("feature___SUB__")-1
232 && memcmp(subf+1, "_SUB__", keylen - sizeof("feature_")) == 0) {
233 mask = FEATURE___SUB___BIT;
234 break;
235 }
236 return;
237
238 case 'b':
239 if (keylen == sizeof("feature_bitwise")-1
240 && memcmp(subf+1, "itwise", keylen - sizeof("feature_")) == 0) {
241 mask = FEATURE_BITWISE_BIT;
242 break;
243 }
244 return;
245
246 case 'e':
247 if (keylen == sizeof("feature_evalbytes")-1
248 && memcmp(subf+1, "valbytes", keylen - sizeof("feature_")) == 0) {
249 mask = FEATURE_EVALBYTES_BIT;
250 break;
251 }
252 return;
253
254 case 'f':
255 if (keylen == sizeof("feature_fc")-1
256 && memcmp(subf+1, "c", keylen - sizeof("feature_")) == 0) {
257 mask = FEATURE_FC_BIT;
258 break;
259 }
260 return;
261
813e85a0 262 case 'i':
0b657b19
DIM
263 if (keylen == sizeof("feature_indirect")-1
264 && memcmp(subf+1, "ndirect", keylen - sizeof("feature_")) == 0) {
265 mask = FEATURE_INDIRECT_BIT;
266 break;
267 }
268 else if (keylen == sizeof("feature_isa")-1
813e85a0
PLE
269 && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
270 mask = FEATURE_ISA_BIT;
271 break;
272 }
273 return;
274
b34c1a7e 275 case 'm':
1ad5a39c
TC
276 if (keylen == sizeof("feature_multidimensional")-1
277 && memcmp(subf+1, "ultidimensional", keylen - sizeof("feature_")) == 0) {
278 mask = FEATURE_MULTIDIMENSIONAL_BIT;
279 break;
280 }
281 else if (keylen == sizeof("feature_myref")-1
b34c1a7e
TC
282 && memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {
283 mask = FEATURE_MYREF_BIT;
284 break;
285 }
286 return;
287
288 case 'p':
289 if (keylen == sizeof("feature_postderef_qq")-1
290 && memcmp(subf+1, "ostderef_qq", keylen - sizeof("feature_")) == 0) {
291 mask = FEATURE_POSTDEREF_QQ_BIT;
292 break;
293 }
294 return;
295
296 case 'r':
297 if (keylen == sizeof("feature_refaliasing")-1
298 && memcmp(subf+1, "efaliasing", keylen - sizeof("feature_")) == 0) {
299 mask = FEATURE_REFALIASING_BIT;
300 break;
301 }
302 return;
303
304 case 's':
305 if (keylen == sizeof("feature_say")-1
306 && memcmp(subf+1, "ay", keylen - sizeof("feature_")) == 0) {
307 mask = FEATURE_SAY_BIT;
308 break;
309 }
310 else if (keylen == sizeof("feature_signatures")-1
311 && memcmp(subf+1, "ignatures", keylen - sizeof("feature_")) == 0) {
312 mask = FEATURE_SIGNATURES_BIT;
313 break;
314 }
315 else if (keylen == sizeof("feature_state")-1
316 && memcmp(subf+1, "tate", keylen - sizeof("feature_")) == 0) {
317 mask = FEATURE_STATE_BIT;
318 break;
319 }
320 else if (keylen == sizeof("feature_switch")-1
321 && memcmp(subf+1, "witch", keylen - sizeof("feature_")) == 0) {
322 mask = FEATURE_SWITCH_BIT;
323 break;
324 }
325 return;
326
327 case 'u':
328 if (keylen == sizeof("feature_unicode")-1
329 && memcmp(subf+1, "nicode", keylen - sizeof("feature_")) == 0) {
330 mask = FEATURE_UNICODE_BIT;
331 break;
332 }
333 else if (keylen == sizeof("feature_unieval")-1
334 && memcmp(subf+1, "nieval", keylen - sizeof("feature_")) == 0) {
335 mask = FEATURE_UNIEVAL_BIT;
336 break;
337 }
338 return;
339
340 default:
341 return;
342 }
343 if (valsv ? SvTRUE(valsv) : valbool)
344 PL_compiling.cop_features |= mask;
345 else
346 PL_compiling.cop_features &= ~mask;
347 }
348}
349#endif /* PERL_IN_MG_C */
350
3dd7db29
JK
351#endif /* PERL_FEATURE_H_ */
352
f2c01b15 353/* ex: set ro: */