Skip to content

Commit 672a4f7

Browse files
committed
fix clang compiler version in _Py_COMPILER
1 parent 7bfa97f commit 672a4f7

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix truncated :data:`sys.version` in case of clang-cl versions greater or
2+
equal 22 on Windows. Also fixes the Windows on Arm case, where the Microsoft
3+
compiler was reported instead of clang. Patch by Chris Eibl.

PC/pyconfig.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,24 @@ WIN32 is still required for the locale module.
148148
#define MS_WIN64
149149
#endif
150150

151+
#ifdef __clang__
152+
#define _Py_CLANG_COMPILER(platform) ( \
153+
"[Clang " _Py_STRINGIZE(__clang_major__)"." _Py_STRINGIZE(__clang_minor__ ) \
154+
"." _Py_STRINGIZE(__clang_patchlevel__) " " platform \
155+
" with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
156+
#endif
157+
151158
/* set the _Py_COMPILER and support tier
152159
*
153160
* win_amd64 MSVC (x86_64-pc-windows-msvc): 1
154161
* win32 MSVC (i686-pc-windows-msvc): 1
155162
* win_arm64 MSVC (aarch64-pc-windows-msvc): 2
156-
* other archs and ICC: 0
163+
* other archs and clang-cl/ICC: 0
157164
*/
158165
#ifdef MS_WIN64
159166
#if defined(_M_X64) || defined(_M_AMD64)
160167
#if defined(__clang__)
161-
#define _Py_COMPILER ("[Clang " __clang_version__ "] 64 bit (AMD64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
168+
#define _Py_COMPILER _Py_CLANG_COMPILER("64 bit (AMD64)")
162169
#define PY_SUPPORT_TIER 0
163170
#elif defined(__INTEL_COMPILER)
164171
#define _Py_COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 64 bit (amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
@@ -169,8 +176,13 @@ WIN32 is still required for the locale module.
169176
#endif /* __clang__ */
170177
#define PYD_PLATFORM_TAG "win_amd64"
171178
#elif defined(_M_ARM64)
179+
#if defined(__clang__)
180+
#define _Py_COMPILER _Py_CLANG_COMPILER("64 bit (ARM64)")
181+
#define PY_SUPPORT_TIER 0
182+
#else
172183
#define _Py_COMPILER _Py_PASTE_VERSION("64 bit (ARM64)")
173184
#define PY_SUPPORT_TIER 2
185+
#endif /* __clang__ */
174186
#define PYD_PLATFORM_TAG "win_arm64"
175187
#else
176188
#define _Py_COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
@@ -220,7 +232,7 @@ typedef _W64 int Py_ssize_t;
220232
#if defined(MS_WIN32) && !defined(MS_WIN64)
221233
#if defined(_M_IX86)
222234
#if defined(__clang__)
223-
#define _Py_COMPILER ("[Clang " __clang_version__ "] 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
235+
#define _Py_COMPILER _Py_CLANG_COMPILER("32 bit (Intel)")
224236
#define PY_SUPPORT_TIER 0
225237
#elif defined(__INTEL_COMPILER)
226238
#define _Py_COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")

0 commit comments

Comments
 (0)