Logo ROOT  
Reference Guide
CPPInstance.cxx File Reference
#include "CPyCppyy.h"
#include "CPPInstance.h"
#include "CPPScope.h"
#include "CPPOverload.h"
#include "MemoryRegulator.h"
#include "ProxyWrappers.h"
#include "PyStrings.h"
#include "TypeManip.h"
#include "Utility.h"
#include "CPyCppyy/DispatchPtr.h"
#include <algorithm>
#include <sstream>
Include dependency graph for CPPInstance.cxx:

Namespaces

 CPyCppyy
 

Macros

#define CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(name, op, lmeth, rmeth)
 
#define CPYCPPYY_OPERATOR_STUB(name, op, ometh)
 
#define CPYCPPYY_STUB_BODY(name, op)
 
#define CPYCPPYY_UNARY_OPERATOR(name, op, label)
 
#define DATA_CACHE(pyobj)   ((ExtendedData*)((pyobj)->fObject))->fDatamemberCache
 
#define DISPATCHPTR(pyobj)   ((ExtendedData*)((pyobj)->fObject))->fDispatchPtr
 
#define EXT_OBJECT(pyobj)   ((ExtendedData*)((pyobj)->fObject))->fObject
 
#define SMART_CLS(pyobj)   ((ExtendedData*)((pyobj)->fObject))->fSmartClass
 
#define SMART_TYPE(pyobj)   SMART_CLS(pyobj)->fCppType
 

Functions

static Py_hash_t CPyCppyy::CPyCppyy_PyLong_AsHash_t (PyObject *obj)
 
static PyObjectCPyCppyy::eqneq_binop (CPPClass *klass, PyObject *self, PyObject *obj, int op)
 
static int CPyCppyy::op_clear (CPPInstance *pyobj)
 
static void CPyCppyy::op_dealloc (CPPInstance *pyobj)
 
static PyObjectCPyCppyy::op_destruct (CPPInstance *self)
 
static PyObjectCPyCppyy::op_dispatch (PyObject *self, PyObject *args, PyObject *)
 
static PyObjectCPyCppyy::op_get_smartptr (CPPInstance *self)
 
static PyObjectCPyCppyy::op_getownership (CPPInstance *pyobj, void *)
 
static Py_hash_t CPyCppyy::op_hash (CPPInstance *self)
 
static CPPInstance * CPyCppyy::op_new (PyTypeObject *subtype, PyObject *, PyObject *)
 
static int CPyCppyy::op_nonzero (CPPInstance *self)
 
static PyObjectCPyCppyy::op_repr (CPPInstance *self)
 
static PyObjectCPyCppyy::op_richcompare (CPPInstance *self, PyObject *other, int op)
 
static int CPyCppyy::op_setownership (CPPInstance *pyobj, PyObject *value, void *)
 
static PyObjectCPyCppyy::op_str (CPPInstance *self)
 
static PyObjectCPyCppyy::op_str_internal (PyObject *pyobj, PyObject *lshift, bool isBound)
 

Variables

PyTypeObject CPyCppyy::CPPInstance_Type
 
static PyNumberMethods CPyCppyy::op_as_number
 
static PyGetSetDef CPyCppyy::op_getset []
 
static PyMethodDef CPyCppyy::op_methods []
 

Macro Definition Documentation

◆ CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB

#define CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB (   name,
  op,
  lmeth,
  rmeth 
)
Value:
static PyObject* op_##name##_stub(PyObject* left, PyObject* right) \
{ \
/* placeholder to lazily install and forward do '(l/r)meth' if available */ \
CPPClass* klass; PyObject** pmeth; \
PyObject *cppobj, *other; \
if (CPPInstance_Check(left)) { \
klass = (CPPClass*)Py_TYPE(left); \
if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};\
pmeth = &lmeth; cppobj = left; other = right; \
} else if (CPPInstance_Check(right)) { \
klass = (CPPClass*)Py_TYPE(right); \
if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};\
pmeth = &rmeth; cppobj = right; other = left; \
} else { \
PyErr_SetString(PyExc_NotImplementedError, ""); \
return nullptr; \
} \
PyObject*& meth = *pmeth; \
CPYCPPYY_STUB_BODY(name, op) \
}
bool CPPInstance_Check(T *object)
Definition: CPPInstance.h:118
CPPScope CPPClass
Definition: CPPScope.h:63
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
_object PyObject
Definition: PyMethodBase.h:41
char name[80]
Definition: TGX11.cxx:109

