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*)
"__smartptr__", (PyCFunction)op_get_smart_ptr, METH_NOARGS, (
char*)
"get associated smart pointer, if any" },
193 { (
char*)NULL, NULL, 0, NULL }
201 ObjectProxy* pyobj = (ObjectProxy*)subtype->tp_alloc( subtype, 0 );
202 pyobj->fObject = NULL;
211 void op_dealloc( ObjectProxy* pyobj )
220 PyObject* op_richcompare( ObjectProxy* self, ObjectProxy* other,
int op )
222 if ( op != Py_EQ && op != Py_NE ) {
223 Py_INCREF( Py_NotImplemented );
224 return Py_NotImplemented;
230 if ( (
PyObject*)other == Py_None && ! self->fObject )
235 else if (
Py_TYPE(self) ==
Py_TYPE(other) && self->GetObject() == other->GetObject() )
238 if ( ( op == Py_EQ && bIsEq ) || ( op == Py_NE && ! bIsEq ) ) {
239 Py_INCREF( Py_True );
243 Py_INCREF( Py_False );
251 PyObject* op_repr( ObjectProxy* pyobj )
256 clName.append(
"*" );
258 std::string smartPtrName;
261 smartPtrName = smartPtrType ?
Cppyy::GetFinalName( smartPtrType ) :
"unknown smart pointer";
267 const_cast< char*
>(
"GetName" ),
const_cast< char*
>(
"" ) );
291 clName.c_str(), pyobj->GetObject(), smartPtrName.c_str(), pyobj->fSmartPtr );
294 clName.c_str(), pyobj->GetObject() );
300#define PYROOT_STUB( name, op, pystring ) \
301 PyObject* op_##name##_stub( PyObject* left, PyObject* right ) \
303 if ( ! ObjectProxy_Check( left ) ) { \
304 if ( ObjectProxy_Check( right ) ) { \
305 std::swap( left, right ); \
307 Py_INCREF( Py_NotImplemented ); \
308 return Py_NotImplemented; \
312 if ( ! Utility::AddBinaryOperator( \
313 left, right, #op, "__"#name"__", "__r"#name"__" ) ) { \
314 Py_INCREF( Py_NotImplemented ); \
315 return Py_NotImplemented; \
319 return PyObject_CallMethodObjArgs( left, pystring, right, NULL ); \
329 PyNumberMethods op_as_number = {
330 (binaryfunc)op_add_stub,
331 (binaryfunc)op_sub_stub,
332 (binaryfunc)op_mul_stub,
333#
if PY_VERSION_HEX < 0x03000000
334 (binaryfunc)op_div_stub,
349#if PY_VERSION_HEX < 0x03000000
355#if PY_VERSION_HEX < 0x03000000
362#if PY_VERSION_HEX < 0x03000000
372#if PY_VERSION_HEX >= 0x02020000
374#if PY_VERSION_HEX < 0x03000000
377 , (binaryfunc)op_div_stub
382#
if PY_VERSION_HEX >= 0x02050000
385#
if PY_VERSION_HEX >= 0x03050000
393#if !defined(_MSC_VER)
394#pragma GCC diagnostic push
395#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
401 (
char*)
"ROOT.ObjectProxy",
404 (destructor)op_dealloc,
414 PyBaseObject_Type.tp_hash,
421 Py_TPFLAGS_BASETYPE |
423 Py_TPFLAGS_CHECKTYPES,
424 (
char*)
"PyROOT object proxy (internal)",
427 (richcmpfunc)op_richcompare,
449#
if PY_VERSION_HEX >= 0x02030000
452#
if PY_VERSION_HEX >= 0x02060000
455#
if PY_VERSION_HEX >= 0x03040000
458#
if PY_VERSION_HEX >= 0x03080000
460#
if PY_VERSION_HEX < 0x03090000
466#if !defined(_MSC_VER)
467#pragma GCC diagnostic pop
#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