]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131942: Use the Python-specific `Py_DEBUG` macro rather than `_DEBUG` in Windows...
authorXuehai Pan <XuehaiPan@pku.edu.cn>
Thu, 8 May 2025 15:01:25 +0000 (23:01 +0800)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 15:01:25 +0000 (15:01 +0000)
13 files changed:
Doc/c-api/intro.rst
Include/internal/pycore_importdl.h
Misc/NEWS.d/next/Windows/2025-03-31-15-37-57.gh-issue-131942.jip_aL.rst [new file with mode: 0644]
Modules/_ctypes/callproc.c
Modules/_ssl.c
Modules/_ssl/debughelpers.c
PC/launcher.c
PC/pyconfig.h.in
PC/python_uwp.cpp
PC/python_ver_rc.h
Python/dynload_win.c
Python/marshal.c
Python/pylifecycle.c

index c8c60eb9f48f45ae02764053db78d9d0162e9cde..2bad0bab224e516fa8cf0a6df6831c72ba625e00 100644 (file)
@@ -826,14 +826,17 @@ frequently used builds will be described in the remainder of this section.
 
 Compiling the interpreter with the :c:macro:`!Py_DEBUG` macro defined produces
 what is generally meant by :ref:`a debug build of Python <debug-build>`.
-:c:macro:`!Py_DEBUG` is enabled in the Unix build by adding
-:option:`--with-pydebug` to the :file:`./configure` command.
-It is also implied by the presence of the
-not-Python-specific :c:macro:`!_DEBUG` macro.  When :c:macro:`!Py_DEBUG` is enabled
-in the Unix build, compiler optimization is disabled.
+
+On Unix, :c:macro:`!Py_DEBUG` can be enabled by adding :option:`--with-pydebug`
+to the :file:`./configure` command. This will also disable compiler optimization.
+
+On Windows, selecting a debug build (e.g., by passing the :option:`-d` option to
+:file:`PCbuild/build.bat`) automatically enables :c:macro:`!Py_DEBUG`.
+Additionally, the presence of the not-Python-specific :c:macro:`!_DEBUG` macro,
+when defined by the compiler, will also implicitly enable :c:macro:`!Py_DEBUG`.
 
 In addition to the reference count debugging described below, extra checks are
-performed, see :ref:`Python Debug Build <debug-build>`.
+performed. See :ref:`Python Debug Build <debug-build>` for more details.
 
 Defining :c:macro:`Py_TRACE_REFS` enables reference tracing
 (see the :option:`configure --with-trace-refs option <--with-trace-refs>`).
