This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
No code specified for -.
[perl5.git] / ext / Time / HiRes / fallback / const-c.inc
CommitLineData
98b50af3
JH
1#define PERL_constant_NOTFOUND 1
2#define PERL_constant_NOTDEF 2
3#define PERL_constant_ISIV 3
4#define PERL_constant_ISNO 4
5#define PERL_constant_ISNV 5
6#define PERL_constant_ISPV 6
7#define PERL_constant_ISPVN 7
8#define PERL_constant_ISSV 8
9#define PERL_constant_ISUNDEF 9
10#define PERL_constant_ISUV 10
11#define PERL_constant_ISYES 11
12
13#ifndef NVTYPE
14typedef double NV; /* 5.6 and later define NVTYPE, and typedef NV to it. */
15#endif
16#ifndef aTHX_
17#define aTHX_ /* 5.6 or later define this for threading support. */
18#endif
19#ifndef pTHX_
20#define pTHX_ /* 5.6 or later define this for threading support. */
21#endif
170c5524 22
98b50af3
JH
23static int
24constant_11 (pTHX_ const char *name, IV *iv_return) {
25 /* When generated this function returned values for the list of names given
26 here. However, subsequent manual editing may have added or removed some.
27 ITIMER_PROF ITIMER_REAL d_getitimer d_nanosleep d_setitimer */
28 /* Offset 7 gives the best switch position. */
29 switch (name[7]) {
30 case 'P':
31 if (memEQ(name, "ITIMER_PROF", 11)) {
32 /* ^ */
33#ifdef ITIMER_PROF
34 *iv_return = ITIMER_PROF;
35 return PERL_constant_ISIV;
36#else
37 return PERL_constant_NOTDEF;
38#endif
39 }
40 break;
41 case 'R':
42 if (memEQ(name, "ITIMER_REAL", 11)) {
43 /* ^ */
44#ifdef ITIMER_REAL
45 *iv_return = ITIMER_REAL;
46 return PERL_constant_ISIV;
47#else
48 return PERL_constant_NOTDEF;
49#endif
50 }
51 break;
52 case 'i':
53 if (memEQ(name, "d_getitimer", 11)) {
54 /* ^ */
55#ifdef HAS_GETITIMER
56 *iv_return = 1;
57 return PERL_constant_ISIV;
58#else
59 *iv_return = 0;
60 return PERL_constant_ISIV;
61#endif
62 }
63 if (memEQ(name, "d_setitimer", 11)) {
64 /* ^ */
65#ifdef HAS_SETITIMER
66 *iv_return = 1;
67 return PERL_constant_ISIV;
68#else
69 *iv_return = 0;
70 return PERL_constant_ISIV;
71#endif
72 }
73 break;
74 case 'l':
75 if (memEQ(name, "d_nanosleep", 11)) {
76 /* ^ */
ced84e60
SP
77#ifdef TIME_HIRES_NANOSLEEP
78 *iv_return = 1;
79 return PERL_constant_ISIV;
80#else
81 *iv_return = 0;
82 return PERL_constant_ISIV;
83#endif
84 }
85 break;
86 }
87 return PERL_constant_NOTFOUND;
88}
89
90static int
91constant_14 (pTHX_ const char *name, IV *iv_return) {
92 /* When generated this function returned values for the list of names given
93 here. However, subsequent manual editing may have added or removed some.
170c5524
SP
94 CLOCKS_PER_SEC CLOCK_REALTIME CLOCK_SOFTTIME ITIMER_VIRTUAL d_clock_getres
95 d_gettimeofday */
96 /* Offset 8 gives the best switch position. */
97 switch (name[8]) {
98 case 'A':
ced84e60 99 if (memEQ(name, "CLOCK_REALTIME", 14)) {
170c5524 100 /* ^ */
ced84e60
SP
101#ifdef CLOCK_REALTIME
102 *iv_return = CLOCK_REALTIME;
103 return PERL_constant_ISIV;
104#else
105 return PERL_constant_NOTDEF;
106#endif
107 }
108 break;
170c5524
SP
109 case 'E':
110 if (memEQ(name, "CLOCKS_PER_SEC", 14)) {
111 /* ^ */
112#ifdef CLOCKS_PER_SEC
113 *iv_return = CLOCKS_PER_SEC;
114 return PERL_constant_ISIV;
115#else
116 return PERL_constant_NOTDEF;
117#endif
118 }
119 break;
120 case 'F':
121 if (memEQ(name, "CLOCK_SOFTTIME", 14)) {
122 /* ^ */
123#ifdef CLOCK_SOFTTIME
124 *iv_return = CLOCK_SOFTTIME;
125 return PERL_constant_ISIV;
126#else
127 return PERL_constant_NOTDEF;
128#endif
129 }
130 break;
131 case 'I':
ced84e60 132 if (memEQ(name, "ITIMER_VIRTUAL", 14)) {
170c5524 133 /* ^ */
ced84e60
SP
134#ifdef ITIMER_VIRTUAL
135 *iv_return = ITIMER_VIRTUAL;
136 return PERL_constant_ISIV;
137#else
138 return PERL_constant_NOTDEF;
139#endif
140 }
141 break;
170c5524 142 case 'e':
ced84e60 143 if (memEQ(name, "d_gettimeofday", 14)) {
170c5524 144 /* ^ */
ced84e60
SP
145#ifdef HAS_GETTIMEOFDAY
146 *iv_return = 1;
147 return PERL_constant_ISIV;
148#else
149 *iv_return = 0;
150 return PERL_constant_ISIV;
151#endif
152 }
153 break;
170c5524 154 case 'g':
ced84e60 155 if (memEQ(name, "d_clock_getres", 14)) {
170c5524 156 /* ^ */
ced84e60
SP
157#ifdef TIME_HIRES_CLOCK_GETRES
158 *iv_return = 1;
159 return PERL_constant_ISIV;
160#else
161 *iv_return = 0;
162 return PERL_constant_ISIV;
163#endif
164 }
165 break;
166 }
167 return PERL_constant_NOTFOUND;
168}
169
170static int
171constant_15 (pTHX_ const char *name, IV *iv_return) {
172 /* When generated this function returned values for the list of names given
173 here. However, subsequent manual editing may have added or removed some.
174 CLOCK_MONOTONIC CLOCK_TIMEOFDAY ITIMER_REALPROF d_clock_gettime */
175 /* Offset 7 gives the best switch position. */
176 switch (name[7]) {
177 case 'I':
178 if (memEQ(name, "CLOCK_TIMEOFDAY", 15)) {
179 /* ^ */
180#ifdef CLOCK_TIMEOFDAY
181 *iv_return = CLOCK_TIMEOFDAY;
182 return PERL_constant_ISIV;
183#else
184 return PERL_constant_NOTDEF;
185#endif
186 }
187 break;
188 case 'O':
189 if (memEQ(name, "CLOCK_MONOTONIC", 15)) {
190 /* ^ */
191#ifdef CLOCK_MONOTONIC
192 *iv_return = CLOCK_MONOTONIC;
193 return PERL_constant_ISIV;
194#else
195 return PERL_constant_NOTDEF;
196#endif
197 }
198 break;
199 case 'R':
200 if (memEQ(name, "ITIMER_REALPROF", 15)) {
201 /* ^ */
202#ifdef ITIMER_REALPROF
203 *iv_return = ITIMER_REALPROF;
204 return PERL_constant_ISIV;
205#else
206 return PERL_constant_NOTDEF;
207#endif
208 }
209 break;
210 case '_':
211 if (memEQ(name, "d_clock_gettime", 15)) {
212 /* ^ */
213#ifdef TIME_HIRES_CLOCK_GETTIME
98b50af3
JH
214 *iv_return = 1;
215 return PERL_constant_ISIV;
216#else
217 *iv_return = 0;
218 return PERL_constant_ISIV;
219#endif
220 }
221 break;
222 }
223 return PERL_constant_NOTFOUND;
224}
225
226static int
227constant (pTHX_ const char *name, STRLEN len, IV *iv_return) {
228 /* Initially switch on the length of the name. */
229 /* When generated this function returned values for the list of names given
230 in this section of perl code. Rather than manually editing these functions
231 to add or remove constants, which would result in this comment and section
232 of code becoming inaccurate, we recommend that you edit this section of
233 code, and use it to regenerate a new set of constant functions which you
234 then use to replace the originals.
235
236 Regenerate these constant functions by feeding this entire source file to
237 perl -x
238
ced84e60 239#!perl -w
98b50af3
JH
240use ExtUtils::Constant qw (constant_types C_constant XS_constant);
241
242my $types = {map {($_, 1)} qw(IV)};
170c5524
SP
243my @names = (qw(CLOCKS_PER_SEC CLOCK_HIGHRES CLOCK_MONOTONIC
244 CLOCK_PROCESS_CPUTIME_ID CLOCK_REALTIME CLOCK_SOFTTIME
245 CLOCK_THREAD_CPUTIME_ID CLOCK_TIMEOFDAY ITIMER_PROF ITIMER_REAL
246 ITIMER_REALPROF ITIMER_VIRTUAL TIMER_ABSTIME),
247 {name=>"d_clock", type=>"IV", macro=>"TIME_HIRES_CLOCK", value=>"1", default=>["IV", "0"]},
ced84e60
SP
248 {name=>"d_clock_getres", type=>"IV", macro=>"TIME_HIRES_CLOCK_GETRES", value=>"1", default=>["IV", "0"]},
249 {name=>"d_clock_gettime", type=>"IV", macro=>"TIME_HIRES_CLOCK_GETTIME", value=>"1", default=>["IV", "0"]},
170c5524 250 {name=>"d_clock_nanosleep", type=>"IV", macro=>"TIME_HIRES_CLOCK_NANOSLEEP", value=>"1", default=>["IV", "0"]},
98b50af3
JH
251 {name=>"d_getitimer", type=>"IV", macro=>"HAS_GETITIMER", value=>"1", default=>["IV", "0"]},
252 {name=>"d_gettimeofday", type=>"IV", macro=>"HAS_GETTIMEOFDAY", value=>"1", default=>["IV", "0"]},
ced84e60 253 {name=>"d_nanosleep", type=>"IV", macro=>"TIME_HIRES_NANOSLEEP", value=>"1", default=>["IV", "0"]},
98b50af3
JH
254 {name=>"d_setitimer", type=>"IV", macro=>"HAS_SETITIMER", value=>"1", default=>["IV", "0"]},
255 {name=>"d_ualarm", type=>"IV", macro=>"HAS_UALARM", value=>"1", default=>["IV", "0"]},
256 {name=>"d_usleep", type=>"IV", macro=>"HAS_USLEEP", value=>"1", default=>["IV", "0"]});
257
258print constant_types(); # macro defs
259foreach (C_constant ("Time::HiRes", 'constant', 'IV', $types, undef, 3, @names) ) {
260 print $_, "\n"; # C constant subs
261}
262print "#### XS Section:\n";
263print XS_constant ("Time::HiRes", $types);
264__END__
265 */
266
267 switch (len) {
170c5524
SP
268 case 7:
269 if (memEQ(name, "d_clock", 7)) {
270#ifdef TIME_HIRES_CLOCK
271 *iv_return = 1;
272 return PERL_constant_ISIV;
273#else
274 *iv_return = 0;
275 return PERL_constant_ISIV;
276#endif
277 }
278 break;
98b50af3
JH
279 case 8:
280 /* Names all of length 8. */
281 /* d_ualarm d_usleep */
282 /* Offset 7 gives the best switch position. */
283 switch (name[7]) {
284 case 'm':
ced84e60
SP
285 if (memEQ(name, "d_ualar", 7)) {
286 /* m */
98b50af3
JH
287#ifdef HAS_UALARM
288 *iv_return = 1;
289 return PERL_constant_ISIV;
290#else
291 *iv_return = 0;
292 return PERL_constant_ISIV;
293#endif
294 }
295 break;
296 case 'p':
ced84e60
SP
297 if (memEQ(name, "d_uslee", 7)) {
298 /* p */
98b50af3
JH
299#ifdef HAS_USLEEP
300 *iv_return = 1;
301 return PERL_constant_ISIV;
302#else
303 *iv_return = 0;
304 return PERL_constant_ISIV;
305#endif
306 }
307 break;
308 }
309 break;
310 case 11:
311 return constant_11 (aTHX_ name, iv_return);
312 break;
ced84e60 313 case 13:
170c5524
SP
314 /* Names all of length 13. */
315 /* CLOCK_HIGHRES TIMER_ABSTIME */
316 /* Offset 2 gives the best switch position. */
317 switch (name[2]) {
318 case 'M':
319 if (memEQ(name, "TIMER_ABSTIME", 13)) {
320 /* ^ */
321#ifdef TIMER_ABSTIME
322 *iv_return = TIMER_ABSTIME;
323 return PERL_constant_ISIV;
324#else
325 return PERL_constant_NOTDEF;
326#endif
327 }
328 break;
329 case 'O':
330 if (memEQ(name, "CLOCK_HIGHRES", 13)) {
331 /* ^ */
ced84e60 332#ifdef CLOCK_HIGHRES
170c5524
SP
333 *iv_return = CLOCK_HIGHRES;
334 return PERL_constant_ISIV;
98b50af3 335#else
170c5524 336 return PERL_constant_NOTDEF;
98b50af3 337#endif
170c5524
SP
338 }
339 break;
ced84e60
SP
340 }
341 break;
342 case 14:
343 return constant_14 (aTHX_ name, iv_return);
344 break;
345 case 15:
346 return constant_15 (aTHX_ name, iv_return);
347 break;
170c5524
SP
348 case 17:
349 if (memEQ(name, "d_clock_nanosleep", 17)) {
350#ifdef TIME_HIRES_CLOCK_NANOSLEEP
351 *iv_return = 1;
352 return PERL_constant_ISIV;
353#else
354 *iv_return = 0;
355 return PERL_constant_ISIV;
356#endif
357 }
358 break;
ced84e60
SP
359 case 23:
360 if (memEQ(name, "CLOCK_THREAD_CPUTIME_ID", 23)) {
361#ifdef CLOCK_THREAD_CPUTIME_ID
362 *iv_return = CLOCK_THREAD_CPUTIME_ID;
363 return PERL_constant_ISIV;
98b50af3 364#else
ced84e60 365 return PERL_constant_NOTDEF;
98b50af3 366#endif
98b50af3
JH
367 }
368 break;
ced84e60
SP
369 case 24:
370 if (memEQ(name, "CLOCK_PROCESS_CPUTIME_ID", 24)) {
371#ifdef CLOCK_PROCESS_CPUTIME_ID
372 *iv_return = CLOCK_PROCESS_CPUTIME_ID;
98b50af3
JH
373 return PERL_constant_ISIV;
374#else
375 return PERL_constant_NOTDEF;
376#endif
377 }
378 break;
379 }
380 return PERL_constant_NOTFOUND;
381}
382