48 if ( pyobj->
fFlags & ObjectProxy::kIsValue ) {
49 if ( ! (pyobj->
fFlags & ObjectProxy::kIsSmartPtr) ) {
57 else if ( pyobj->
fObject && ( pyobj->
fFlags & ObjectProxy::kIsOwner ) ) {
58 if ( ! (pyobj->
fFlags & ObjectProxy::kIsSmartPtr) ) {
75 PyObject* op_nonzero( ObjectProxy* self )
78 PyObject* result = self->GetObject() ? Py_True : Py_False;
84 PyObject* op_destruct( ObjectProxy* self )
96 PyObject* op_reduce( ObjectProxy* self )
105 static PyObject* s_expand = PyDict_GetItemString(
106 PyModule_GetDict(
gRootModule ),
const_cast< char*
>(
"_ObjectProxy__expand__" ) );
113 if ( s_bfClass == self->ObjectIsA() ) {
120 if ( s_buff.WriteObjectAny( self->GetObject(),
122 PyErr_Format( PyExc_IOError,
136 PyObject* result = PyTuple_New( 2 );
137 Py_INCREF( s_expand );
138 PyTuple_SET_ITEM( result, 0, s_expand );
139 PyTuple_SET_ITEM( result, 1, res2 );
150 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!:__dispatch__" ),
155 PyObject* pymeth = PyObject_GetAttr( self, mname );
160 PyObject* pydisp = PyObject_GetAttrString( pymeth,
const_cast<char*
>(
"disp" ) );
167 PyObject* oload = PyObject_CallFunctionObjArgs( pydisp, sigarg, NULL );
174 PyObject* op_get_smart_ptr( ObjectProxy* self )
185 PyMethodDef op_methods[] = {
186 { (
char*)
"__nonzero__", (PyCFunction)op_nonzero, METH_NOARGS, NULL },
187 { (
char*)
"__bool__", (PyCFunction)op_nonzero, METH_NOARGS, NULL },
188 { (
char*)
"__destruct__", (PyCFunction)op_destruct, METH_NOARGS, NULL },
189 { (
char*)
"__reduce__", (PyCFunction)op_reduce, METH_NOARGS, NULL },
190 { (
char*)
"__dispatch__", (PyCFunction)op_dispatch, METH_VARARGS, (
char*)
"dispatch to selected overload" },
191 { (
char*)
"_get_smart_ptr", (PyCFunction)op_get_smart_ptr, METH_NOARGS, (
char*)
"get associated smart pointer, if any" },
192 { (
char*)NULL, NULL, 0, NULL }
200 ObjectProxy* pyobj = (ObjectProxy*)subtype->tp_alloc( subtype, 0 );
201 pyobj->fObject = NULL;
210 void op_dealloc( ObjectProxy* pyobj )
219 PyObject* op_richcompare( ObjectProxy* self, ObjectProxy* other,
int op )
221 if ( op != Py_EQ && op != Py_NE ) {
222 Py_INCREF( Py_NotImplemented );
223 return Py_NotImplemented;
229 if ( (
PyObject*)other == Py_None && ! self->fObject )
234 else if (
Py_TYPE(self) ==
Py_TYPE(other) && self->GetObject() == other->GetObject() )
237 if ( ( op == Py_EQ && bIsEq ) || ( op == Py_NE && ! bIsEq ) ) {
238 Py_INCREF( Py_True );
242 Py_INCREF( Py_False );
250 PyObject* op_repr( ObjectProxy* pyobj )
255 clName.append(
"*" );
257 std::string smartPtrName;
260 smartPtrName = smartPtrType ?
Cppyy::GetFinalName( smartPtrType ) :
"unknown smart pointer";
266 const_cast< char*
>(
"GetName" ),
const_cast< char*
>(
"" ) );
290 clName.c_str(), pyobj->GetObject(), smartPtrName.c_str(), pyobj->fSmartPtr );
293 clName.c_str(), pyobj->GetObject() );
299#define PYROOT_STUB( name, op, pystring ) \
300 PyObject* op_##name##_stub( PyObject* left, PyObject* right ) \
302 if ( ! ObjectProxy_Check( left ) ) { \
303 if ( ObjectProxy_Check( right ) ) { \
304 std::swap( left, right ); \
306 Py_INCREF( Py_NotImplemented ); \
307 return Py_NotImplemented; \
311 if ( ! Utility::AddBinaryOperator( \
312 left, right, #op, "__"#name"__", "__r"#name"__" ) ) { \
313 Py_INCREF( Py_NotImplemented ); \
314 return Py_NotImplemented; \
318 return PyObject_CallMethodObjArgs( left, pystring, right, NULL ); \
328 PyNumberMethods op_as_number = {
329 (binaryfunc)op_add_stub,
330 (binaryfunc)op_sub_stub,
331 (binaryfunc)op_mul_stub,
332#
if PY_VERSION_HEX < 0x03000000
333 (binaryfunc)op_div_stub,
348#if PY_VERSION_HEX < 0x03000000
354#if PY_VERSION_HEX < 0x03000000
361#if PY_VERSION_HEX < 0x03000000
371#if PY_VERSION_HEX >= 0x02020000
373#if PY_VERSION_HEX < 0x03000000
376 , (binaryfunc)op_div_stub
381#
if PY_VERSION_HEX >= 0x02050000
384#
if PY_VERSION_HEX >= 0x03050000
396 (
char*)
"ROOT.ObjectProxy",
399 (destructor)op_dealloc,
408 PyBaseObject_Type.tp_hash,
415 Py_TPFLAGS_BASETYPE |
417 Py_TPFLAGS_CHECKTYPES,
418 (
char*)
"PyROOT object proxy (internal)",
421 (richcmpfunc)op_richcompare,
443#
if PY_VERSION_HEX >= 0x02030000
446#
if PY_VERSION_HEX >= 0x02060000
449#
if PY_VERSION_HEX >= 0x03040000
#define PYROOT_STUB(name, op, pystring)
#define PyBytes_FromString
#define PyROOT_PyUnicode_AsString
#define PyBytes_FromStringAndSize
#define PyROOT_PyUnicode_GET_SIZE
#define PyROOT_PyUnicode_FromFormat
#define PyROOT_PyUnicode_Type
#define PyVarObject_HEAD_INIT(type, size)
Cppyy::TCppType_t ObjectIsA() const
PyObject_HEAD void * fObject
Cppyy::TCppType_t fSmartPtrType
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
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.
@ kInvalidObject
if object ctor succeeded but object should not be used
void CallDestructor(TCppType_t type, TCppObject_t self)
void Destruct(TCppType_t type, TCppObject_t instance)
void Deallocate(TCppType_t type, TCppObject_t instance)
TCppScope_t GetScope(const std::string &scope_name)
std::string GetFinalName(TCppType_t type)
R__EXTERN PyObject * gAdd
R__EXTERN PyObject * gMul
R__EXTERN PyObject * gDiv
R__EXTERN PyObject * gSub
R__EXTERN PyObject * gDeref
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, Bool_t isRef=kFALSE)
if the object is a null pointer, return a typed one (as needed for overloading)
PyTypeObject PyRootType_Type
PyTypeObject ObjectProxy_Type
void op_dealloc_nofree(ObjectProxy *)
Destroy the held C++ object, if owned; does not deallocate the proxy.
R__EXTERN PyObject * gRootModule