Logo ROOT   6.12/07
Reference Guide
PyROOT.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen, Apr 2004
3 
4 #ifndef PYROOT_PYROOT_H
5 #define PYROOT_PYROOT_H
6 
7 #ifdef _WIN32
8 // Disable warning C4275: non dll-interface class
9 #pragma warning ( disable : 4275 )
10 // Disable warning C4251: needs to have dll-interface to be used by clients
11 #pragma warning ( disable : 4251 )
12 // Disable warning C4800: 'int' : forcing value to bool
13 #pragma warning ( disable : 4800 )
14 // Avoid that pyconfig.h decides using a #pragma what library python library to use
15 //#define MS_NO_COREDLL 1
16 #endif
17 
18 // to prevent problems with fpos_t and redefinition warnings
19 #if defined(linux)
20 
21 #include <stdio.h>
22 
23 #ifdef _POSIX_C_SOURCE
24 #undef _POSIX_C_SOURCE
25 #endif
26 
27 #ifdef _FILE_OFFSET_BITS
28 #undef _FILE_OFFSET_BITS
29 #endif
30 
31 #ifdef _XOPEN_SOURCE
32 #undef _XOPEN_SOURCE
33 #endif
34 
35 #endif // linux
36 
37 
38 #include "Python.h"
39 #include "Rtypes.h"
40 
41 // for 3.3 support
42 #if PY_VERSION_HEX < 0x03030000
43  typedef PyDictEntry* (*dict_lookup_func) ( PyDictObject*, PyObject*, Long_t );
44 #else
45  struct PyDictKeyEntry;
46  typedef PyDictKeyEntry* (*dict_lookup_func) ( PyDictObject*, PyObject*, Py_hash_t, PyObject*** );
47 #define PyDictEntry PyDictKeyEntry
48 #endif
49 
50 // for 3.0 support (backwards compatibility, really)
51 #if PY_VERSION_HEX < 0x03000000
52 #define PyBytes_Check PyString_Check
53 #define PyBytes_CheckExact PyString_CheckExact
54 #define PyBytes_AS_STRING PyString_AS_STRING
55 #define PyBytes_AsString PyString_AsString
56 #define PyBytes_GET_SIZE PyString_GET_SIZE
57 #define PyBytes_Size PyString_Size
58 #define PyBytes_FromFormat PyString_FromFormat
59 #define PyBytes_FromString PyString_FromString
60 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
61 
62 #define PyBytes_Type PyString_Type
63 
64 #define PyROOT_PyUnicode_Check PyString_Check
65 #define PyROOT_PyUnicode_CheckExact PyString_CheckExact
66 #define PyROOT_PyUnicode_AsString PyString_AS_STRING
67 #define PyROOT_PyUnicode_AsStringChecked PyString_AsString
68 #define PyROOT_PyUnicode_GET_SIZE PyString_GET_SIZE
69 #define PyROOT_PyUnicode_GetSize PyString_Size
70 #define PyROOT_PyUnicode_FromFormat PyString_FromFormat
71 #define PyROOT_PyUnicode_FromString PyString_FromString
72 #define PyROOT_PyUnicode_InternFromString PyString_InternFromString
73 #define PyROOT_PyUnicode_Append PyString_Concat
74 #define PyROOT_PyUnicode_AppendAndDel PyString_ConcatAndDel
75 #define PyROOT_PyUnicode_FromStringAndSize PyString_FromStringAndSize
76 
77 #define PyROOT_PyUnicode_Type PyString_Type
78 
79 static inline PyObject* PyROOT_PyCapsule_New( void* cobj, const char* /* name */, void (*destr)(void *) )
80 {
81  return PyCObject_FromVoidPtr( cobj, destr );
82 }
83 #define PyROOT_PyCapsule_CheckExact PyCObject_Check
84 static inline void* PyROOT_PyCapsule_GetPointer( PyObject* capsule, const char* /* name */ )
85 {
86  return (void*)PyCObject_AsVoidPtr( capsule );
87 }
88 
89 #define PYROOT__long__ "__long__"
90 #define PYROOT__idiv__ "__idiv__"
91 #define PYROOT__div__ "__div__"
92 #define PYROOT__next__ "next"
93 
94 #endif // ! 3.0
95 
96 // for 3.0 support (backwards compatibility, really)
97 #if PY_VERSION_HEX >= 0x03000000
98 #define PyROOT_PyUnicode_Check PyUnicode_Check
99 #define PyROOT_PyUnicode_CheckExact PyUnicode_CheckExact
100 #define PyROOT_PyUnicode_AsString _PyUnicode_AsString
101 #define PyROOT_PyUnicode_AsStringChecked _PyUnicode_AsString
102 #define PyROOT_PyUnicode_GetSize PyUnicode_GetSize
103 #define PyROOT_PyUnicode_GET_SIZE PyUnicode_GET_SIZE
104 #define PyROOT_PyUnicode_FromFormat PyUnicode_FromFormat
105 #define PyROOT_PyUnicode_FromString PyUnicode_FromString
106 #define PyROOT_PyUnicode_InternFromString PyUnicode_InternFromString
107 #define PyROOT_PyUnicode_Append PyUnicode_Append
108 #define PyROOT_PyUnicode_AppendAndDel PyUnicode_AppendAndDel
109 #define PyROOT_PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
110 
111 #define PyROOT_PyUnicode_Type PyUnicode_Type
112 
113 #define PyIntObject PyLongObject
114 #define PyInt_Check PyLong_Check
115 #define PyInt_AsLong PyLong_AsLong
116 #define PyInt_AS_LONG PyLong_AsLong
117 #define PyInt_AsSsize_t PyLong_AsSsize_t
118 #define PyInt_CheckExact PyLong_CheckExact
119 #define PyInt_FromLong PyLong_FromLong
120 #define PyInt_FromSsize_t PyLong_FromSsize_t
121 
122 #define PyInt_Type PyLong_Type
123 
124 #define PyROOT_PyCapsule_New PyCapsule_New
125 #define PyROOT_PyCapsule_CheckExact PyCapsule_CheckExact
126 #define PyROOT_PyCapsule_GetPointer PyCapsule_GetPointer
127 
128 #define PYROOT__long__ "__int__"
129 #define PYROOT__idiv__ "__itruediv__"
130 #define PYROOT__div__ "__truediv__"
131 #define PYROOT__next__ "__next__"
132 
133 #define Py_TPFLAGS_HAVE_RICHCOMPARE 0
134 #define Py_TPFLAGS_CHECKTYPES 0
135 
136 #define PyClass_Check PyType_Check
137 
138 #define PyBuffer_Type PyMemoryView_Type
139 #endif // ! 3.0
140 
141 #if PY_VERSION_HEX >= 0x03020000
142 #define PyROOT_PySliceCast PyObject*
143 #else
144 #define PyROOT_PySliceCast PySliceObject*
145 #endif // >= 3.2
146 
147 // feature of 3.0 not in 2.5 and earlier
148 #if PY_VERSION_HEX < 0x02060000
149 #define PyVarObject_HEAD_INIT(type, size) \
150  PyObject_HEAD_INIT(type) size,
151 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
152 #endif
153 
154 // backwards compatibility, pre python 2.5
155 #if PY_VERSION_HEX < 0x02050000
156 typedef int Py_ssize_t;
157 #define PyInt_AsSsize_t PyInt_AsLong
158 #define PyInt_FromSsize_t PyInt_FromLong
159 # define PY_SSIZE_T_FORMAT "%d"
160 # if !defined(PY_SSIZE_T_MIN)
161 # define PY_SSIZE_T_MAX INT_MAX
162 # define PY_SSIZE_T_MIN INT_MIN
163 # endif
164 #define ssizeobjargproc intobjargproc
165 #define lenfunc inquiry
166 #define ssizeargfunc intargfunc
167 
168 #define PyIndex_Check(obj) \
169  (PyInt_Check(obj) || PyLong_Check(obj))
170 
171 inline Py_ssize_t PyNumber_AsSsize_t( PyObject* obj, PyObject* ) {
172  return (Py_ssize_t)PyLong_AsLong( obj );
173 }
174 
175 #else
176 # ifdef R__MACOSX
177 # if SIZEOF_SIZE_T == SIZEOF_INT
178 # if defined(MAC_OS_X_VERSION_10_4)
179 # define PY_SSIZE_T_FORMAT "%ld"
180 # else
181 # define PY_SSIZE_T_FORMAT "%d"
182 # endif
183 # elif SIZEOF_SIZE_T == SIZEOF_LONG
184 # define PY_SSIZE_T_FORMAT "%ld"
185 # endif
186 # else
187 # define PY_SSIZE_T_FORMAT "%zd"
188 # endif
189 #endif
190 
191 #if PY_VERSION_HEX < 0x02020000
192 #define PyBool_FromLong PyInt_FromLong
193 #endif
194 
195 #if PY_VERSION_HEX < 0x03000000
196 // the following should quiet Solaris
197 #ifdef Py_False
198 #undef Py_False
199 #define Py_False ( (PyObject*)(void*)&_Py_ZeroStruct )
200 #endif
201 
202 #ifdef Py_True
203 #undef Py_True
204 #define Py_True ( (PyObject*)(void*)&_Py_TrueStruct )
205 #endif
206 #endif
207 
208 // C++ version of the cppyy API
209 #include "Cppyy.h"
210 
211 #endif // !PYROOT_PYROOT_H
Py_ssize_t PyNumber_AsSsize_t(PyObject *obj, PyObject *)
Definition: PyROOT.h:171
long Long_t
Definition: RtypesCore.h:50
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
Definition: PyROOT.h:84
int Py_ssize_t
Definition: PyROOT.h:156
static PyObject * PyROOT_PyCapsule_New(void *cobj, const char *, void(*destr)(void *))
Definition: PyROOT.h:79
_object PyObject
Definition: TPyArg.h:20