From 03d628de73b2aa24c2795d432cea27808592f7bc Mon Sep 17 00:00:00 2001 From: John Stark Date: Tue, 26 Mar 2013 10:23:42 -0400 Subject: [PATCH 1/2] Fix MSVC compilation issue when PythonQt Debug build against python Release Copied most of the contents of `vtkPython.h` (cherry picked from commit commontk/PythonQt@8a50eaa62c3f2bf3afecf12566a484200169f31b) Co-authored-by: Jean-Christophe Fillion-Robin --- src/PythonQtPythonInclude.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index dcf281406..a99204ad6 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -56,11 +56,42 @@ # include # endif +// +// Use the real python debugging library if it is provided. +// Otherwise use the "documented" trick involving checking for _DEBUG +// and undefined that symbol while we include Python headers. +// Update: this method does not fool Microsoft Visual C++ 8 anymore; two +// of its header files (crtdefs.h and use_ansi.h) check if _DEBUG was set +// or not, and set flags accordingly (_CRT_MANIFEST_RETAIL, +// _CRT_MANIFEST_DEBUG, _CRT_MANIFEST_INCONSISTENT). The next time the +// check is performed in the same compilation unit, and the flags are found, +// and error is triggered. Let's prevent that by setting _CRT_NOFORCE_MANIFEST. +// + // If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link // release Python DLL if it is available by undefining _DEBUG while // including Python.h #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG) #undef _DEBUG +// Include these low level headers before undefing _DEBUG. Otherwise when doing +// a debug build against a release build of python the compiler will end up +// including these low level headers without DEBUG enabled, causing it to try +// and link release versions of this low level C api. +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include #if defined(_MSC_VER) && _MSC_VER >= 1400 #define _CRT_NOFORCE_MANIFEST 1 #define _STL_NOFORCE_MANIFEST 1 From 7957c6ebfce6911867c0b299e46df0a9ab6632bd Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 28 May 2013 00:32:03 -0400 Subject: [PATCH 2/2] Fix "_invalid_parameter_noinfo_noreturn" link error By ensuring that "undef" of _DEBUG macro is not done before system includes, it fixes the issue. Based on a similar fix in VTK. See: https://github.com/Kitware/VTK/commit/81d4a72c1195437403f1772559c9c28978818f03 See: commontk/PythonQt#9 Thanks to @Neosettler for reporting and testing. Reported-by: Neosettler (cherry picked from commit commontk/PythonQt@77d81777a59c2eebe17894e2d2c94af0de5b7899) --- src/PythonQtPythonInclude.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index a99204ad6..673db874f 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -72,7 +72,7 @@ // release Python DLL if it is available by undefining _DEBUG while // including Python.h #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG) -#undef _DEBUG +# define PYTHONQT_UNDEF_DEBUG // Include these low level headers before undefing _DEBUG. Otherwise when doing // a debug build against a release build of python the compiler will end up // including these low level headers without DEBUG enabled, causing it to try @@ -92,14 +92,17 @@ # include # include # include -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define _CRT_NOFORCE_MANIFEST 1 -#define _STL_NOFORCE_MANIFEST 1 +# undef _DEBUG +# if defined(_MSC_VER) && _MSC_VER >= 1400 +# define _CRT_NOFORCE_MANIFEST 1 +# define _STL_NOFORCE_MANIFEST 1 +# endif #endif + #include -#define _DEBUG -#else -#include + +#ifdef PYTHONQT_UNDEF_DEBUG +# define _DEBUG #endif // By including Python.h on Linux truncate could have been defined (in unistd.h)