Skip to content

Use the Python-specific Py_DEBUG macro rather than _DEBUG in Windows-related C code #131942

@XuehaiPan

Description

@XuehaiPan

Follow the discussion at #131799 (comment).

Currently, the Windows-related C code is mixed using the Python-specific Py_DEBUG macro and non-Python-specific _DEBUG macro.

The documentation said _DEBUG implies Py_DEBUG.

Py_DEBUG

Compiling the interpreter with the Py_DEBUG macro defined produces what is generally meant by a debug build of Python. Py_DEBUG is enabled in the Unix build by adding --with-pydebug to the ./configure command. It is also implied by the presence of the not-Python-specific _DEBUG macro. When Py_DEBUG is enabled in the Unix build, compiler optimization is disabled.

And it is guaranteed by the following code on Windows.

cpython/PC/pyconfig.h.in

Lines 379 to 381 in 4940d96

#ifdef _DEBUG
# define Py_DEBUG
#endif

All platform-non-specific code and Unix-specific code is using the Python-specific Py_DEBUG macro. It would be nice to use Py_DEBUG in Windows-related C code either. It could improve the code readability and maintainability.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions