7 #if PY_VERSION_HEX >= 0x03000000
9 #define PyMethod_GET_CLASS( meth ) Py_None
16 PyTypeObject TCustomFloat_Type = {
17 PyVarObject_HEAD_INIT( &PyType_Type, 0 )
36 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
38 (
char*)
"PyROOT float object for pass by reference",
63 #if PY_VERSION_HEX >= 0x02030000
66 #if PY_VERSION_HEX >= 0x02060000
69 #if PY_VERSION_HEX >= 0x03040000
75 PyTypeObject TCustomInt_Type = {
76 PyVarObject_HEAD_INIT( &PyType_Type, 0 )
95 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
97 (
char*)
"PyROOT long object for pass by reference",
122 #if PY_VERSION_HEX >= 0x02030000
125 #if PY_VERSION_HEX >= 0x02060000
128 #if PY_VERSION_HEX >= 0x03040000
134 static PyMethodObject* free_list;
135 static int numfree = 0;
136 #ifndef PyMethod_MAXFREELIST
137 #define PyMethod_MAXFREELIST 256
140 PyObject* TCustomInstanceMethod_New( PyObject* func, PyObject*
self, PyObject*
141 #
if PY_VERSION_HEX < 0x03000000
149 if ( ! PyCallable_Check( func ) ) {
150 PyErr_Format( PyExc_SystemError,
151 "%s:%d: bad argument to internal function",
152 __FILE__, __LINE__ );
158 free_list = (PyMethodObject*)( im->im_self );
159 (void)PyObject_INIT( im, &TCustomInstanceMethod_Type );
162 im = PyObject_GC_New( PyMethodObject, &TCustomInstanceMethod_Type );
167 im->im_weakreflist = NULL;
172 #if PY_VERSION_HEX < 0x03000000
173 Py_XINCREF( pyclass );
174 im->im_class = pyclass;
176 PyObject_GC_Track( im );
177 return (PyObject*)im;
184 static void im_dealloc( PyMethodObject* im )
186 PyObject_GC_UnTrack( im );
188 if ( im->im_weakreflist != NULL )
189 PyObject_ClearWeakRefs( (PyObject*) im );
191 Py_DECREF( im->im_func );
192 Py_XDECREF( im->im_self );
193 #if PY_VERSION_HEX < 0x03000000
194 Py_XDECREF( im->im_class );
197 if ( numfree < PyMethod_MAXFREELIST ) {
198 im->im_self = (PyObject*)free_list;
212 static PyObject* im_call( PyObject* meth, PyObject* args, PyObject* kw )
214 PyObject*
self = PyMethod_GET_SELF( meth );
219 Py_ssize_t argc = PyTuple_GET_SIZE( args );
220 PyObject* pyclass = PyMethod_GET_CLASS( meth );
221 if ( 1 <= argc && PyObject_IsInstance( PyTuple_GET_ITEM( args, 0 ), pyclass ) == 1 ) {
222 self = PyTuple_GET_ITEM( args, 0 );
224 PyObject* newArgs = PyTuple_New( argc - 1 );
225 for (
int i = 1; i < argc; ++i ) {
226 PyObject* v = PyTuple_GET_ITEM( args, i );
228 PyTuple_SET_ITEM( newArgs, i-1, v );
234 return PyMethod_Type.tp_call( meth, args, kw );
239 PyCFunctionObject* func = (PyCFunctionObject*)PyMethod_GET_FUNCTION( meth );
244 PyObject* result = PyCFunction_Call( (PyObject*)func, args, kw );
255 static PyObject* im_descr_get( PyObject* meth, PyObject* obj, PyObject* pyclass )
257 if ( PyMethod_GET_SELF( meth ) != NULL
258 #
if PY_VERSION_HEX < 0x03000000
259 || ( PyMethod_GET_CLASS( meth ) != NULL &&
260 ! PyObject_IsSubclass( pyclass, PyMethod_GET_CLASS(meth) ) )
267 if ( obj == Py_None )
270 return TCustomInstanceMethod_New( PyMethod_GET_FUNCTION( meth ), obj, pyclass );
274 PyTypeObject TCustomInstanceMethod_Type = {
275 PyVarObject_HEAD_INIT( &PyType_Type, 0 )
276 (
char*)
"ROOT.InstanceMethod",
279 (destructor)im_dealloc,
294 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
296 (
char*)
"PyROOT custom instance method (internal)",
321 #
if PY_VERSION_HEX >= 0x02030000
324 #
if PY_VERSION_HEX >= 0x02060000
327 #
if PY_VERSION_HEX >= 0x03040000