Issue 1612190: Py_DEBUG - Python tracker (original) (raw)

Hello,

I am writing an extension module (Win32, VC8). Of course I need to #include <Python.h>. Now, when _DEBUG is defined in my application Py_DEBUG gets defined as well (in pyconfig.h). I don't want this to happen as I have to link to the python debug library that way. However, I don't want to debug python, I only want to debug my own application. So the automatic definition of Py_DEBUG doesn't seem right. A solution that would be backwards compatible could look like:

#ifdef _DEBUG && !defined(Py_NO_DEBUG) # define Py_DEBUG #endif

Could something like this be included in python? Note that #undef _DEBUG #include <Python.h> #define _DEBUG does not work as VC8 complains in this case, because some header files had the _DEBUG preprocessor symbol and some didn't. That trick used to work in VC 6 and 7.x. I've seen a lot of people fighting this problem.

Another problem that also arises from pyconfig.h is this code:

ifdef _DEBUG

pragma comment(lib,"python24_d.lib")

else

I don't think it's clean that python tells my program what to link to. I am the one who should (and wants to) do this via a linker switch. I know that some people probably would regard the code above as a feature, but it's the opposite imo. A backwards compatible change could look like:

#ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext / # if defined(_MSC_VER) && !defined(Py_NO_AUTOMATIC_MSVC_LINK) / So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) / # ifdef _DEBUG # pragma comment(lib,"python24_d.lib") # else # pragma comment(lib,"python24.lib") # endif / _DEBUG / # endif / _MSC_VER / # endif / Py_BUILD_CORE / #endif / MS_COREDLL */

Thanks,

-Matthias

You should just not define _DEBUG then. You don't need to define _DEBUG to perform debugging; instead, _DEBUG requests that the debug version of the MS CRT is linked to your application.

As mixing different CRTs (e.g. debug and non-debug) in a single application can cause crashes, you must use a python2x.dll that is linked with the debug CRT; this will be python2x_d.dll. So no, something like this should not be added to Python.