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 // If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
60 // release Python DLL if it is available by undefining _DEBUG while
61 // including Python.h
62 #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG)
63 #undef _DEBUG
64 #if defined(_MSC_VER) && _MSC_VER >= 1400
65 #define _CRT_NOFORCE_MANIFEST 1
66 #define _STL_NOFORCE_MANIFEST 1
67 #endif
68 #include <Python.h>
69 #define _DEBUG
70 #else
71 #include <Python.h>
72 #endif
73 
74 // By including Python.h on Linux truncate could have been defined (in unistd.h)
75 // which would lead to compiler errors. Therefore:
76 #ifdef truncate
77 # undef truncate
78 #endif
79 
80 // get Qt keywords back
81 #ifdef PYTHONQT_RESTORE_KEYWORDS
82 #define slots Q_SLOTS
83 #undef PYTHONQT_RESTORE_KEYWORDS
84 #endif
85 
86 #if PY_MAJOR_VERSION >= 3
87 #define PY3K
88 // Helper defines to facilitate porting
89 #define PyString_FromString PyUnicode_FromString
90 #define PyString_AS_STRING PyUnicode_AsUTF8
91 #define PyString_AsString PyUnicode_AsUTF8
92 #define PyString_FromFormat PyUnicode_FromFormat
93 #define PyString_Check PyUnicode_Check
94 
95 #define PyInt_Type PyLong_Type
96 #define PyInt_FromLong PyLong_FromLong
97 #define PyInt_AS_LONG PyLong_AS_LONG
98 #define PyInt_Check PyLong_Check
99 #define PyInt_AsLong PyLong_AsLong
100 
101 #else
102 // Defines to use Python 3 names in Python 2 code
103 #define PyBytes_Type PyString_Type
104 #define PyBytes_Check PyString_Check
105 #define PyBytes_AS_STRING PyString_AS_STRING
106 #define PyBytes_AsString PyString_AsString
107 #define PyBytes_GET_SIZE PyString_GET_SIZE
108 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
109 #endif
110 
111 #endif