H3D API  2.4.1
Python3Compatibility.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __PYTHON3COMPATIBILITY_H__
30 #define __PYTHON3COMPATIBILITY_H__
31 
32 #include <H3D/H3DApi.h>
33 #include <H3D/Field.h>
34 #if defined(_MSC_VER)
35 // undefine _DEBUG since we want to always link to the release version of
36 // python and pyconfig.h automatically links debug version if _DEBUG is
37 // defined.
38 #if defined _DEBUG && ! defined HAVE_PYTHON_DEBUG_LIBRARY
39 #define _DEBUG_UNDEFED
40 #undef _DEBUG
41 #endif
42 
43 // define HAVE_ROUND if not defined
44 #if _MSC_VER >= 1800
45 #ifndef HAVE_ROUND
46 #define HAVE_ROUND 1
47 #endif
48 #endif // _MSC_VER >= 1800
49 
50 #endif
51 #if defined(__APPLE__) && defined(__MACH__) && defined( HAVE_PYTHON_OSX_FRAMEWORK )
52 #include <Python/Python.h>
53 #else
54 #ifdef __GNUC__
55 #ifdef _POSIX_C_SOURCE
56 #undef _POSIX_C_SOURCE
57 #endif
58 #ifdef _XOPEN_SOURCE
59 #undef _XOPEN_SOURCE
60 #endif
61 #endif
62 #include <Python.h>
63 #endif
64 #if defined(_MSC_VER)
65 // redefine _DEBUG if it was undefed
66 #ifdef _DEBUG_UNDEFED
67 #define _DEBUG
68 #endif
69 #endif
70 
71 // Get Field pointer encapsulated in an PyCapsule object.
72 inline H3D::Field *getFieldPointer(PyObject * po) {
73  return static_cast< H3D::Field * >
74  ( PyCapsule_GetPointer( po, NULL ) );
75 
76 }
77 
78 #if PY_MAJOR_VERSION >= 3
79 
80 inline PyObject *Py_FindMethod(PyMethodDef[], PyObject *o, const char *name){
81  PyObject *nameobj = PyUnicode_FromString(name);
82  return PyObject_GenericGetAttr((PyObject *)o, nameobj);
83 }
84 
85 // replace PyInt with PyLong variants
86 #define PyInt_Check PyLong_Check
87 #define PyInt_FromLong PyLong_FromLong
88 #define PyInt_AsLong PyLong_AsLong
89 #define PyInt_FromSize_t PyLong_FromSize_t
90 
91 // removed in python 3, used in bit masks. set to 0 to do nothing
92 // if used in such masks
93 #define Py_TPFLAGS_CHECKTYPES 0
94 
95 // replace PyString with PyUnicode
96 #define PyString_Check PyUnicode_Check
97 #define PyString_AsString(X) ( PyBytes_AsString( PyUnicode_AsUTF8String(X) ) )
98 #define PyString_FromString(X) PyUnicode_FromString(X)
99 #endif //PY_MAJOR_VERSION >= 3
100 
101 
102 #endif
Contains the Field class.
Base header file that handles all configuration related settings.
The Field class.
Definition: Field.h:46