Skip to content

Commit 21726f5

Browse files
committed
Adding premake4.lua and glue for old MSVC versions
- Glue code is based on the stdint.h from Android's libusb_aah, which I mentioned in libtomcrypt#577, I added the stdbool.h stuff, too. - This required adjusting the main header: tommath.h - Minor adjustments were needed in s_mp_rand_platform.c to make it work with older Windows SDKs - The premake4.lua was tested thoroughly with VS2003 through VS2022 Some refinements after testing on VS2019 and VS2022
1 parent 66de864 commit 21726f5

File tree

4 files changed

+622
-0
lines changed

4 files changed

+622
-0
lines changed

old_msvc_glue.h

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/* SPDX-License-Identifier: Unlicense */
2+
/**
3+
* This file has no copyright assigned and is placed in the Public Domain.
4+
* This file was originally part of the w64 mingw-runtime package.
5+
* From there it was borrowed by libusb_aah into the Android source tree,
6+
* from where it was picked up for libtommath.
7+
*/
8+
/* ISO C9x 7.18 Integer types <stdint.h>
9+
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
10+
*
11+
* THIS SOFTWARE IS NOT COPYRIGHTED
12+
*
13+
* Contributor: Danny Smith <[email protected]>
14+
* Modified for libusb/MSVC: Pete Batard <[email protected]>
15+
*
16+
* This source code is offered for use in the public domain. You may
17+
* use, modify or distribute it freely.
18+
*
19+
* This code is distributed in the hope that it will be useful but
20+
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
21+
* DISCLAIMED. This includes but is not limited to warranties of
22+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
*
24+
* Date: 2010-04-02
25+
*/
26+
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
27+
#error This header should only be used with Microsoft compilers before 16.0 (VS2010)
28+
#endif
29+
#ifndef _STDINT_H
30+
#define _STDINT_H
31+
#ifndef _INTPTR_T_DEFINED
32+
#define _INTPTR_T_DEFINED
33+
#ifndef __intptr_t_defined
34+
#define __intptr_t_defined
35+
#undef intptr_t
36+
#ifdef _WIN64
37+
typedef __int64 intptr_t;
38+
#else
39+
typedef int intptr_t;
40+
#endif /* _WIN64 */
41+
#endif /* __intptr_t_defined */
42+
#endif /* _INTPTR_T_DEFINED */
43+
#ifndef _UINTPTR_T_DEFINED
44+
#define _UINTPTR_T_DEFINED
45+
#ifndef __uintptr_t_defined
46+
#define __uintptr_t_defined
47+
#undef uintptr_t
48+
#ifdef _WIN64
49+
typedef unsigned __int64 uintptr_t;
50+
#else
51+
typedef unsigned int uintptr_t;
52+
#endif /* _WIN64 */
53+
#endif /* __uintptr_t_defined */
54+
#endif /* _UINTPTR_T_DEFINED */
55+
#ifndef _PTRDIFF_T_DEFINED
56+
#define _PTRDIFF_T_DEFINED
57+
#ifndef _PTRDIFF_T_
58+
#define _PTRDIFF_T_
59+
#undef ptrdiff_t
60+
#ifdef _WIN64
61+
typedef __int64 ptrdiff_t;
62+
#else
63+
typedef int ptrdiff_t;
64+
#endif /* _WIN64 */
65+
#endif /* _PTRDIFF_T_ */
66+
#endif /* _PTRDIFF_T_DEFINED */
67+
#ifndef _WCHAR_T_DEFINED
68+
#define _WCHAR_T_DEFINED
69+
#ifndef __cplusplus
70+
typedef unsigned short wchar_t;
71+
#endif /* C++ */
72+
#endif /* _WCHAR_T_DEFINED */
73+
#ifndef _WCTYPE_T_DEFINED
74+
#define _WCTYPE_T_DEFINED
75+
#ifndef _WINT_T
76+
#define _WINT_T
77+
typedef unsigned short wint_t;
78+
typedef unsigned short wctype_t;
79+
#endif /* _WINT_T */
80+
#endif /* _WCTYPE_T_DEFINED */
81+
/* 7.18.1.1 Exact-width integer types */
82+
typedef __int8 int8_t;
83+
typedef unsigned __int8 uint8_t;
84+
typedef __int16 int16_t;
85+
typedef unsigned __int16 uint16_t;
86+
typedef __int32 int32_t;
87+
typedef unsigned __int32 uint32_t;
88+
typedef __int64 int64_t;
89+
typedef unsigned __int64 uint64_t;
90+
/* 7.18.1.2 Minimum-width integer types */
91+
typedef signed char int_least8_t;
92+
typedef unsigned char uint_least8_t;
93+
typedef short int_least16_t;
94+
typedef unsigned short uint_least16_t;
95+
typedef int int_least32_t;
96+
typedef unsigned uint_least32_t;
97+
typedef __int64 int_least64_t;
98+
typedef unsigned __int64 uint_least64_t;
99+
/* 7.18.1.3 Fastest minimum-width integer types
100+
* Not actually guaranteed to be fastest for all purposes
101+
* Here we use the exact-width types for 8 and 16-bit ints.
102+
*/
103+
typedef __int8 int_fast8_t;
104+
typedef unsigned __int8 uint_fast8_t;
105+
typedef __int16 int_fast16_t;
106+
typedef unsigned __int16 uint_fast16_t;
107+
typedef __int32 int_fast32_t;
108+
typedef unsigned __int32 uint_fast32_t;
109+
typedef __int64 int_fast64_t;
110+
typedef unsigned __int64 uint_fast64_t;
111+
/* 7.18.1.5 Greatest-width integer types */
112+
typedef __int64 intmax_t;
113+
typedef unsigned __int64 uintmax_t;
114+
/* 7.18.2 Limits of specified-width integer types */
115+
/* 7.18.2.1 Limits of exact-width integer types */
116+
#define INT8_MIN (-128)
117+
#define INT16_MIN (-32768)
118+
#define INT32_MIN (-2147483647 - 1)
119+
#define INT64_MIN (-9223372036854775807LL - 1)
120+
#define INT8_MAX 127
121+
#define INT16_MAX 32767
122+
#define INT32_MAX 2147483647
123+
#define INT64_MAX 9223372036854775807LL
124+
#define UINT8_MAX 255
125+
#define UINT16_MAX 65535
126+
#define UINT32_MAX 0xffffffffU /* 4294967295U */
127+
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
128+
/* 7.18.2.2 Limits of minimum-width integer types */
129+
#define INT_LEAST8_MIN INT8_MIN
130+
#define INT_LEAST16_MIN INT16_MIN
131+
#define INT_LEAST32_MIN INT32_MIN
132+
#define INT_LEAST64_MIN INT64_MIN
133+
#define INT_LEAST8_MAX INT8_MAX
134+
#define INT_LEAST16_MAX INT16_MAX
135+
#define INT_LEAST32_MAX INT32_MAX
136+
#define INT_LEAST64_MAX INT64_MAX
137+
#define UINT_LEAST8_MAX UINT8_MAX
138+
#define UINT_LEAST16_MAX UINT16_MAX
139+
#define UINT_LEAST32_MAX UINT32_MAX
140+
#define UINT_LEAST64_MAX UINT64_MAX
141+
/* 7.18.2.3 Limits of fastest minimum-width integer types */
142+
#define INT_FAST8_MIN INT8_MIN
143+
#define INT_FAST16_MIN INT16_MIN
144+
#define INT_FAST32_MIN INT32_MIN
145+
#define INT_FAST64_MIN INT64_MIN
146+
#define INT_FAST8_MAX INT8_MAX
147+
#define INT_FAST16_MAX INT16_MAX
148+
#define INT_FAST32_MAX INT32_MAX
149+
#define INT_FAST64_MAX INT64_MAX
150+
#define UINT_FAST8_MAX UINT8_MAX
151+
#define UINT_FAST16_MAX UINT16_MAX
152+
#define UINT_FAST32_MAX UINT32_MAX
153+
#define UINT_FAST64_MAX UINT64_MAX
154+
/* 7.18.2.4 Limits of integer types capable of holding
155+
object pointers */
156+
#ifdef _WIN64
157+
#define INTPTR_MIN INT64_MIN
158+
#define INTPTR_MAX INT64_MAX
159+
#define UINTPTR_MAX UINT64_MAX
160+
#else
161+
#define INTPTR_MIN INT32_MIN
162+
#define INTPTR_MAX INT32_MAX
163+
#define UINTPTR_MAX UINT32_MAX
164+
#endif
165+
/* 7.18.2.5 Limits of greatest-width integer types */
166+
#define INTMAX_MIN INT64_MIN
167+
#define INTMAX_MAX INT64_MAX
168+
#define UINTMAX_MAX UINT64_MAX
169+
/* 7.18.3 Limits of other integer types */
170+
#ifdef _WIN64
171+
#define PTRDIFF_MIN INT64_MIN
172+
#define PTRDIFF_MAX INT64_MAX
173+
#else
174+
#define PTRDIFF_MIN INT32_MIN
175+
#define PTRDIFF_MAX INT32_MAX
176+
#endif
177+
#define SIG_ATOMIC_MIN INT32_MIN
178+
#define SIG_ATOMIC_MAX INT32_MAX
179+
#ifndef SIZE_MAX
180+
#ifdef _WIN64
181+
#define SIZE_MAX UINT64_MAX
182+
#else
183+
#define SIZE_MAX UINT32_MAX
184+
#endif
185+
#endif
186+
#ifndef WCHAR_MIN /* also in wchar.h */
187+
#define WCHAR_MIN 0U
188+
#define WCHAR_MAX 0xffffU
189+
#endif
190+
/*
191+
* wint_t is unsigned short for compatibility with MS runtime
192+
*/
193+
#define WINT_MIN 0U
194+
#define WINT_MAX 0xffffU
195+
/* 7.18.4 Macros for integer constants */
196+
/* 7.18.4.1 Macros for minimum-width integer constants
197+
Accoding to Douglas Gwyn <[email protected]>:
198+
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
199+
9899:1999 as initially published, the expansion was required
200+
to be an integer constant of precisely matching type, which
201+
is impossible to accomplish for the shorter types on most
202+
platforms, because C99 provides no standard way to designate
203+
an integer constant with width less than that of type int.
204+
TC1 changed this to require just an integer constant
205+
*expression* with *promoted* type."
206+
The trick used here is from Clive D W Feather.
207+
*/
208+
#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
209+
#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
210+
#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
211+
/* The 'trick' doesn't work in C89 for long long because, without
212+
suffix, (val) will be evaluated as int, not intmax_t */
213+
#define INT64_C(val) val##i64
214+
#define UINT8_C(val) (val)
215+
#define UINT16_C(val) (val)
216+
#define UINT32_C(val) (val##i32)
217+
#define UINT64_C(val) val##ui64
218+
/* 7.18.4.2 Macros for greatest-width integer constants */
219+
#define INTMAX_C(val) val##i64
220+
#define UINTMAX_C(val) val##ui64
221+
#endif
222+
223+
/* This part is a standing for stdbool.h, which MSVC versions < 1600 also seem to lack */
224+
#ifndef _STDBOOL_H
225+
#define _STDBOOL_H
226+
#ifndef __cplusplus
227+
typedef char _Bool;
228+
#endif
229+
#define bool _Bool
230+
#define false 0
231+
#define true 1
232+
233+
#define __bool_true_false_are_defined 1
234+
#endif /* _STDBOOL_H */

0 commit comments

Comments
 (0)