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
 

Macros

#define ARRAY_SIZE(pyobj)   ((ExtendedData*)((pyobj)->fObject))->fArraySize
 
#define CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(name, op, lmeth, rmeth)
 
#define CPYCPPYY_OPERATOR_STUB(name, op, ometh)
 
#define CPYCPPYY_ORDERED_OPERATOR_STUB(op, ometh, label)
 
#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 void * CPyCppyy::cast_actual (void *obj)
 
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_item (CPPInstance *self, Py_ssize_t idx)
 
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_reshape (CPPInstance *self, PyObject *shape)
 
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)
 
static int CPyCppyy::op_traverse (CPPInstance *, visitproc, void *)
 
static bool CPyCppyy::ScopeFlagCheck (CPPInstance *self, CPPScope::EFlags flag)
 
static void CPyCppyy::ScopeFlagSet (CPPInstance *self, CPPScope::EFlags flag)
 

Variables

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

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   pyobj)    ((ExtendedData*)((pyobj)->fObject))->fArraySize

Definition at line 84 of file CPPInstance.cxx.

◆ 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:196
_object PyObject
char name[80]
Definition TGX11.cxx:110
bool CPPInstance_Check(T *object)
CPPScope CPPClass
Definition CPPScope.h:68

Definition at line 935 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 924 of file CPPInstance.cxx.

◆ CPYCPPYY_ORDERED_OPERATOR_STUB

#define CPYCPPYY_ORDERED_OPERATOR_STUB (   op,
  ometh,
  label 
)
Value:
if (!ometh) { \
PyCallable* pyfunc = Utility::FindBinaryOperator((PyObject*)self, other, #op);\
if (pyfunc) \
ometh = (PyObject*)CPPOverload_New(#label, pyfunc); \
} \
meth = ometh;

Definition at line 535 of file CPPInstance.cxx.

◆ CPYCPPYY_STUB_BODY

#define CPYCPPYY_STUB_BODY (   name,
  op 
)
Value:
bool previously_resolved_overload = (bool)meth; \
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 && previously_resolved_overload) { \
/* try again, in case (left, right) are different types than before */ \
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 897 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 957 of file CPPInstance.cxx.

◆ DATA_CACHE

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

Definition at line 80 of file CPPInstance.cxx.

◆ DISPATCHPTR

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

Definition at line 83 of file CPPInstance.cxx.

◆ EXT_OBJECT

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

Definition at line 79 of file CPPInstance.cxx.

◆ SMART_CLS

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

Definition at line 81 of file CPPInstance.cxx.

◆ SMART_TYPE

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

Definition at line 82 of file CPPInstance.cxx.