Logo ROOT   6.16/01
Reference Guide
TFunctionHolder.cxx
Go to the documentation of this file.
1// Author: Wim Lavrijsen, Apr 2005
2
3// Bindings
4#include "PyROOT.h"
5#include "TFunctionHolder.h"
6#include "ObjectProxy.h"
7
8
9//- public members --------------------------------------------------------------
11 ObjectProxy*& self, PyObject* args, PyObject* )
12{
13// no self means called as a free function; all ok
14 if ( ! self ) {
15 Py_INCREF( args );
16 return args;
17 }
18
19// otherwise, add self as part of the function arguments (means bound member)
20 Py_ssize_t sz = PyTuple_GET_SIZE( args );
21 PyObject* newArgs = PyTuple_New( sz + 1 );
22 for ( int i = 0; i < sz; ++i ) {
23 PyObject* item = PyTuple_GET_ITEM( args, i );
24 Py_INCREF( item );
25 PyTuple_SET_ITEM( newArgs, i + 1, item );
26 }
27
28 Py_INCREF( self );
29 PyTuple_SET_ITEM( newArgs, 0, (PyObject*)self );
30
31 return newArgs;
32}
33
34////////////////////////////////////////////////////////////////////////////////
35/// preliminary check in case keywords are accidently used (they are ignored otherwise)
36
38 ObjectProxy*& self, PyObject* args, PyObject* kwds, TCallContext* ctxt )
39{
40 if ( kwds != 0 && PyDict_Size( kwds ) ) {
41 PyErr_SetString( PyExc_TypeError, "keyword arguments are not yet supported" );
42 return 0;
43 }
44
45// setup as necessary
46 if ( ! this->Initialize( ctxt ) )
47 return 0; // important: 0, not Py_None
48
49// reorder self into args, if necessary
50 if ( ! ( args = this->PreProcessArgs( self, args, kwds ) ) )
51 return 0;
52
53// translate the arguments
54 Bool_t bConvertOk = this->ConvertAndSetArgs( args, ctxt );
55 Py_DECREF( args );
56
57 if ( bConvertOk == kFALSE )
58 return 0; // important: 0, not Py_None
59
60// execute function
61 return this->Execute( 0, 0, ctxt );
62}
int Py_ssize_t
Definition: PyROOT.h:166
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
_object PyObject
Definition: TPyArg.h:20
virtual PyObject * PreProcessArgs(ObjectProxy *&self, PyObject *args, PyObject *kwds)
verify existence of self, return if ok
virtual PyObject * Call(ObjectProxy *&, PyObject *args, PyObject *kwds, TCallContext *ctx=0)
preliminary check in case keywords are accidently used (they are ignored otherwise)
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176