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(),
121 TClass::GetClass( Cppyy::GetFinalName( self->ObjectIsA() ).c_str() ) ) != 1 ) {
122 PyErr_Format( PyExc_IOError,
123 "could not stream object of type %s", Cppyy::GetFinalName( self->ObjectIsA() ).c_str() );
134 PyTuple_SET_ITEM( res2, 1,
PyBytes_FromString( Cppyy::GetFinalName( self->ObjectIsA() ).c_str() ) );
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" },
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
390 PyTypeObject ObjectProxy_Type = {
392 (
char*)
"ROOT.ObjectProxy",
395 (destructor)op_dealloc,
404 PyBaseObject_Type.tp_hash,
411 Py_TPFLAGS_BASETYPE |
413 Py_TPFLAGS_CHECKTYPES,
414 (
char*)
"PyROOT object proxy (internal)",
417 (richcmpfunc)op_richcompare,
439 #
if PY_VERSION_HEX >= 0x02030000
442 #
if PY_VERSION_HEX >= 0x02060000
445 #
if PY_VERSION_HEX >= 0x03040000
#define PyBytes_FromString
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
#define PyROOT_PyUnicode_GET_SIZE
Cppyy::TCppType_t fSmartPtrType
R__EXTERN PyObject * gDiv
std::string GetFinalName(TCppType_t type)
R__EXTERN PyObject * gDeref
#define PyVarObject_HEAD_INIT(type, size)
R__EXTERN PyObject * gAdd
#define PYROOT_STUB(name, op, pystring)
#define PyROOT_PyUnicode_FromFormat
R__EXTERN PyObject * gRootModule
#define PyROOT_PyUnicode_Type
#define PyROOT_PyUnicode_AsString
void CallDestructor(TCppType_t type, TCppObject_t self)
Cppyy::TCppType_t ObjectIsA() const
PyTypeObject PyRootType_Type
TCppScope_t GetScope(const std::string &scope_name)
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.
void Deallocate(TCppType_t type, TCppObject_t instance)
R__EXTERN PyObject * gSub
PyObject_HEAD void * fObject
void op_dealloc_nofree(ObjectProxy *)
Destroy the held C++ object, if owned; does not deallocate the proxy.
void Destruct(TCppType_t type, TCppObject_t instance)
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)
R__EXTERN PyObject * gMul
#define PyBytes_FromStringAndSize