Logo ROOT  
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.3 support
51#if PY_VERSION_HEX < 0x03030000
52// Use PyString_Size for a version lower than 3.0
53#if PY_VERSION_HEX < 0x03000000
54#define PyROOT_PyUnicode_GetSize PyString_Size
55#else
56#define PyROOT_PyUnicode_GetSize PyUnicode_GetSize
57#endif
58#else // if greater or equal than 3.3
59#define PyROOT_PyUnicode_GetSize PyUnicode_GetLength
60#endif
61
62// for 3.0 support (backwards compatibility, really)
63#if PY_VERSION_HEX < 0x03000000
64#define PyBytes_Check PyString_Check
65#define PyBytes_CheckExact PyString_CheckExact
66#define PyBytes_AS_STRING PyString_AS_STRING
67#define PyBytes_AsString PyString_AsString
68#define PyBytes_GET_SIZE PyString_GET_SIZE
69#define PyBytes_Size PyString_Size
70#define PyBytes_FromFormat PyString_FromFormat
71#define PyBytes_FromString PyString_FromString
72#define PyBytes_FromStringAndSize PyString_FromStringAndSize
73
74#define PyBytes_Type PyString_Type
75
76#define PyROOT_PyUnicode_Check PyString_Check
77#define PyROOT_PyUnicode_CheckExact PyString_CheckExact
78#define PyROOT_PyUnicode_AsString PyString_AS_STRING
79#define PyROOT_PyUnicode_AsStringChecked PyString_AsString
80#define PyROOT_PyUnicode_GET_SIZE PyString_GET_SIZE
81#define PyROOT_PyUnicode_FromFormat PyString_FromFormat
82#define PyROOT_PyUnicode_FromString PyString_FromString
83#define PyROOT_PyUnicode_InternFromString PyString_InternFromString
84#define PyROOT_PyUnicode_Append PyString_Concat
85#define PyROOT_PyUnicode_AppendAndDel PyString_ConcatAndDel
86#define PyROOT_PyUnicode_FromStringAndSize PyString_FromStringAndSize
87
88#define PyROOT_PyUnicode_Type PyString_Type
89
90static inline PyObject* PyROOT_PyCapsule_New( void* cobj, const char* /* name */, void (*destr)(void *) )
91{
92 return PyCObject_FromVoidPtr( cobj, destr );
93}
94#define PyROOT_PyCapsule_CheckExact PyCObject_Check
95static inline void* PyROOT_PyCapsule_GetPointer( PyObject* capsule, const char* /* name */ )
96{
97 return (void*)PyCObject_AsVoidPtr( capsule );
98}
99
100#define PYROOT__long__ "__long__"
101#define PYROOT__idiv__ "__idiv__"
102#define PYROOT__div__ "__div__"
103#define PYROOT__next__ "next"
104
105#endif // ! 3.0
106
107// Support non-ASCII strings
108#if PY_VERSION_HEX >= 0x03030000
109#define PyROOT_PyUnicode_AsStringAndSize _PyUnicode_AsStringAndSize
110#endif
111
112// for 3.0 support (backwards compatibility, really)
113#if PY_VERSION_HEX >= 0x03000000
114#define PyROOT_PyUnicode_Check PyUnicode_Check
115#define PyROOT_PyUnicode_CheckExact PyUnicode_CheckExact
116#define PyROOT_PyUnicode_AsString _PyUnicode_AsString
117#define PyROOT_PyUnicode_AsStringChecked _PyUnicode_AsString
118#define PyROOT_PyUnicode_GET_SIZE PyUnicode_GET_SIZE
119#define PyROOT_PyUnicode_FromFormat PyUnicode_FromFormat
120#define PyROOT_PyUnicode_FromString PyUnicode_FromString
121#define PyROOT_PyUnicode_InternFromString PyUnicode_InternFromString
122#define PyROOT_PyUnicode_Append PyUnicode_Append
123#define PyROOT_PyUnicode_AppendAndDel PyUnicode_AppendAndDel
124#define PyROOT_PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
125
126#define PyROOT_PyUnicode_Type PyUnicode_Type
127
128#define PyIntObject PyLongObject
129#define PyInt_Check PyLong_Check
130#define PyInt_AsLong PyLong_AsLong
131#define PyInt_AS_LONG PyLong_AsLong
132#define PyInt_AsSsize_t PyLong_AsSsize_t
133#define PyInt_CheckExact PyLong_CheckExact
134#define PyInt_FromLong PyLong_FromLong
135#define PyInt_FromSsize_t PyLong_FromSsize_t
136
137#define PyInt_Type PyLong_Type
138
139#define PyROOT_PyCapsule_New PyCapsule_New
140#define PyROOT_PyCapsule_CheckExact PyCapsule_CheckExact
141#define PyROOT_PyCapsule_GetPointer PyCapsule_GetPointer
142
143#define PYROOT__long__ "__int__"
144#define PYROOT__idiv__ "__itruediv__"
145#define PYROOT__div__ "__truediv__"
146#define PYROOT__next__ "__next__"
147
148#define Py_TPFLAGS_HAVE_RICHCOMPARE 0
149#define Py_TPFLAGS_CHECKTYPES 0
150
151#define PyClass_Check PyType_Check
152
153#define PyBuffer_Type PyMemoryView_Type
154#endif // ! 3.0
155
156#if PY_VERSION_HEX >= 0x03020000
157#define PyROOT_PySliceCast PyObject*
158#else
159#define PyROOT_PySliceCast PySliceObject*
160#endif // >= 3.2
161
162// feature of 3.0 not in 2.5 and earlier
163#if PY_VERSION_HEX < 0x02060000
164#define PyVarObject_HEAD_INIT(type, size) \
165 PyObject_HEAD_INIT(type) size,
166#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
167#endif
168
169// backwards compatibility, pre python 2.5
170#if PY_VERSION_HEX < 0x02050000
171typedef int Py_ssize_t;
172#define PyInt_AsSsize_t PyInt_AsLong
173#define PyInt_FromSsize_t PyInt_FromLong
174# define PY_SSIZE_T_FORMAT "%d"
175# if !defined(PY_SSIZE_T_MIN)
176# define PY_SSIZE_T_MAX INT_MAX
177# define PY_SSIZE_T_MIN INT_MIN
178# endif
179#define ssizeobjargproc intobjargproc
180#define lenfunc inquiry
181#define ssizeargfunc intargfunc
182
183#define PyIndex_Check(obj) \
184 (PyInt_Check(obj) || PyLong_Check(obj))
185
187 return (Py_ssize_t)PyLong_AsLong( obj );
188}
189
190#else
191# ifdef R__MACOSX
192# if SIZEOF_SIZE_T == SIZEOF_INT
193# if defined(MAC_OS_X_VERSION_10_4)
194# define PY_SSIZE_T_FORMAT "%ld"
195# else
196# define PY_SSIZE_T_FORMAT "%d"
197# endif
198# elif SIZEOF_SIZE_T == SIZEOF_LONG
199# define PY_SSIZE_T_FORMAT "%ld"
200# endif
201# else
202# define PY_SSIZE_T_FORMAT "%zd"
203# endif
204#endif
205
206#if PY_VERSION_HEX < 0x02020000
207#define PyBool_FromLong PyInt_FromLong
208#endif
209
210#if PY_VERSION_HEX < 0x03000000
211// the following should quiet Solaris
212#ifdef Py_False
213#undef Py_False
214#define Py_False ( (PyObject*)(void*)&_Py_ZeroStruct )
215#endif
216
217#ifdef Py_True
218#undef Py_True
219#define Py_True ( (PyObject*)(void*)&_Py_TrueStruct )
220#endif
221#endif
222
223// C++ version of the cppyy API
224#include "Cppyy.h"
225
226#endif // !PYROOT_PYROOT_H
Py_ssize_t PyNumber_AsSsize_t(PyObject *obj, PyObject *)
Definition: PyROOT.h:186
int Py_ssize_t
Definition: PyROOT.h:171
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
Definition: PyROOT.h:95
static PyObject * PyROOT_PyCapsule_New(void *cobj, const char *, void(*destr)(void *))
Definition: PyROOT.h:90
long Long_t
Definition: RtypesCore.h:50
_object PyObject
Definition: TPyArg.h:20