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 Python.h defines to avoid redefinition warning.
37 #undef _POSIX_C_SOURCE
38 #undef _POSIX_THREADS
39 #undef _XOPEN_SOURCE
40 
41 // Undefine Qt keywords that conflict with Python headers
42 #ifdef slots
43 #undef slots
44 #define PYTHONQT_RESTORE_KEYWORDS
45 #endif
46 
47 // If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
48 // release Python DLL if it is available by undefining _DEBUG while
49 // including Python.h
50 #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG)
51 #undef _DEBUG
52 #if defined(_MSC_VER) && _MSC_VER >= 1400
53 #define _CRT_NOFORCE_MANIFEST 1
54 #define _STL_NOFORCE_MANIFEST 1
55 #endif
56 #include <Python.h>
57 #define _DEBUG
58 #else
59 #include <Python.h>
60 #endif
61 
62 // By including Python.h on Linux truncate could have been defined (in unistd.h)
63 // which would lead to compiler errors. Therefore:
64 #ifdef truncate
65 # undef truncate
66 #endif
67 
68 // get Qt keywords back
69 #ifdef PYTHONQT_RESTORE_KEYWORDS
70 #define slots Q_SLOTS
71 #undef PYTHONQT_RESTORE_KEYWORDS
72 #endif
73 
74 #if PY_MAJOR_VERSION >= 3
75 #define PY3K
76 // Helper defines to facilitate porting
77 #define PyString_FromString PyUnicode_FromString
78 #define PyString_AS_STRING PyUnicode_AsUTF8
79 #define PyString_AsString PyUnicode_AsUTF8
80 #define PyString_FromFormat PyUnicode_FromFormat
81 #define PyString_Check PyUnicode_Check
82 
83 #define PyInt_Type PyLong_Type
84 #define PyInt_FromLong PyLong_FromLong
85 #define PyInt_AS_LONG PyLong_AS_LONG
86 #define PyInt_Check PyLong_Check
87 #define PyInt_AsLong PyLong_AsLong
88 
89 #else
90 // Defines to use Python 3 names in Python 2 code
91 #define PyBytes_Type PyString_Type
92 #define PyBytes_Check PyString_Check
93 #define PyBytes_AS_STRING PyString_AS_STRING
94 #define PyBytes_AsString PyString_AsString
95 #define PyBytes_GET_SIZE PyString_GET_SIZE
96 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
97 #endif
98 
99 #endif