-
Notifications
You must be signed in to change notification settings - Fork 4
/
duktape.h
4459 lines (3930 loc) · 156 KB
/
duktape.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Duktape public API for Duktape 1.2.1.
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit 74bd1c845e5198b5e2d6cb7c98e54c3af1d6c0e4 (v1.2.1).
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
*/
/* LICENSE.txt */
/*
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2015 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
/* AUTHORS.rst */
/*
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code and agreed to irrevocably license
* their contributions under the Duktape ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <[email protected]>
* * Niki Dobrev
* * Andreas \u00d6man <[email protected]>
* * L\u00e1szl\u00f3 Lang\u00f3 <[email protected]>
* * Legimet <[email protected]>
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/hftmarkand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
*
* If you are accidentally missing from this list, send me an e-mail
* (``[email protected]``) and I'll fix the omission.
*/
#ifndef DUKTAPE_H_INCLUDED
#define DUKTAPE_H_INCLUDED
#define DUK_SINGLE_FILE
/*
* Determine platform features, select feature selection defines
* (e.g. _XOPEN_SOURCE), include system headers, and define DUK_USE_XXX
* defines which are (only) checked in Duktape internal code for
* activated features. Duktape feature selection is based on automatic
* feature detection, user supplied DUK_OPT_xxx defines, and optionally
* a "duk_custom.h" user header (if DUK_OPT_HAVE_CUSTOM_H is defined).
*
* When compiling Duktape, DUK_COMPILING_DUKTAPE is set, and this file
* is included before any system headers are included. Feature selection
* defines (e.g. _XOPEN_SOURCE) are defined here before any system headers
* are included (which is a requirement for system headers to work correctly).
* This file is responsible for including all system headers and contains
* all platform dependent cruft in general. When compiling user code,
* DUK_COMPILING_DUKTAPE is not defined, and we must avoid e.g. defining
* unnecessary feature selection defines.
*
* The general order of handling:
* - Compiler feature detection (require no includes)
* - Intermediate platform detection (-> easier platform defines)
* - Platform detection, system includes, byte order detection, etc
* - ANSI C wrappers (e.g. DUK_MEMCMP), wrappers for constants, etc
* - DUK_USE_xxx defines are resolved based on input defines
* - Duktape Date provider settings
* - Final sanity checks
*
* DUK_F_XXX are internal feature detection macros which should not be
* used outside this header.
*
* Useful resources:
*
* http://sourceforge.net/p/predef/wiki/Home/
* http://sourceforge.net/p/predef/wiki/Architectures/
* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Preprocessor defines available in a particular GCC:
*
* gcc -dM -E - </dev/null # http://www.brain-dump.org/blog/entry/107
*/
#ifndef DUK_FEATURES_H_INCLUDED
#define DUK_FEATURES_H_INCLUDED
/*
* Compiler features
*/
#undef DUK_F_C99
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define DUK_F_C99
#endif
#undef DUK_F_CPP
#if defined(__cplusplus)
#define DUK_F_CPP
#endif
#undef DUK_F_CPP11
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define DUK_F_CPP11
#endif
/*
* Provides the duk_rdtsc() inline function (if available), limited to
* GCC C99.
*
* See: http://www.mcs.anl.gov/~kazutomo/rdtsc.html
*/
/* XXX: more accurate detection of what gcc versions work; more inline
* asm versions for other compilers.
*/
#if defined(__GNUC__) && defined(__i386__) && defined(DUK_F_C99) && \
!defined(__cplusplus) /* unsigned long long not standard */
static __inline__ unsigned long long duk_rdtsc(void) {
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#define DUK_RDTSC_AVAILABLE 1
#elif defined(__GNUC__) && defined(__x86_64__) && defined(DUK_F_C99) && \
!defined(__cplusplus) /* unsigned long long not standard */
static __inline__ unsigned long long duk_rdtsc(void) {
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long) lo) | (((unsigned long long) hi) << 32);
}
#define DUK_RDTSC_AVAILABLE 1
#else
/* not available */
#undef DUK_RDTSC_AVAILABLE
#endif
/*
* Intermediate platform, architecture, and compiler detection. These are
* hopelessly intertwined - e.g. architecture defines depend on compiler etc.
*
* Provide easier defines for platforms and compilers which are often tricky
* or verbose to detect. The intent is not to provide intermediate defines for
* all features; only if existing feature defines are inconvenient.
*/
/* Intel x86 (32-bit) */
#if defined(i386) || defined(__i386) || defined(__i386__) || \
defined(__i486__) || defined(__i586__) || defined(__i686__) || \
defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
#define DUK_F_X86
#endif
/* AMD64 (64-bit) */
#if defined(__amd64__) || defined(__amd64) || \
defined(__x86_64__) || defined(__x86_64) || \
defined(_M_X64) || defined(_M_AMD64)
#define DUK_F_X64
#endif
/* X32: 64-bit with 32-bit pointers (allows packed tvals). X32 support is
* not very mature yet.
*
* https://sites.google.com/site/x32abi/
*/
#if defined(DUK_F_X64) && \
(defined(_ILP32) || defined(__ILP32__))
#define DUK_F_X32
/* define only one of: DUK_F_X86, DUK_F_X32, or DUK_F_X64 */
#undef DUK_F_X64
#undef DUK_F_X86
#endif
/* ARM */
#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
#define DUK_F_ARM
#endif
/* MIPS */
/* Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
defined(_R3000) || defined(_R4000) || defined(_R5900) || \
defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
defined(__mips) || defined(__MIPS__)
#define DUK_F_MIPS
#if defined(__LP64__) || defined(__mips64) || defined(__mips64__) || \
defined(__mips_n64)
#define DUK_F_MIPS64
#else
#define DUK_F_MIPS32
#endif
#endif
/* SuperH */
#if defined(__sh__) || \
defined(__sh1__) || defined(__SH1__) || \
defined(__sh2__) || defined(__SH2__) || \
defined(__sh3__) || defined(__SH3__) || \
defined(__sh4__) || defined(__SH4__) || \
defined(__sh5__) || defined(__SH5__)
#define DUK_F_SUPERH
#endif
/* Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
*/
#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
#define DUK_F_M68K
#endif
/* Linux */
#if defined(__linux) || defined(__linux__) || defined(linux)
#define DUK_F_LINUX
#endif
/* FreeBSD */
#if defined(__FreeBSD__) || defined(__FreeBSD)
#define DUK_F_FREEBSD
#endif
/* NetBSD */
#if defined(__NetBSD__) || defined(__NetBSD)
#define DUK_F_NETBSD
#endif
/* OpenBSD */
#if defined(__OpenBSD__) || defined(__OpenBSD)
#define DUK_F_OPENBSD
#endif
/* BSD variant */
#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
defined(__bsdi__) || defined(__DragonFly__)
#define DUK_F_BSD
#endif
/* Generic Unix (includes Cygwin) */
#if defined(__unix) || defined(__unix__) || defined(unix) || \
defined(DUK_F_LINUX) || defined(DUK_F_BSD)
#define DUK_F_UNIX
#endif
/* Cygwin */
#if defined(__CYGWIN__)
#define DUK_F_CYGWIN
#endif
/* Windows (32-bit or above) */
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
#define DUK_F_WINDOWS
#endif
#if defined(__APPLE__)
#define DUK_F_APPLE
#endif
/* Atari ST TOS. __TOS__ defined by PureC (which doesn't work as a target now
* because int is 16-bit, to be fixed). No platform define in VBCC apparently,
* so to use with VBCC, user must define '__TOS__' manually.
*/
#if defined(__TOS__)
#define DUK_F_TOS
#endif
/* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually.
*/
#if defined(AMIGA) || defined(__amigaos__)
#define DUK_F_AMIGAOS
#endif
/* Flash player (e.g. Crossbridge) */
#if defined(__FLASHPLAYER__)
#define DUK_F_FLASHPLAYER
#endif
/* Emscripten (provided explicitly by user), improve if possible */
#if defined(EMSCRIPTEN)
#define DUK_F_EMSCRIPTEN
#endif
/* QNX */
#if defined(__QNX__)
#define DUK_F_QNX
#endif
/* TI-Nspire (using Ndless) */
#if defined(_TINSPIRE)
#define DUK_F_TINSPIRE
#endif
/* GCC and GCC version convenience define. */
#if defined(__GNUC__)
#define DUK_F_GCC
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
#define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
#else
#error cannot figure out gcc version
#endif
#endif
/* Clang */
#if defined(__clang__)
#define DUK_F_CLANG
/* It seems clang also defines __GNUC__, so undo the GCC detection. */
#if defined(DUK_F_GCC)
#undef DUK_F_GCC
#endif
#if defined(DUK_F_GCC_VERSION)
#undef DUK_F_GCC_VERSION
#endif
#endif
/* MSVC */
#if defined(_MSC_VER)
/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
*/
#define DUK_F_MSVC
#if defined(_MSC_FULL_VER)
#if (_MSC_FULL_VER > 100000000)
#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
#else
#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
#endif
#endif
#endif /* _MSC_VER */
/* MinGW */
#if defined(__MINGW32__) || defined(__MINGW64__)
/* NOTE: Also GCC flags are detected (DUK_F_GCC etc). */
#define DUK_F_MINGW
#endif
/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
#if defined(__BCC__) || defined(__BCC_VERSION__)
#define DUK_F_BCC
#endif
#if defined(__VBCC__)
#define DUK_F_VBCC
#endif
#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
!defined(DUK_F_BCC)
/* ULL / LL preprocessor constants should be avoided because they're not
* always available. With suitable options, some compilers will support
* 64-bit integer types but won't support ULL / LL preprocessor constants.
* Assume C99/C++11 environments have these. However, BCC is nominally
* C99 but doesn't support these constants.
*/
#define DUK_F_ULL_CONSTS
#endif
/*
* Platform detection, system includes, Date provider selection.
*
* Feature selection (e.g. _XOPEN_SOURCE) must happen before any system
* headers are included. This header should avoid providing any feature
* selection defines when compiling user code (only when compiling Duktape
* itself). If a feature selection option is required for user code to
* compile correctly (e.g. it is needed for type detection), it should
* probably be -checked- here, not defined here.
*
* Date provider selection seems a bit out-of-place here, but since
* the date headers and provider functions are heavily platform
* specific, there's little point in duplicating the platform if-else
* ladder. All platform specific Date provider functions are in
* duk_bi_date.c; here we provide appropriate #defines to enable them,
* and include all the necessary system headers so that duk_bi_date.c
* compiles. Date "providers" are:
*
* NOW = getting current time (required)
* TZO = getting local time offset (required)
* PRS = parse datetime (optional)
* FMT = format datetime (optional)
*
* There's a lot of duplication here, unfortunately, because many
* platforms have similar (but not identical) headers, Date providers,
* etc. The duplication could be removed by more complicated nested
* #ifdefs, but it would then be more difficult to make fixes which
* affect only a specific platform.
*
* XXX: add a way to provide custom functions to provide the critical
* primitives; this would be convenient when porting to unknown platforms
* (rather than muck with Duktape internals).
*/
#if defined(DUK_COMPILING_DUKTAPE) && \
(defined(DUK_F_LINUX) || defined(DUK_F_EMSCRIPTEN))
/* A more recent Emscripten (2014-05) seems to lack "linux" environment
* defines, so check for Emscripten explicitly.
*/
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* e.g. getdate_r */
#endif
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE /* e.g. strptime */
#endif
#endif
#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
#define _XOPEN_SOURCE 600
#define _POSIX_C_SOURCE 200112L
#endif
#undef DUK_F_MSVC_CRT_SECURE
#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
/* http://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx
* http://msdn.microsoft.com/en-us/library/wd3wzwts.aspx
* Seem to be available since VS2005.
*/
#if (_MSC_VER >= 1400)
/* VS2005+, secure CRT functions are preferred. Windows Store applications
* (and probably others) should use these.
*/
#define DUK_F_MSVC_CRT_SECURE
#endif
#if (_MSC_VER < 1700)
/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
#define DUK_F_NO_STDINT_H
#endif
/* Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
*/
#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif /* DUK_F_WINDOWS && _MSC_VER */
#if defined(DUK_F_TOS) || defined(DUK_F_BCC)
#define DUK_F_NO_STDINT_H
#endif
/* Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
*/
#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
#define __STDC_LIMIT_MACROS
#endif
#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
#define __STDC_CONSTANT_MACROS
#endif
#if defined(__APPLE__)
/* Mac OSX, iPhone, Darwin */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <TargetConditionals.h>
#include <architecture/byte_order.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_OPENBSD)
/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <sys/endian.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_BSD)
/* other BSD */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <sys/endian.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_TOS)
/* Atari ST TOS */
#define DUK_USE_DATE_NOW_TIME
#define DUK_USE_DATE_TZO_GMTIME
/* no parsing (not an error) */
#define DUK_USE_DATE_FMT_STRFTIME
#include <limits.h>
#include <time.h>
#elif defined(DUK_F_AMIGAOS)
#if defined(DUK_F_M68K)
/* AmigaOS on M68k */
#define DUK_USE_DATE_NOW_TIME
#define DUK_USE_DATE_TZO_GMTIME
/* no parsing (not an error) */
#define DUK_USE_DATE_FMT_STRFTIME
#include <limits.h>
#include <time.h>
#else
#error AmigaOS but not M68K, not supported now
#endif
#elif defined(DUK_F_WINDOWS)
/* Windows 32-bit and 64-bit are currently the same. */
/* MSVC does not have sys/param.h */
#define DUK_USE_DATE_NOW_WINDOWS
#define DUK_USE_DATE_TZO_WINDOWS
/* Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
*/
#include <windows.h>
#include <limits.h>
#elif defined(DUK_F_FLASHPLAYER)
/* Crossbridge */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <endian.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_QNX)
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_TINSPIRE)
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_LINUX)
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#if defined(DUK_F_BCC)
/* no endian.h */
#else
#include <endian.h>
#endif /* DUK_F_BCC */
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(__posix)
/* POSIX */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <endian.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#elif defined(DUK_F_CYGWIN)
/* Cygwin -- don't use strptime() for now */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#include <endian.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#else
/* Other UNIX, hopefully others */
#define DUK_USE_DATE_NOW_GETTIMEOFDAY
#define DUK_USE_DATE_TZO_GMTIME_R
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
#include <sys/types.h>
#if defined(DUK_F_BCC)
/* no endian.h */
#else
#include <endian.h>
#endif /* DUK_F_BCC */
#include <limits.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#endif
/* Shared includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h> /* varargs */
#include <setjmp.h>
#include <stddef.h> /* e.g. ptrdiff_t */
#if defined(DUK_F_NO_STDINT_H)
/* stdint.h not available */
#else
/* Technically C99 (C++11) but found in many systems. Note the workaround
* above for some C++ compilers (__STDC_LIMIT_MACROS etc).
*/
#include <stdint.h>
#endif
#include <math.h>
/*
* Detection for specific libc variants (like uclibc) and other libc specific
* features. Potentially depends on the #includes above.
*/
#if defined(__UCLIBC__)
#define DUK_F_UCLIBC
#endif
/*
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
*/
/* XXX: add feature options to force basic types from outside? */
#if !defined(INT_MAX)
#error INT_MAX not defined
#endif
/* Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
*/
#if defined(INT_MAX) && defined(INT_MIN)
#if INT_MAX != -(INT_MIN + 1)
#error platform does not seem complement of two
#endif
#else
#error cannot check complement of two
#endif
/* Pointer size determination based on architecture.
* XXX: unsure about BCC correctness.
*/
#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
defined(DUK_F_BCC) || \
(defined(__WORDSIZE) && (__WORDSIZE == 32))
#define DUK_F_32BIT_PTRS
#elif defined(DUK_F_X64) || \
(defined(__WORDSIZE) && (__WORDSIZE == 64))
#define DUK_F_64BIT_PTRS
#else
/* not sure, not needed with C99 anyway */
#endif
/* Intermediate define for 'have inttypes.h' */
#undef DUK_F_HAVE_INTTYPES
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
!(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
/* vbcc + AmigaOS has C99 but no inttypes.h */
#define DUK_F_HAVE_INTTYPES
#elif defined(__cplusplus) && (__cplusplus >= 201103L)
/* C++11 apparently ratified stdint.h */
#define DUK_F_HAVE_INTTYPES
#endif
/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
*/
#if defined(DUK_F_HAVE_INTTYPES)
/* C99 or compatible */
#define DUK_F_HAVE_64BIT
#include <inttypes.h>
typedef uint8_t duk_uint8_t;
typedef int8_t duk_int8_t;
typedef uint16_t duk_uint16_t;
typedef int16_t duk_int16_t;
typedef uint32_t duk_uint32_t;
typedef int32_t duk_int32_t;
typedef uint64_t duk_uint64_t;
typedef int64_t duk_int64_t;
typedef uint_least8_t duk_uint_least8_t;
typedef int_least8_t duk_int_least8_t;
typedef uint_least16_t duk_uint_least16_t;
typedef int_least16_t duk_int_least16_t;
typedef uint_least32_t duk_uint_least32_t;
typedef int_least32_t duk_int_least32_t;
typedef uint_least64_t duk_uint_least64_t;
typedef int_least64_t duk_int_least64_t;
typedef uint_fast8_t duk_uint_fast8_t;
typedef int_fast8_t duk_int_fast8_t;
typedef uint_fast16_t duk_uint_fast16_t;
typedef int_fast16_t duk_int_fast16_t;
typedef uint_fast32_t duk_uint_fast32_t;
typedef int_fast32_t duk_int_fast32_t;
typedef uint_fast64_t duk_uint_fast64_t;
typedef int_fast64_t duk_int_fast64_t;
typedef uintptr_t duk_uintptr_t;
typedef intptr_t duk_intptr_t;
typedef uintmax_t duk_uintmax_t;
typedef intmax_t duk_intmax_t;
#define DUK_UINT8_MIN 0
#define DUK_UINT8_MAX UINT8_MAX
#define DUK_INT8_MIN INT8_MIN
#define DUK_INT8_MAX INT8_MAX
#define DUK_UINT_LEAST8_MIN 0
#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
#define DUK_UINT_FAST8_MIN 0
#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
#define DUK_INT_FAST8_MIN INT_FAST8_MIN
#define DUK_INT_FAST8_MAX INT_FAST8_MAX
#define DUK_UINT16_MIN 0
#define DUK_UINT16_MAX UINT16_MAX
#define DUK_INT16_MIN INT16_MIN
#define DUK_INT16_MAX INT16_MAX
#define DUK_UINT_LEAST16_MIN 0
#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
#define DUK_UINT_FAST16_MIN 0
#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
#define DUK_INT_FAST16_MIN INT_FAST16_MIN
#define DUK_INT_FAST16_MAX INT_FAST16_MAX
#define DUK_UINT32_MIN 0
#define DUK_UINT32_MAX UINT32_MAX
#define DUK_INT32_MIN INT32_MIN
#define DUK_INT32_MAX INT32_MAX
#define DUK_UINT_LEAST32_MIN 0
#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
#define DUK_UINT_FAST32_MIN 0
#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
#define DUK_INT_FAST32_MIN INT_FAST32_MIN
#define DUK_INT_FAST32_MAX INT_FAST32_MAX
#define DUK_UINT64_MIN 0
#define DUK_UINT64_MAX UINT64_MAX
#define DUK_INT64_MIN INT64_MIN
#define DUK_INT64_MAX INT64_MAX
#define DUK_UINT_LEAST64_MIN 0
#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
#define DUK_UINT_FAST64_MIN 0
#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
#define DUK_INT_FAST64_MIN INT_FAST64_MIN
#define DUK_INT_FAST64_MAX INT_FAST64_MAX
#define DUK_UINTPTR_MIN 0
#define DUK_UINTPTR_MAX UINTPTR_MAX
#define DUK_INTPTR_MIN INTPTR_MIN
#define DUK_INTPTR_MAX INTPTR_MAX
#define DUK_UINTMAX_MIN 0
#define DUK_UINTMAX_MAX UINTMAX_MAX
#define DUK_INTMAX_MIN INTMAX_MIN
#define DUK_INTMAX_MAX INTMAX_MAX
#define DUK_SIZE_MIN 0
#define DUK_SIZE_MAX SIZE_MAX
#else /* C99 types */
/* When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
*/
#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
(defined(UCHAR_MAX) && (UCHAR_MAX == 255))
typedef unsigned char duk_uint8_t;
typedef signed char duk_int8_t;
#else
#error cannot detect 8-bit type
#endif
#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
typedef unsigned short duk_uint16_t;
typedef signed short duk_int16_t;
#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
typedef unsigned int duk_uint16_t;
typedef signed int duk_int16_t;
#else
#error cannot detect 16-bit type
#endif
#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
typedef unsigned int duk_uint32_t;
typedef signed int duk_int32_t;
#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
typedef unsigned long duk_uint32_t;
typedef signed long duk_int32_t;
#else
#error cannot detect 32-bit type
#endif
/* 64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
*/
#undef DUK_F_HAVE_64BIT
#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
#if (ULONG_MAX > 4294967295UL)
#define DUK_F_HAVE_64BIT
typedef unsigned long duk_uint64_t;
typedef signed long duk_int64_t;
#endif
#endif
#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
#if (ULLONG_MAX > 4294967295UL)
#define DUK_F_HAVE_64BIT
typedef unsigned long long duk_uint64_t;
typedef signed long long duk_int64_t;
#endif
#endif
#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
#if (__ULONG_LONG_MAX__ > 4294967295UL)
#define DUK_F_HAVE_64BIT
typedef unsigned long long duk_uint64_t;
typedef signed long long duk_int64_t;
#endif
#endif
#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
#if (__LONG_LONG_MAX__ > 2147483647L)
#define DUK_F_HAVE_64BIT
typedef unsigned long long duk_uint64_t;
typedef signed long long duk_int64_t;
#endif
#endif
#if !defined(DUK_F_HAVE_64BIT) && \
(defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
/* Both MinGW and MSVC have a 64-bit type. */
#define DUK_F_HAVE_64BIT
typedef unsigned long duk_uint64_t;
typedef signed long duk_int64_t;
#endif
#if !defined(DUK_F_HAVE_64BIT)
/* cannot detect 64-bit type, not always needed so don't error */
#endif
typedef duk_uint8_t duk_uint_least8_t;
typedef duk_int8_t duk_int_least8_t;
typedef duk_uint16_t duk_uint_least16_t;
typedef duk_int16_t duk_int_least16_t;
typedef duk_uint32_t duk_uint_least32_t;
typedef duk_int32_t duk_int_least32_t;
typedef duk_uint8_t duk_uint_fast8_t;
typedef duk_int8_t duk_int_fast8_t;
typedef duk_uint16_t duk_uint_fast16_t;
typedef duk_int16_t duk_int_fast16_t;
typedef duk_uint32_t duk_uint_fast32_t;
typedef duk_int32_t duk_int_fast32_t;
#if defined(DUK_F_HAVE_64BIT)
typedef duk_uint64_t duk_uint_least64_t;
typedef duk_int64_t duk_int_least64_t;
typedef duk_uint64_t duk_uint_fast64_t;
typedef duk_int64_t duk_int_fast64_t;
#endif
#if defined(DUK_F_HAVE_64BIT)
typedef duk_uint64_t duk_uintmax_t;
typedef duk_int64_t duk_intmax_t;
#else
typedef duk_uint32_t duk_uintmax_t;
typedef duk_int32_t duk_intmax_t;
#endif
/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
*/
#define DUK_UINT8_MIN 0UL
#define DUK_UINT8_MAX 0xffUL