index 525a16f6b97274668ac9b4f8b4fd90502c8f10dd..3ba9229cc21378700b861aa8a0e0a60501f0ee6c 100644 (file)
@@ -107,7 +107,7 @@ extern int _PyImport_RunModInitFunc(
 #include <windows.h>
 typedef FARPROC dl_funcptr;
 
-#ifdef _DEBUG
+#ifdef Py_DEBUG
 #  define PYD_DEBUG_SUFFIX "_d"
 #else
 #  define PYD_DEBUG_SUFFIX ""
diff --git a/Misc/NEWS.d/next/Windows/2025-03-31-15-37-57.gh-issue-131942.jip_aL.rst b/Misc/NEWS.d/next/Windows/2025-03-31-15-37-57.gh-issue-131942.jip_aL.rst
new file mode 100644 (file)
index 0000000..837f726
--- /dev/null
@@ -0,0 +1 @@
+Use the Python-specific :c:macro:`Py_DEBUG` macro rather than :c:macro:`!_DEBUG` in Windows-related C code. Patch by Xuehai Pan.
index 856b0376e5eaa00e8f9fdfb1787ccd95f4fb79d9..404178ca623a93882b005b83a9799d33a0f55df0 100644 (file)
@@ -92,7 +92,7 @@ module _ctypes
 #include <sanitizer/msan_interface.h>
 #endif
 
-#if defined(_DEBUG) || defined(__MINGW32__)
+#if defined(Py_DEBUG) || defined(__MINGW32__)
 /* Don't use structured exception handling on Windows if this is defined.
    MingW, AFAIK, doesn't support it.
 */
index 97a29f4d0e1830aae19104538543f9e743d3334c..1b26f503e738272da3d47d3cc0eae9cfa31613eb 100644 (file)
@@ -4427,7 +4427,7 @@ _ssl__SSLContext_load_dh_params_impl(PySSLContext *self, PyObject *filepath)
     FILE *f;
     DH *dh;
 
-#if defined(MS_WINDOWS) && defined(_DEBUG)
+#if defined(MS_WINDOWS) && defined(Py_DEBUG)
     PyErr_SetString(PyExc_NotImplementedError,
                     "load_dh_params: unavailable on Windows debug build");
     return NULL;
index 7c0b4876f4353ad1a66a57e733023607bf0a7a3e..f0a0a1674f32bd766052469e799312b9c6d2b91f 100644 (file)
@@ -175,7 +175,7 @@ _PySSLContext_set_keylog_filename(PyObject *op, PyObject *arg,
     PySSLContext *self = PySSLContext_CAST(op);
     FILE *fp;
 
-#if defined(MS_WINDOWS) && defined(_DEBUG)
+#if defined(MS_WINDOWS) && defined(Py_DEBUG)
     PyErr_SetString(PyExc_NotImplementedError,
                     "set_keylog_filename: unavailable on Windows debug build");
     return -1;
index 5c63d872bd4dfce781c7157360beb3fcd434f877..fed5e156b92cb3e2fc557dffd9a073c52eb79fb7 100644 (file)
@@ -140,7 +140,7 @@ static wchar_t * get_env(wchar_t * key)
     return buf;
 }
 
-#if defined(_DEBUG)
+#if defined(Py_DEBUG)
 /* Do not define EXECUTABLEPATH_VALUE in debug builds as it'll
    never point to the debug build. */
 #if defined(_WINDOWS)
index bbafaed808eecd220a9ca5b5e7a5fa0ba2fcd292..1d659e7cee682b7957a3ca677f7ac13504f5cafe 100644 (file)
@@ -94,6 +94,11 @@ WIN32 is still required for the locale module.
 #endif
 #endif /* Py_BUILD_CORE || Py_BUILD_CORE_BUILTIN || Py_BUILD_CORE_MODULE */
 
+/* _DEBUG implies Py_DEBUG */
+#ifdef _DEBUG
+#  define Py_DEBUG 1
+#endif
+
 /* Define to 1 if you want to disable the GIL */
 /* Uncomment the definition for free-threaded builds, or define it manually
  * when compiling extension modules. Note that we test with #ifdef, so
@@ -319,21 +324,21 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
                         This is relevant when using build-system generator (e.g CMake) where
                         the linking is explicitly handled */
 #                       if defined(Py_GIL_DISABLED)
-#                       if defined(_DEBUG)
+#                       if defined(Py_DEBUG)
 #                               pragma comment(lib,"python315t_d.lib")
 #                       elif defined(Py_LIMITED_API)
 #                               pragma comment(lib,"python3t.lib")
 #                       else
 #                               pragma comment(lib,"python315t.lib")
-#                       endif /* _DEBUG */
+#                       endif /* Py_DEBUG */
 #                       else /* Py_GIL_DISABLED */
-#                       if defined(_DEBUG)
+#                       if defined(Py_DEBUG)
 #                               pragma comment(lib,"python315_d.lib")
 #                       elif defined(Py_LIMITED_API)
 #                               pragma comment(lib,"python3.lib")
 #                       else
 #                               pragma comment(lib,"python315.lib")
-#                       endif /* _DEBUG */
+#                       endif /* Py_DEBUG */
 #                       endif /* Py_GIL_DISABLED */
 #               endif /* _MSC_VER && !Py_NO_LINK_LIB */
 #       endif /* Py_BUILD_CORE */
@@ -376,11 +381,6 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
 #       define ALIGNOF_MAX_ALIGN_T 8
 #endif
 
-#ifdef _DEBUG
-#       define Py_DEBUG
-#endif
-
-
 #ifdef MS_WIN32
 
 #define SIZEOF_SHORT 2
index b9c408a580c99920613f47d805f696073d2fd9e3..8cdb8d722cdb9a09c3ed76159bad37d2b5f54f07 100644 (file)
 #include <winrt\Windows.Storage.h>
 
 #ifdef PYTHONW
-#ifdef _DEBUG
+#ifdef Py_DEBUG
 const wchar_t *PROGNAME = L"pythonw_d.exe";
 #else
 const wchar_t *PROGNAME = L"pythonw.exe";
 #endif
 #else
-#ifdef _DEBUG
+#ifdef Py_DEBUG
 const wchar_t *PROGNAME = L"python_d.exe";
 #else
 const wchar_t *PROGNAME = L"python.exe";
index ee867fe41224c375c5e27c1b37c53518ab68b1c6..bb98144cd03f15d988e54659be01a637a4ad0ecd 100644 (file)
@@ -10,7 +10,7 @@
 #define MS_WINDOWS
 #include "modsupport.h"
 #include "patchlevel.h"
-#ifdef _DEBUG
+#ifdef Py_DEBUG
 #   define PYTHON_DEBUG_EXT "_d"
 #else
 #   define PYTHON_DEBUG_EXT
index 6324063401e51f3b8abf8e08f5f44ece81e7117a..de9b0a77817a63322e2918697119cb81a6554be5 100644 (file)
@@ -108,7 +108,7 @@ static char *GetPythonImport (HINSTANCE hModule)
                 char *pch;
 
                 /* Don't claim that python3.dll is a Python DLL. */
-#ifdef _DEBUG
+#ifdef Py_DEBUG
                 if (strcmp(import_name, "python3_d.dll") == 0) {
 #else
                 if (strcmp(import_name, "python3.dll") == 0) {
@@ -120,7 +120,7 @@ static char *GetPythonImport (HINSTANCE hModule)
                 /* Ensure python prefix is followed only
                    by numbers to the end of the basename */
                 pch = import_name + 6;
-#ifdef _DEBUG
+#ifdef Py_DEBUG
                 while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') {
 #else
                 while (*pch && *pch != '.') {
@@ -300,7 +300,7 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
             char buffer[256];
 
             PyOS_snprintf(buffer, sizeof(buffer),
-#ifdef _DEBUG
+#ifdef Py_DEBUG
                           "python%d%d_d.dll",
 #else
                           "python%d%d.dll",
index b39c1a5b1ade50e33673eaac0a7f5801fb880b33..afbef6ee6796d9ac5c060cfd8d4f9dc4765957dd 100644 (file)
@@ -38,7 +38,7 @@ module marshal
  * On Windows PGO builds, the r_object function overallocates its stack and
  * can cause a stack overflow. We reduce the maximum depth for all Windows
  * releases to protect against this.
- * #if defined(MS_WINDOWS) && defined(_DEBUG)
+ * #if defined(MS_WINDOWS) && defined(Py_DEBUG)
  */
 #if defined(MS_WINDOWS)
 #  define MAX_MARSHAL_STACK_DEPTH 1000
index c4c1d9fd9e13805d673be4f8a57c29b4bc965432..8394245d373030121371f10ae76dadc98e3b0317 100644 (file)
@@ -3144,7 +3144,7 @@ static inline void _Py_NO_RETURN
 fatal_error_exit(int status)
 {
     if (status < 0) {
-#if defined(MS_WINDOWS) && defined(_DEBUG)
+#if defined(MS_WINDOWS) && defined(Py_DEBUG)
         DebugBreak();
 #endif
         abort();