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
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
8 #ifndef PERL_FEATURE_H_
9 #define PERL_FEATURE_H_
10
11 #if defined(PERL_CORE) || defined (PERL_EXT)
12
13 #define HINT_FEATURE_SHIFT      26
14
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
31
32 #define FEATURE_BUNDLE_DEFAULT  0
33 #define FEATURE_BUNDLE_510      1
34 #define FEATURE_BUNDLE_511      2
35 #define FEATURE_BUNDLE_515      3
36 #define FEATURE_BUNDLE_523      4
37 #define FEATURE_BUNDLE_527      5
38 #define FEATURE_BUNDLE_CUSTOM   (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
39
40 #define CURRENT_HINTS \
41     (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
42 #define CURRENT_FEATURE_BUNDLE \
43     ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
44
45 #define FEATURE_IS_ENABLED_MASK(mask)                   \
46   ((CURRENT_HINTS & HINT_LOCALIZE_HH)                \
47     ? (PL_curcop->cop_features & (mask)) : FALSE)
48
49 /* The longest string we pass in.  */
50 #define MAX_FEATURE_LEN (sizeof("multidimensional")-1)
51
52 #define FEATURE_FC_IS_ENABLED \
53     ( \
54         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
55          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
56      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
57          FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
58     )
59
60 #define FEATURE_ISA_IS_ENABLED \
61     ( \
62         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
63          FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
64     )
65
66 #define FEATURE_SAY_IS_ENABLED \
67     ( \
68         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
69          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
70      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
71          FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
72     )
73
74 #define FEATURE_STATE_IS_ENABLED \
75     ( \
76         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
77          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
78      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
79          FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
80     )
81
82 #define FEATURE_SWITCH_IS_ENABLED \
83     ( \
84         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
85          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
86      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
87          FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
88     )
89
90 #define FEATURE_BITWISE_IS_ENABLED \
91     ( \
92         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
93      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
94          FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
95     )
96
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
104 #define FEATURE_EVALBYTES_IS_ENABLED \
105     ( \
106         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
107          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
108      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
109          FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
110     )
111
112 #define FEATURE_SIGNATURES_IS_ENABLED \
113     ( \
114         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
115          FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
116     )
117
118 #define FEATURE___SUB___IS_ENABLED \
119     ( \
120         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
121          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
122      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
123          FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
124     )
125
126 #define FEATURE_REFALIASING_IS_ENABLED \
127     ( \
128         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
129          FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
130     )
131
132 #define FEATURE_POSTDEREF_QQ_IS_ENABLED \
133     ( \
134         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
135          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
136      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
137          FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
138     )
139
140 #define FEATURE_UNIEVAL_IS_ENABLED \
141     ( \
142         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
143          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
144      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
145          FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
146     )
147
148 #define FEATURE_MYREF_IS_ENABLED \
149     ( \
150         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
151          FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
152     )
153
154 #define FEATURE_UNICODE_IS_ENABLED \
155     ( \
156         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
157          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
158      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
159          FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
160     )
161
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
169
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
183 #endif /* PERL_CORE or PERL_EXT */
184
185 #ifdef PERL_IN_OP_C
186 PERL_STATIC_INLINE void
187 S_enable_feature_bundle(pTHX_ SV *ver)
188 {
189     SV *comp_ver = sv_newmortal();
190     PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
191              | (
192                   (sv_setnv(comp_ver, 5.027),
193                    vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
194                         ? FEATURE_BUNDLE_527 :
195                   (sv_setnv(comp_ver, 5.023),
196                    vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
197                         ? FEATURE_BUNDLE_523 :
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;
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;
213 }
214 #endif /* PERL_IN_OP_C */
215
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))
220 PERL_STATIC_INLINE void
221 S_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
262         case 'i':
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
269                  && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
270                 mask = FEATURE_ISA_BIT;
271                 break;
272             }
273             return;
274
275         case 'm':
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
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
351 #endif /* PERL_FEATURE_H_ */
352
353 /* ex: set ro: */