26 Py_XINCREF( pyclass );
29 std::vector< PyCallable* >
dummy;
66 PyObject_GC_Track( pytmpl );
73 int tpp_clear( TemplateProxy* pytmpl )
75 Py_CLEAR( pytmpl->fPyName );
76 Py_CLEAR( pytmpl->fPyClass );
77 Py_CLEAR( pytmpl->fSelf );
78 Py_CLEAR( pytmpl->fNonTemplated );
79 Py_CLEAR( pytmpl->fTemplated );
87 void tpp_dealloc( TemplateProxy* pytmpl )
89 PyObject_GC_UnTrack( pytmpl );
91 PyObject_GC_Del( pytmpl );
97 PyObject* tpp_doc( TemplateProxy* pytmpl,
void* )
100 if ( pytmpl->fNonTemplated )
101 doc = PyObject_GetAttrString( (
PyObject*)pytmpl->fNonTemplated,
"__doc__" );
102 if ( pytmpl->fTemplated ) {
103 PyObject* doc2 = PyObject_GetAttrString( (
PyObject*)pytmpl->fTemplated,
"__doc__" );
107 }
else if ( !doc && doc2 ) {
121 int tpp_traverse( TemplateProxy* pytmpl, visitproc visit,
void* arg )
123 Py_VISIT( pytmpl->fPyName );
124 Py_VISIT( pytmpl->fPyClass );
125 Py_VISIT( pytmpl->fSelf );
126 Py_VISIT( pytmpl->fNonTemplated );
127 Py_VISIT( pytmpl->fTemplated );
177 Py_DECREF( pymeth ); pymeth = 0;
184 Py_XDECREF( pymeth ); pymeth = 0;
190 PyErr_Format( PyExc_TypeError,
"template method \'%s\' with no arguments must be explicit",
201 pymeth = PyObject_GetAttr( pytmpl->fSelf ? pytmpl->fSelf : pytmpl->fPyClass, pyname_v1 );
203 Py_DECREF( pyname_v1 );
215 Py_DECREF( pymeth ); pymeth = 0;
217 Py_XDECREF( pyname_v1 );
224 Py_XDECREF( pymeth ); pymeth = 0;
231 PyObject* tpArgs = PyTuple_New( nArgs );
232 for (
Int_t i = 0; i < nArgs; ++i ) {
233 PyObject* itemi = PyTuple_GET_ITEM( args, i );
234 if ( PyType_Check( itemi ) ) isType =
kTRUE;
235 else if ( ! isType &&
PyBytes_Check( itemi ) ) nStrings += 1;
243 PyTuple_SET_ITEM( tpArgs, i, tp );
247 const char* ptrname = 0;
249 case 'b': ptrname =
"char*";
break;
250 case 'h': ptrname =
"short*";
break;
251 case 'H': ptrname =
"unsigned short*";
break;
252 case 'i': ptrname =
"int*";
break;
253 case 'I': ptrname =
"unsigned int*";
break;
254 case 'l': ptrname =
"long*";
break;
255 case 'L': ptrname =
"unsigned long*";
break;
256 case 'f': ptrname =
"float*";
break;
257 case 'd': ptrname =
"double*";
break;
258 default: ptrname =
"void*";
262 PyTuple_SET_ITEM( tpArgs, i, pyptrname );
267 PyTuple_SET_ITEM( tpArgs, i, pytc );
276 const std::string& tmplname = pytmpl->fNonTemplated->fMethodInfo->fName;
279 if ( ! isType && ! ( nStrings == nArgs ) ) {
283 Py_DECREF( pyname_v2 );
284 std::string proto = mname.substr( 1, mname.size() - 2 );
288 Py_XDECREF( pyname_v1 );
291 pytmpl->fTemplated->AddMethod(
new TFunctionHolder( scope, (
Cppyy::TCppMethod_t)cppmeth ) );
299 PyObject_SetAttrString( pytmpl->fPyClass, (
char*)cppmeth->GetName(), (
PyObject*)pymeth );
301 pymeth = PyObject_GetAttrString(
302 pytmpl->fSelf ? pytmpl->fSelf : pytmpl->fPyClass, (
char*)cppmeth->GetName() );
318 PyObject_SetAttr( pytmpl->fPyClass, pyname_v1, (
PyObject*)pymeth );
319 if ( mname != cppmeth->
GetName() )
320 PyObject_SetAttrString( pytmpl->fPyClass, (
char*)mname.c_str(), (
PyObject*)pymeth );
322 pymeth = PyObject_GetAttr( pytmpl->fSelf ? pytmpl->fSelf : pytmpl->fPyClass, pyname_v1 );
323 Py_DECREF( pyname_v1 );
326 Py_DECREF( pyname_v1 );
330 PyErr_Format( PyExc_TypeError,
"can not resolve method template call for \'%s\'",
338 TemplateProxy* tpp_descrget( TemplateProxy* pytmpl,
PyObject* pyobj,
PyObject* )
340 TemplateProxy* newPyTmpl = (TemplateProxy*)TemplateProxy_Type.tp_alloc( &TemplateProxy_Type, 0 );
343 Py_INCREF( pytmpl->fPyName );
344 newPyTmpl->fPyName = pytmpl->fPyName;
346 Py_XINCREF( pytmpl->fPyClass );
347 newPyTmpl->fPyClass = pytmpl->fPyClass;
350 Py_INCREF( pytmpl->fNonTemplated );
351 newPyTmpl->fNonTemplated = pytmpl->fNonTemplated;
354 Py_INCREF( pytmpl->fTemplated );
355 newPyTmpl->fTemplated = pytmpl->fTemplated;
359 newPyTmpl->fSelf = pyobj;
366 PyGetSetDef tpp_getset[] = {
375 PyTypeObject TemplateProxy_Type = {
377 (
char*)
"ROOT.TemplateProxy",
380 (destructor)tpp_dealloc,
390 (ternaryfunc)tpp_call,
395 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
396 (
char*)
"PyROOT template proxy (internal)",
397 (traverseproc)tpp_traverse,
408 (descrgetfunc)tpp_descrget,
421 #
if PY_VERSION_HEX >= 0x02030000
424 #
if PY_VERSION_HEX >= 0x02060000
427 #
if PY_VERSION_HEX >= 0x03040000
#define PyBytes_FromString
#define PyROOT_PyUnicode_FromString
void AddOverload(MethodProxy *mp)
Store overloads of this templated method.
MethodProxy * fNonTemplated
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
MethodProxy * MethodProxy_New(const std::string &name, std::vector< PyCallable * > &methods)
PyObject * BuildTemplateName(PyObject *pyname, PyObject *args, int argoff)
Helper to construct the "< type, type, ... >" part of a templated name (either for a class as in Make...
#define PyVarObject_HEAD_INIT(type, size)
#define PyROOT_PyUnicode_AsString
PyObject_HEAD PyObject * fSelf
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
void AddTemplate(PyCallable *pc)
PyTypeObject MethodProxy_Type
void Set(const std::string &name, PyObject *pyclass)
Initialize the proxy for the given 'pyclass.'.
#define PyROOT_PyUnicode_AppendAndDel
TCppScope_t GetScope(const std::string &scope_name)
R__EXTERN PyObject * gName
void AddMethod(PyCallable *pc)
Fill in the data of a freshly created method proxy.
R__EXTERN PyObject * gTypeCode
static RooMathCoreReg dummy
#define PyROOT_PyUnicode_Check
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Each ROOT class (see TClass) has a linked list of methods.
Bool_t MethodProxy_Check(T *object)
TMethod * GetMethodAny(const char *method)
Return pointer to method without looking at parameters.
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Template proxy object to return functions and methods.