This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Py_DEBUG
Type: enhancement Stage:
Components: None Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: collinwinter, loewis, nitrogenycs
Priority: normal Keywords:

Created on 2006-12-09 15:48 by nitrogenycs, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg54945 - (view) Author: nitro (nitrogenycs) Date: 2006-12-09 15:48
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
msg54946 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-12-11 19:09
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.
msg54947 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-30 14:40
Closing per Martin's comment.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44321
2006-12-09 15:48:39nitrogenycscreate