From 5e846d84ab0b493719bfd7b61cc827347f20e806 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sun, 7 Dec 2025 17:42:26 +0500 Subject: [PATCH 1/2] PC/pyconfig.h: improve implicit linking code readibility --- PC/pyconfig.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 2381ed3772b109e..7ea2e869fda2517 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -317,17 +317,13 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* All windows compilers that use this header support __declspec */ #define HAVE_DECLSPEC_DLL -/* For an MSVC DLL, we can nominate the .lib files used by extensions */ -#ifdef MS_COREDLL +/* Automatic linking of extension python3x.lib files for MSVC DLLs. + This lets MSVC users build extensions without manually specifying .lib files. + Define Py_NO_LINK_LIB to disable this behavior. */ +#if !defined(Py_NO_LINK_LIB) # if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) /* not building the core - must be an ext */ -# if defined(_MSC_VER) && !defined(Py_NO_LINK_LIB) - /* So MSVC users need not specify the .lib - file in their Makefile */ - /* Define Py_NO_LINK_LIB to build extension disabling pragma - based auto-linking. - This is relevant when using build-system generator (e.g CMake) where - the linking is explicitly handled */ +# if defined(MS_COREDLL) && defined(_MSC_VER) # if defined(Py_GIL_DISABLED) # if defined(Py_DEBUG) # pragma comment(lib,"python316t_d.lib") @@ -347,9 +343,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # pragma comment(lib,"python316.lib") # endif /* Py_DEBUG */ # endif /* Py_GIL_DISABLED */ -# endif /* _MSC_VER && !Py_NO_LINK_LIB */ +# endif /* MS_COREDLL && _MSC_VER */ # endif /* Py_BUILD_CORE */ -#endif /* MS_COREDLL */ +#endif /* Py_NO_LINK_LIB */ #ifdef MS_WIN64 /* maintain "win32" sys.platform for backward compatibility of Python code, From f615ef25c4f0e4421b9332f2f2a56f5fc2299305 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 18 Aug 2026 18:22:33 +0500 Subject: [PATCH 2/2] Move all conditions to the top, fix indentation, use `Py_ENABLE_SHARED` --- PC/pyconfig.h | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 7ea2e869fda2517..22c3ccc05bb004e 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -320,32 +320,30 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Automatic linking of extension python3x.lib files for MSVC DLLs. This lets MSVC users build extensions without manually specifying .lib files. Define Py_NO_LINK_LIB to disable this behavior. */ -#if !defined(Py_NO_LINK_LIB) -# if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) - /* not building the core - must be an ext */ -# if defined(MS_COREDLL) && defined(_MSC_VER) -# if defined(Py_GIL_DISABLED) -# if defined(Py_DEBUG) -# pragma comment(lib,"python316t_d.lib") -# elif defined(Py_LIMITED_API) || defined(Py_TARGET_ABI3T) -# pragma comment(lib,"python3t.lib") -# else -# pragma comment(lib,"python316t.lib") -# endif /* Py_DEBUG */ -# else /* Py_GIL_DISABLED */ -# if defined(Py_DEBUG) -# pragma comment(lib,"python316_d.lib") -# elif defined(Py_TARGET_ABI3T) -# pragma comment(lib,"python3t.lib") -# elif defined(Py_LIMITED_API) -# pragma comment(lib,"python3.lib") -# else -# pragma comment(lib,"python316.lib") -# endif /* Py_DEBUG */ -# endif /* Py_GIL_DISABLED */ -# endif /* MS_COREDLL && _MSC_VER */ -# endif /* Py_BUILD_CORE */ -#endif /* Py_NO_LINK_LIB */ +#if !defined(Py_NO_LINK_LIB) \ + && defined(_MSC_VER) && defined(Py_ENABLE_SHARED) \ + && !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) + /* not building the core - must be an ext */ +# if defined(Py_GIL_DISABLED) +# if defined(Py_DEBUG) +# pragma comment(lib,"python316t_d.lib") +# elif defined(Py_LIMITED_API) || defined(Py_TARGET_ABI3T) +# pragma comment(lib,"python3t.lib") +# else +# pragma comment(lib,"python316t.lib") +# endif /* Py_DEBUG */ +# else +# if defined(Py_DEBUG) +# pragma comment(lib,"python316_d.lib") +# elif defined(Py_TARGET_ABI3T) +# pragma comment(lib,"python3t.lib") +# elif defined(Py_LIMITED_API) +# pragma comment(lib,"python3.lib") +# else +# pragma comment(lib,"python316.lib") +# endif /* Py_DEBUG */ +# endif /* Py_GIL_DISABLED */ +#endif #ifdef MS_WIN64 /* maintain "win32" sys.platform for backward compatibility of Python code,