PythonQt
PythonQtPythonInclude.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2011 MeVis Medical Solutions AG All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
28 *
29 * http://www.mevis.de
30 *
31 */
32
33#ifndef __PythonQtPythonInclude_h
34#define __PythonQtPythonInclude_h
35
36// Undefine macros that features.h defines to avoid redefinition warning
37#ifdef _POSIX_C_SOURCE
38# undef _POSIX_C_SOURCE
39#endif
40
41#ifdef _XOPEN_SOURCE
42# undef _XOPEN_SOURCE
43#endif
44
45// Undefine Qt keywords that conflict with Python headers
46#ifdef slots
47#undef slots
48#define PYTHONQT_RESTORE_KEYWORDS
49#endif
50
51//From https://github.com/boostorg/python/pull/253
52// Python.h defines a macro with hypot name, what breaks libstdc++ math header
53// that it tries to include afterwards.
54# if defined(__MINGW32__)
55# include <cmath>
56# include <math.h>
57# endif
58
59//
60// Use the real python debugging library if it is provided.
61// Otherwise use the "documented" trick involving checking for _DEBUG
62// and undefined that symbol while we include Python headers.
63// Update: this method does not fool Microsoft Visual C++ 8 anymore; two
64// of its header files (crtdefs.h and use_ansi.h) check if _DEBUG was set
65// or not, and set flags accordingly (_CRT_MANIFEST_RETAIL,
66// _CRT_MANIFEST_DEBUG, _CRT_MANIFEST_INCONSISTENT). The next time the
67// check is performed in the same compilation unit, and the flags are found,
68// and error is triggered. Let's prevent that by setting _CRT_NOFORCE_MANIFEST.
69//
70
71// If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
72// release Python DLL if it is available by undefining _DEBUG while
73// including Python.h
74#if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG)
75# define PYTHONQT_UNDEF_DEBUG
76// Include these low level headers before undefing _DEBUG. Otherwise when doing
77// a debug build against a release build of python the compiler will end up
78// including these low level headers without DEBUG enabled, causing it to try
79// and link release versions of this low level C api.
80# include <basetsd.h>
81# include <assert.h>
82# include <ctype.h>
83# include <errno.h>
84# include <io.h>
85# include <math.h>
86# include <sal.h>
87# include <stdarg.h>
88# include <stddef.h>
89# include <stdio.h>
90# include <stdlib.h>
91# include <string.h>
92# include <sys/stat.h>
93# include <time.h>
94# include <wchar.h>
95# undef _DEBUG
96# if defined(_MSC_VER) && _MSC_VER >= 1400
97# define _CRT_NOFORCE_MANIFEST 1
98# define _STL_NOFORCE_MANIFEST 1
99# endif
100#endif
101
102#include <Python.h>
103
104#ifdef PYTHONQT_UNDEF_DEBUG
105# define _DEBUG
106#endif
107
108// By including Python.h on Linux truncate could have been defined (in unistd.h)
109// which would lead to compiler errors. Therefore:
110#ifdef truncate
111# undef truncate
112#endif
113
114// get Qt keywords back
115#ifdef PYTHONQT_RESTORE_KEYWORDS
116#define slots Q_SLOTS
117#undef PYTHONQT_RESTORE_KEYWORDS
118#endif
119
120#if PY_MAJOR_VERSION < 3
121#error "PythonQt requires Python >= 3.x"
122#endif
123
124// Optional compatibility shim for legacy wrappers generated by older PythonQt.
125// Enable by defining PYTHONQT_USE_PYSTRING_SHIM (deprecated).
126#if defined(PYTHONQT_USE_PYSTRING_SHIM)
127#define PY3K
128#define PyString_FromString PyUnicode_FromString
129#endif
130
131// Avoid clashes with libstdc++ <locale> by undefining ctype macros
132// that CPython may introduce on macOS when the UTF-8 ctype quirk is enabled.
133// (_PY_PORT_CTYPE_UTF8_ISSUE is defined by CPython’s pyport.h; we apply these
134// undefs only in C++ builds.)
135#if defined(_PY_PORT_CTYPE_UTF8_ISSUE) && defined(__cplusplus)
136#undef isalnum
137#undef isalpha
138#undef islower
139#undef isspace
140#undef isupper
141#undef tolower
142#undef toupper
143#endif
144
145#endif
146