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#if PY_VERSION_HEX >= 0x03000000
236 else if ( ! isType && PyUnicode_Check( itemi ) ) nStrings += 1;
238 else if ( ! isType &&
PyBytes_Check( itemi ) ) nStrings += 1;
247 PyTuple_SET_ITEM( tpArgs, i, tp );
251 const char* ptrname = 0;
253 case 'b': ptrname =
"char*";
break;
254 case 'h': ptrname =
"short*";
break;
255 case 'H': ptrname =
"unsigned short*";
break;
256 case 'i': ptrname =
"int*";
break;
257 case 'I': ptrname =
"unsigned int*";
break;
258 case 'l': ptrname =
"long*";
break;
259 case 'L': ptrname =
"unsigned long*";
break;
260 case 'f': ptrname =
"float*";
break;
261 case 'd': ptrname =
"double*";
break;
262 default: ptrname =
"void*";
266 PyTuple_SET_ITEM( tpArgs, i, pyptrname );
271 PyTuple_SET_ITEM( tpArgs, i, pytc );
278 if ( ! clName ) clName = PyObject_GetAttr( pytmpl->fPyClass,
PyStrings::gName );
281 const std::string& tmplname = pytmpl->fNonTemplated->fMethodInfo->fName;
284 if ( ! isType && ! ( nStrings == nArgs ) ) {
288 Py_DECREF( pyname_v2 );
289 std::string
proto = mname.substr( 1, mname.size() - 2 );
293 Py_XDECREF( pyname_v1 );
296 pytmpl->fTemplated->AddMethod(
new TFunctionHolder( scope, (
Cppyy::TCppMethod_t)cppmeth ) );
304 PyObject_SetAttrString( pytmpl->fPyClass, (
char*)cppmeth->GetName(), (
PyObject*)pymeth );
306 pymeth = PyObject_GetAttrString(
307 pytmpl->fSelf ? pytmpl->fSelf : pytmpl->fPyClass, (
char*)cppmeth->GetName() );
323 PyObject_SetAttr( pytmpl->fPyClass, pyname_v1, (
PyObject*)pymeth );
324 if ( mname != cppmeth->GetName() )
325 PyObject_SetAttrString( pytmpl->fPyClass, (
char*)mname.c_str(), (
PyObject*)pymeth );
327 pymeth = PyObject_GetAttr( pytmpl->fSelf ? pytmpl->fSelf : pytmpl->fPyClass, pyname_v1 );
328 Py_DECREF( pyname_v1 );
331 Py_DECREF( pyname_v1 );
335 PyErr_Format( PyExc_TypeError,
"can not resolve method template call for \'%s\'",
343 TemplateProxy* tpp_descrget( TemplateProxy* pytmpl,
PyObject* pyobj,
PyObject* )
348 Py_INCREF( pytmpl->fPyName );
349 newPyTmpl->fPyName = pytmpl->fPyName;
351 Py_XINCREF( pytmpl->fPyClass );
352 newPyTmpl->fPyClass = pytmpl->fPyClass;
355 Py_INCREF( pytmpl->fNonTemplated );
356 newPyTmpl->fNonTemplated = pytmpl->fNonTemplated;
359 Py_INCREF( pytmpl->fTemplated );
360 newPyTmpl->fTemplated = pytmpl->fTemplated;
364 newPyTmpl->fSelf = pyobj;
371 PyGetSetDef tpp_getset[] = {
372 { (
char*)
"__doc__", (getter)tpp_doc, NULL, NULL, NULL },
373 { (
char*)NULL, NULL, NULL, NULL, NULL }
382 (
char*)
"ROOT.TemplateProxy",
385 (destructor)tpp_dealloc,
395 (ternaryfunc)tpp_call,
400 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
401 (
char*)
"PyROOT template proxy (internal)",
402 (traverseproc)tpp_traverse,
413 (descrgetfunc)tpp_descrget,
426#
if PY_VERSION_HEX >= 0x02030000
429#
if PY_VERSION_HEX >= 0x02060000
432#
if PY_VERSION_HEX >= 0x03040000
#define PyBytes_FromString
#define PyROOT_PyUnicode_Check
#define PyROOT_PyUnicode_AsString
#define PyROOT_PyUnicode_AppendAndDel
#define PyROOT_PyUnicode_FromString
#define PyVarObject_HEAD_INIT(type, size)
static RooMathCoreReg dummy
void AddMethod(PyCallable *pc)
Fill in the data of a freshly created method proxy.
Template proxy object to return functions and methods.
MethodProxy * fNonTemplated
void AddOverload(MethodProxy *mp)
Store overloads of this templated method.
void Set(const std::string &name, PyObject *pyclass)
Initialize the proxy for the given 'pyclass.'.
PyObject_HEAD PyObject * fSelf
void AddTemplate(PyCallable *pc)
The ROOT global object gROOT contains a list of all defined classes.
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
TMethod * GetMethodAny(const char *method)
Return pointer to method without looking at parameters.
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.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Each ROOT class (see TClass) has a linked list of methods.
virtual const char * GetName() const
Returns name of object.
TCppScope_t GetScope(const std::string &scope_name)
R__EXTERN PyObject * gName
R__EXTERN PyObject * gTypeCode
R__EXTERN PyObject * gCppName
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...
MethodProxy * MethodProxy_New(const std::string &name, std::vector< PyCallable * > &methods)
Bool_t MethodProxy_Check(T *object)
PyTypeObject TemplateProxy_Type
PyTypeObject MethodProxy_Type
static constexpr double pc