Skip to content

Commit fe7e8bf

Browse files
committed
Patches to build on clang-cl
This was mostly: - forward declare struct timeval in pytime (it should have been anyway) - moving struct packing in the correct place - Using a more portable, standard garunteed stringize macro - defining compiler names
1 parent 71ede00 commit fe7e8bf

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

Include/pytime.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ functions and constants
1313
extern "C" {
1414
#endif
1515

16+
#if defined(_MSC_VER)
17+
/* Forward declare struct timeval so that clang-cl doesn't complain about it
18+
being a local declaration later on in _PyTime_AsTimeval.*/
19+
struct timeval;
20+
#endif /* _MSC_VER */
21+
1622
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
1723
store a duration, and so indirectly a date (related to another date, like
1824
UNIX epoch). */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Port CPython to build with clang-cl on Windows.
2+
3+
Patch by Ethan Smith

Modules/_tracemalloc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ static PyThread_type_lock tables_lock;
6767

6868
#define DEFAULT_DOMAIN 0
6969

70-
/* Pack the frame_t structure to reduce the memory footprint. */
70+
/* Pack the pointer_t structure to reduce the memory footprint. */
71+
#if defined(_MSC_VER)
72+
#pragma pack(push, 4)
73+
#endif
7174
typedef struct
7275
#ifdef __GNUC__
7376
__attribute__((packed))
@@ -76,14 +79,18 @@ __attribute__((packed))
7679
uintptr_t ptr;
7780
unsigned int domain;
7881
} pointer_t;
82+
#ifdef _MSC_VER
83+
#pragma pack(pop)
84+
#endif
7985

8086
/* Pack the frame_t structure to reduce the memory footprint on 64-bit
81-
architectures: 12 bytes instead of 16. */
87+
architectures: 12 bytes instead of 16. */
88+
#if defined(_MSC_VER)
89+
#pragma pack(push, 4)
90+
#endif
8291
typedef struct
8392
#ifdef __GNUC__
8493
__attribute__((packed))
85-
#elif defined(_MSC_VER)
86-
#pragma pack(push, 4)
8794
#endif
8895
{
8996
/* filename cannot be NULL: "<unknown>" is used if the Python frame

PC/pyconfig.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,9 @@ WIN32 is still required for the locale module.
9494
/* e.g., this produces, after compile-time string catenation,
9595
* ("[MSC v.1200 32 bit (Intel)]")
9696
*
97-
* _Py_STRINGIZE(_MSC_VER) expands to
98-
* _Py_STRINGIZE1((_MSC_VER)) expands to
99-
* _Py_STRINGIZE2(_MSC_VER) but as this call is the result of token-pasting
100-
* it's scanned again for macros and so further expands to (under MSVC 6)
101-
* _Py_STRINGIZE2(1200) which then expands to
102-
* "1200"
97+
* The double-stringize hack, a method to get the string version of _MSC_VER
10398
*/
104-
#define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
105-
#define _Py_STRINGIZE1(X) _Py_STRINGIZE2 ## X
99+
#define _Py_STRINGIZE(X) _Py_STRINGIZE2(X)
106100
#define _Py_STRINGIZE2(X) #X
107101

108102
/* MSVC defines _WINxx to differentiate the windows platform types
@@ -122,6 +116,8 @@ WIN32 is still required for the locale module.
122116
#if defined(_M_X64) || defined(_M_AMD64)
123117
#if defined(__INTEL_COMPILER)
124118
#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 64 bit (amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
119+
#elif defined(__clang__)
120+
#define COMPILER ("[clang v." _Py_STRINGIZE(__clang_version__) "64 bit (amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
125121
#else
126122
#define COMPILER _Py_PASTE_VERSION("64 bit (AMD64)")
127123
#endif /* __INTEL_COMPILER */
@@ -172,6 +168,8 @@ typedef _W64 int ssize_t;
172168
#if defined(_M_IX86)
173169
#if defined(__INTEL_COMPILER)
174170
#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
171+
#elif defined(__clang__)
172+
#define COMPILER ("[clang v." _Py_STRINGIZE(__clang_version__) "32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
175173
#else
176174
#define COMPILER _Py_PASTE_VERSION("32 bit (Intel)")
177175
#endif /* __INTEL_COMPILER */

0 commit comments

Comments
 (0)