Skip to content

Commit 5fc189d

Browse files
emmatypingisuruf
authored andcommitted
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 3d06953 commit 5fc189d

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
@@ -48,7 +48,10 @@ static PyThread_type_lock tables_lock;
4848

4949
#define DEFAULT_DOMAIN 0
5050

51-
/* Pack the frame_t structure to reduce the memory footprint. */
51+
/* Pack the pointer_t structure to reduce the memory footprint. */
52+
#if defined(_MSC_VER)
53+
#pragma pack(push, 4)
54+
#endif
5255
typedef struct
5356
#ifdef __GNUC__
5457
__attribute__((packed))
@@ -57,14 +60,18 @@ __attribute__((packed))
5760
uintptr_t ptr;
5861
unsigned int domain;
5962
} pointer_t;
63+
#ifdef _MSC_VER
64+
#pragma pack(pop)
65+
#endif
6066

6167
/* Pack the frame_t structure to reduce the memory footprint on 64-bit
62-
architectures: 12 bytes instead of 16. */
68+
architectures: 12 bytes instead of 16. */
69+
#if defined(_MSC_VER)
70+
#pragma pack(push, 4)
71+
#endif
6372
typedef struct
6473
#ifdef __GNUC__
6574
__attribute__((packed))
66-
#elif defined(_MSC_VER)
67-
#pragma pack(push, 4)
6875
#endif
6976
{
7077
/* 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 */
@@ -175,6 +171,8 @@ typedef _W64 int ssize_t;
175171
#if defined(_M_IX86)
176172
#if defined(__INTEL_COMPILER)
177173
#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
174+
#elif defined(__clang__)
175+
#define COMPILER ("[clang v." _Py_STRINGIZE(__clang_version__) "32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
178176
#else
179177
#define COMPILER _Py_PASTE_VERSION("32 bit (Intel)")
180178
#endif /* __INTEL_COMPILER */

0 commit comments

Comments
 (0)