SourceForge.net Logo
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 // get Qt keywords back
63 #ifdef PYTHONQT_RESTORE_KEYWORDS
64 #define slots Q_SLOTS
65 #undef PYTHONQT_RESTORE_KEYWORDS
66 #endif
67 
68 #if PY_MAJOR_VERSION >= 3
69 #define PY3K
70 // Helper defines to facilitate porting
71 #define PyString_FromString PyUnicode_FromString
72 #define PyString_AS_STRING PyUnicode_AsUTF8
73 #define PyString_AsString PyUnicode_AsUTF8
74 #define PyString_FromFormat PyUnicode_FromFormat
75 #define PyString_Check PyUnicode_Check
76 
77 #define PyInt_Type PyLong_Type
78 #define PyInt_FromLong PyLong_FromLong
79 #define PyInt_AS_LONG PyLong_AS_LONG
80 #define PyInt_Check PyLong_Check
81 #define PyInt_AsLong PyLong_AsLong
82 
83 #else
84 // Defines to use Python 3 names in Python 2 code
85 #define PyBytes_Type PyString_Type
86 #define PyBytes_Check PyString_Check
87 #define PyBytes_AS_STRING PyString_AS_STRING
88 #define PyBytes_AsString PyString_AsString
89 #define PyBytes_GET_SIZE PyString_GET_SIZE
90 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
91 #endif
92 
93 #endif