Definition at line 639 of file CPPInstance.cxx.

◆ CPYCPPYY_OPERATOR_STUB

#define CPYCPPYY_OPERATOR_STUB (   name,
  op,
  ometh 
)
Value:
static PyObject* op_##name##_stub(PyObject* left, PyObject* right) \
{ \
/* placeholder to lazily install and forward to 'ometh' if available */ \
CPPClass* klass = (CPPClass*)Py_TYPE(left); \
if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{}; \
PyObject*& meth = ometh; \
PyObject *cppobj = left, *other = right; \
CPYCPPYY_STUB_BODY(name, op) \
}
CPPScope CPPClass
Definition: CPPScope.h:63
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
_object PyObject
Definition: PyMethodBase.h:41
char name[80]
Definition: TGX11.cxx:109

Definition at line 628 of file CPPInstance.cxx.

◆ CPYCPPYY_STUB_BODY

#define CPYCPPYY_STUB_BODY (   name,
  op 
)
Value:
if (!meth) { \
PyErr_Clear(); \
PyCallable* pyfunc = Utility::FindBinaryOperator(left, right, #op); \
if (pyfunc) meth = (PyObject*)CPPOverload_New(#name, pyfunc); \
else { \
PyErr_SetString(PyExc_NotImplementedError, ""); \
return nullptr; \
} \
} \
PyObject* res = PyObject_CallFunctionObjArgs(meth, cppobj, other, nullptr);\
if (!res) { \
/* try again, in case there is a better overload out there */ \
PyErr_Clear(); \
PyCallable* pyfunc = Utility::FindBinaryOperator(left, right, #op); \
if (pyfunc) ((CPPOverload*&)meth)->AdoptMethod(pyfunc); \
else { \
PyErr_SetString(PyExc_NotImplementedError, ""); \
return nullptr; \
} \
/* use same overload with newly added function */ \
res = PyObject_CallFunctionObjArgs(meth, cppobj, other, nullptr); \
} \
return res;
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable *> &methods)
Definition: CPPOverload.h:91
_object PyObject
Definition: PyMethodBase.h:41
PyCallable * FindBinaryOperator(PyObject *left, PyObject *right, const char *op, Cppyy::TCppScope_t scope=0)
Definition: Utility.cxx:280
char name[80]
Definition: TGX11.cxx:109

Definition at line 602 of file CPPInstance.cxx.

◆ CPYCPPYY_UNARY_OPERATOR

#define CPYCPPYY_UNARY_OPERATOR (   name,
  op,
  label 
)
Value:
static PyObject* op_##name##_stub(PyObject* pyobj) \
{ \
/* placeholder to lazily install unary operators */ \
PyCallable* pyfunc = Utility::FindUnaryOperator((PyObject*)Py_TYPE(pyobj), #op);\
if (pyfunc && Utility::AddToClass((PyObject*)Py_TYPE(pyobj), #label, pyfunc))\
return PyObject_CallMethod(pyobj, (char*)#label, nullptr); \
PyErr_SetString(PyExc_NotImplementedError, ""); \
return nullptr; \
}
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
_object PyObject
Definition: PyMethodBase.h:41
PyCallable * FindUnaryOperator(PyObject *pyclass, const char *op)
Definition: Utility.cxx:266
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
Definition: Utility.cxx:169
char name[80]
Definition: TGX11.cxx:109

Definition at line 661 of file CPPInstance.cxx.

◆ DATA_CACHE

#define DATA_CACHE (   pyobj)    ((ExtendedData*)((pyobj)->fObject))->fDatamemberCache

Definition at line 77 of file CPPInstance.cxx.

◆ DISPATCHPTR

#define DISPATCHPTR (   pyobj)    ((ExtendedData*)((pyobj)->fObject))->fDispatchPtr

Definition at line 76 of file CPPInstance.cxx.

◆ EXT_OBJECT

#define EXT_OBJECT (   pyobj)    ((ExtendedData*)((pyobj)->fObject))->fObject

Definition at line 73 of file CPPInstance.cxx.

◆ SMART_CLS

#define SMART_CLS (   pyobj)    ((ExtendedData*)((pyobj)->fObject))->fSmartClass

Definition at line 74 of file CPPInstance.cxx.

◆ SMART_TYPE

#define SMART_TYPE (   pyobj)    SMART_CLS(pyobj)->fCppType

Definition at line 75 of file CPPInstance.cxx.