Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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

namespace  CPyCppyy
 Set of helper functions that are invoked from the pythonizors, on the Python side.
 

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 PyObjectCPyCppyy::op_add_stub (PyObject *left, PyObject *right)
 
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_div_stub (PyObject *left, PyObject *right)
 
static PyObjectCPyCppyy::op_get_smartptr (CPPInstance *self)
 
static PyObjectCPyCppyy::op_getownership (CPPInstance *pyobj, void *)
 
static Py_hash_t CPyCppyy::op_hash (CPPInstance *self)
 
static PyObjectCPyCppyy::op_invert_stub (PyObject *pyobj)
 
static PyObjectCPyCppyy::op_mul_stub (PyObject *left, PyObject *right)
 
static PyObjectCPyCppyy::op_neg_stub (PyObject *pyobj)
 
static CPPInstanceCPyCppyy::op_new (PyTypeObject *subtype, PyObject *, PyObject *)
 
static int CPyCppyy::op_nonzero (CPPInstance *self)
 
static PyObjectCPyCppyy::op_pos_stub (PyObject *pyobj)
 
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)
 
static PyObjectCPyCppyy::op_sub_stub (PyObject *left, PyObject *right)
 

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) \
}
#define Py_TYPE(ob)
Definition CPyCppyy.h:217
_object PyObject
char name[80]
Definition TGX11.cxx:110
bool CPPInstance_Check(T *object)
CPPScope CPPClass
Definition CPPScope.h:63

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) \
}

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;

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; \
}

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.