Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPClassMethod.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CPPClassMethod.h"
4#include "CPPInstance.h"
5
6
7//- public members --------------------------------------------------------------
9#if PY_VERSION_HEX >= 0x03080000
10 self
11#endif
12 , CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt)
13{
14// preliminary check in case keywords are accidently used (they are ignored otherwise)
15 if (kwds && ((PyDict_Check(kwds) && PyDict_Size(kwds)) ||
16 (PyTuple_CheckExact(kwds) && PyTuple_GET_SIZE(kwds)))) {
17 PyErr_SetString(PyExc_TypeError, "keyword arguments are not yet supported");
18 return nullptr;
19 }
20
21// setup as necessary
22 if (!this->Initialize(ctxt))
23 return nullptr;
24
25// translate the arguments
26#if PY_VERSION_HEX >= 0x03080000
27// TODO: The following is not robust and should be revisited e.g. by making CPPOverloads
28// that have only CPPClassMethods be true Python classmethods? Note that the original
29// implementation wasn't 100% correct either (e.g. static size() mapped to len()).
30//
31// As-is, if no suitable `self` is given (normal case), but the type of the first argument
32// matches the enclosing scope of the class method and it isn't needed for the call, then
33// assume that the method was (incorrectly) bound and so drop that instance from args.
34 int nargs = (int)CPyCppyy_PyArgs_GET_SIZE(args, nargsf);
35 if ((!self || (PyObject*)self == Py_None) && nargs) {
36 PyObject* arg0 = CPyCppyy_PyArgs_GET_ITEM(args, 0);
37 if ((CPPInstance_Check(arg0) && ((CPPInstance*)arg0)->ObjectIsA() == GetScope()) && \
38 (fArgsRequired <= nargs-1)) {
39 args += 1; // drops first argument
40 nargsf -= 1;
41 }
42 }
43#endif
44
45 if (!this->ConvertAndSetArgs(args, nargsf, ctxt))
46 return nullptr;
47
48// execute function
49 return this->Execute(nullptr, 0, ctxt);
50}
static Py_ssize_t CPyCppyy_PyArgs_GET_SIZE(CPyCppyy_PyArgs_t args, size_t)
Definition CPyCppyy.h:337
PyObject * CPyCppyy_PyArgs_t
Definition CPyCppyy.h:330
static PyObject * CPyCppyy_PyArgs_GET_ITEM(CPyCppyy_PyArgs_t args, Py_ssize_t i)
Definition CPyCppyy.h:331
_object PyObject
virtual PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr)
bool Initialize(CallContext *ctxt=nullptr)
bool ConvertAndSetArgs(CPyCppyy_PyArgs_t, size_t nargsf, CallContext *ctxt=nullptr)
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
Cppyy::TCppScope_t GetScope()
Definition CPPMethod.h:87
bool CPPInstance_Check(T *object)