Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPInstance.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CPPInstance.h"
4#include "CPPScope.h"
5#include "CPPOverload.h"
6#include "MemoryRegulator.h"
7#include "ProxyWrappers.h"
8#include "PyStrings.h"
9#include "TypeManip.h"
10#include "Utility.h"
11
13
14// Standard
15#include <algorithm>
16#include <sstream>
17
18
19//- data _____________________________________________________________________
20namespace CPyCppyy {
22}
23
24//______________________________________________________________________________
25// Python-side proxy objects
26// =========================
27//
28// C++ objects are represented in Python by CPPInstances, which encapsulate
29// them using either a pointer (normal), pointer-to-pointer (kIsReference set),
30// or as an owned value (kIsValue set). Objects held as reference are never
31// owned, otherwise the object is owned if kIsOwner is set.
32//
33// In addition to encapsulation, CPPInstance offers rudimentary comparison
34// operators (based on pointer value and class comparisons); stubs (with lazy
35// lookups) for numeric operators; and a representation that prints the C++
36// pointer values, rather than the PyObject* ones as is the default.
37//
38// Smart pointers have the underlying type as the Python type, but store the
39// pointer to the smart pointer. They carry a pointer to the Python-sode smart
40// class for dereferencing to get to the actual instance pointer.
41
42
43//- private helpers ----------------------------------------------------------
44namespace {
45
46// Several specific use cases require extra data in a CPPInstance, but can not
47// be a new type. E.g. cross-inheritance derived types are by definition added
48// a posterio, and caching of datamembers is up to the datamember, not the
49// instance type. To not have normal use of CPPInstance take extra memory, this
50// extended data can slot in place of fObject for those use cases.
51
52struct ExtendedData {
53 ExtendedData() : fObject(nullptr), fSmartClass(nullptr), fDispatchPtr(nullptr), fArraySize(0) {}
54 ~ExtendedData() {
55 for (auto& pc : fDatamemberCache)
56 Py_XDECREF(pc.second);
57 fDatamemberCache.clear();
58 }
59
60// the original object reference it replaces (Note: has to be first data member, see usage
61// in GetObjectRaw(), e.g. for ptr-ptr passing)
62 void* fObject;
63
64// for caching expensive-to-create data member representations
65 CPyCppyy::CI_DatamemberCache_t fDatamemberCache;
66
67// for smart pointer types
68 CPyCppyy::CPPSmartClass* fSmartClass;
69
70// for back-referencing from Python-derived instances
71 CPyCppyy::DispatchPtr* fDispatchPtr;
72
73// for representing T* as a low-level array
74 Py_ssize_t fArraySize;
75};
76
77} // unnamed namespace
78
79#define EXT_OBJECT(pyobj) ((ExtendedData*)((pyobj)->fObject))->fObject
80#define DATA_CACHE(pyobj) ((ExtendedData*)((pyobj)->fObject))->fDatamemberCache
81#define SMART_CLS(pyobj) ((ExtendedData*)((pyobj)->fObject))->fSmartClass
82#define SMART_TYPE(pyobj) SMART_CLS(pyobj)->fCppType
83#define DISPATCHPTR(pyobj) ((ExtendedData*)((pyobj)->fObject))->fDispatchPtr
84#define ARRAY_SIZE(pyobj) ((ExtendedData*)((pyobj)->fObject))->fArraySize
85
87 if (fFlags & kIsExtended)
88 return;
89 void* obj = fObject;
90 fObject = (void*)new ExtendedData{};
91 EXT_OBJECT(this) = obj;
93}
94
96{
97 if (IsSmart()) {
98 // We get the raw pointer from the smart pointer each time, in case it has
99 // changed or has been freed.
100 return Cppyy::CallR(SMART_CLS(this)->fDereferencer, EXT_OBJECT(this), 0, nullptr);
101 }
102 return EXT_OBJECT(this);
103}
104
105
106//- public methods -----------------------------------------------------------
108{
109// create a fresh instance; args and kwds are not used by op_new (see below)
110 PyObject* self = (PyObject*)this;
111 if (!target) target = Py_TYPE(self);
112 PyObject* newinst = target->tp_new(target, nullptr, nullptr);
113
114// set the C++ instance as given
115 ((CPPInstance*)newinst)->fObject = cppinst;
116
117// look for user-provided __cpp_copy__ (not reusing __copy__ b/c of differences
118// in semantics: need to pass in the new instance) ...
119 PyObject* cpy = PyObject_GetAttrString(self, (char*)"__cpp_copy__");
120 if (cpy && PyCallable_Check(cpy)) {
121 PyObject* args = PyTuple_New(1);
122 Py_INCREF(newinst);
123 PyTuple_SET_ITEM(args, 0, newinst);
124 PyObject* res = PyObject_CallObject(cpy, args);
125 Py_DECREF(args);
126 Py_DECREF(cpy);
127 if (res) {
128 Py_DECREF(res);
129 return (CPPInstance*)newinst;
130 }
131
132 // error already set, but need to return nullptr
133 Py_DECREF(newinst);
134 return nullptr;
135 } else if (cpy)
136 Py_DECREF(cpy);
137 else
138 PyErr_Clear();
139
140// ... otherwise, shallow copy any Python-side dictionary items
141 PyObject* selfdct = PyObject_GetAttr(self, PyStrings::gDict);
142 PyObject* newdct = PyObject_GetAttr(newinst, PyStrings::gDict);
143 bool bMergeOk = PyDict_Merge(newdct, selfdct, 1) == 0;
144 Py_DECREF(newdct);
145 Py_DECREF(selfdct);
146
147 if (!bMergeOk) {
148 // presume error already set
149 Py_DECREF(newinst);
150 return nullptr;
151 }
152
154 return (CPPInstance*)newinst;
155}
156
157
158//----------------------------------------------------------------------------
160{
161 fFlags |= kIsOwner;
162 if ((fFlags & kIsExtended) && DISPATCHPTR(this))
163 DISPATCHPTR(this)->PythonOwns();
164}
165
166//----------------------------------------------------------------------------
168{
169 fFlags &= ~kIsOwner;
170 if ((fFlags & kIsExtended) && DISPATCHPTR(this))
171 DISPATCHPTR(this)->CppOwns();
172}
173
174//----------------------------------------------------------------------------
176{
177 CreateExtension();
178 Py_INCREF(smart_type);
179 SMART_CLS(this) = (CPPSmartClass*)smart_type;
180 fFlags |= kIsSmartPtr;
181}
182
183//----------------------------------------------------------------------------
185{
186 if (!IsSmart()) return (Cppyy::TCppType_t)0;
187 return SMART_TYPE(this);
188}
189
190//----------------------------------------------------------------------------
192{
193// Return the cache for expensive data objects (and make extended as necessary)
194 CreateExtension();
195 return DATA_CACHE(this);
196}
197
198//----------------------------------------------------------------------------
200{
201// Set up the dispatch pointer for memory management
202 CreateExtension();
203 DISPATCHPTR(this) = (DispatchPtr*)ptr;
204}
205
206
207//----------------------------------------------------------------------------
209// Destroy the held C++ object, if owned; does not deallocate the proxy.
210
211 Cppyy::TCppType_t klass = pyobj->ObjectIsA(false /* check_smart */);
212 void*& cppobj = pyobj->GetObjectRaw();
213
216
217 if (cppobj && (pyobj->fFlags & CPPInstance::kIsOwner)) {
218 if (pyobj->fFlags & CPPInstance::kIsValue) {
219 Cppyy::CallDestructor(klass, cppobj);
220 Cppyy::Deallocate(klass, cppobj);
221 } else
222 Cppyy::Destruct(klass, cppobj);
223 }
224 cppobj = nullptr;
225
226 if (pyobj->IsExtended()) delete (ExtendedData*)pyobj->fObject;
228}
229
230
231namespace CPyCppyy {
232
233//= CPyCppyy object proxy null-ness checking =================================
234static int op_nonzero(CPPInstance* self)
235{
236// Null of the proxy is determined by null-ness of the held C++ object.
237 if (!self->GetObject())
238 return 0;
239
240// If the object is valid, then the normal Python behavior is to allow __len__
241// to determine truth. However, that function is defined in typeobject.c and only
242// installed if tp_as_number exists w/o the nb_nonzero/nb_bool slot filled in, so
243// it can not be called directly. Instead, since we're only ever dealing with
244// CPPInstance derived objects, ignore length from sequence or mapping and call
245// the __len__ method, if any, directly.
246
247 PyObject* pylen = PyObject_CallMethodObjArgs((PyObject*)self, PyStrings::gLen, NULL);
248 if (!pylen) {
249 PyErr_Clear();
250 return 1; // since it's still a valid object
251 }
252
253 int result = PyObject_IsTrue(pylen);
254 Py_DECREF(pylen);
255 return result;
256}
257
258//= CPyCppyy object explicit destruction =====================================
260{
261// User access to force deletion of the object. Needed in case of a true
262// garbage collector (like in PyPy), to allow the user control over when
263// the C++ destructor is called. This method requires that the C++ object
264// is owned (no-op otherwise).
265 op_dealloc_nofree(self);
267}
268
269//= CPyCppyy object dispatch support =========================================
270static PyObject* op_dispatch(PyObject* self, PyObject* args, PyObject* /* kdws */)
271{
272// User-side __dispatch__ method to allow selection of a specific overloaded
273// method. The actual selection is in the __overload__() method of CPPOverload.
274 PyObject *mname = nullptr, *sigarg = nullptr;
275 if (!PyArg_ParseTuple(args, const_cast<char*>("O!O!:__dispatch__"),
276 &CPyCppyy_PyText_Type, &mname, &CPyCppyy_PyText_Type, &sigarg))
277 return nullptr;
278
279// get the named overload
280 PyObject* pymeth = PyObject_GetAttr(self, mname);
281 if (!pymeth)
282 return nullptr;
283
284// get the '__overload__' method to allow overload selection
285 PyObject* pydisp = PyObject_GetAttrString(pymeth, const_cast<char*>("__overload__"));
286 if (!pydisp) {
287 Py_DECREF(pymeth);
288 return nullptr;
289 }
290
291// finally, call dispatch to get the specific overload
292 PyObject* oload = PyObject_CallFunctionObjArgs(pydisp, sigarg, nullptr);
293 Py_DECREF(pydisp);
294 Py_DECREF(pymeth);
295 return oload;
296}
297
298//= CPyCppyy smart pointer support ===========================================
300{
301 if (!self->IsSmart()) {
302 // TODO: more likely should raise
304 }
305
307}
308
309//= pointer-as-array support for legacy C code ===============================
311{
312 CreateExtension();
313 fFlags |= kIsArray;
314 ARRAY_SIZE(this) = sz;
315}
316
318 if (!(fFlags & kIsArray))
319 return -1;
320 return (Py_ssize_t)ARRAY_SIZE(this);
321}
322
324{
325// Allow the user to fix up the actual (type-strided) size of the buffer.
326 if (!PyTuple_Check(shape) || PyTuple_GET_SIZE(shape) != 1) {
327 PyErr_SetString(PyExc_TypeError, "tuple object of size 1 expected");
328 return nullptr;
329 }
330
331 long sz = PyLong_AsLong(PyTuple_GET_ITEM(shape, 0));
332 if (sz <= 0) {
333 PyErr_SetString(PyExc_ValueError, "array length must be positive");
334 return nullptr;
335 }
336
337 self->CastToArray(sz);
338
340}
341
343{
344// In C, it is common to represent an array of structs as a pointer to the first
345// object in the array. If the caller indexes a pointer to an object that does not
346// define indexing, then highly likely such C-style indexing is the goal. Just
347// like C, this is potentially unsafe, so caveat emptor.
348
350 PyErr_Format(PyExc_TypeError, "%s object does not support indexing", Py_TYPE(self)->tp_name);
351 return nullptr;
352 }
353
354 Py_ssize_t idx = PyInt_AsSsize_t(pyidx);
355 if (idx == (Py_ssize_t)-1 && PyErr_Occurred())
356 return nullptr;
357
358 if (idx < 0) {
359 // this is debatable, and probably should not care, but the use case is pretty
360 // circumscribed anyway, so might as well keep the functionality simple
361 PyErr_SetString(PyExc_IndexError, "negative indices not supported for array of structs");
362 return nullptr;
363 }
364
365 if (self->fFlags & CPPInstance::kIsArray) {
366 Py_ssize_t maxidx = ARRAY_SIZE(self);
367 if (0 <= maxidx && maxidx <= idx) {
368 PyErr_SetString(PyExc_IndexError, "index out of range");
369 return nullptr;
370 }
371 }
372
373 unsigned flags = 0; size_t sz = sizeof(void*);
374 if (self->fFlags & CPPInstance::kIsPtrPtr) {
376 } else {
377 sz = Cppyy::SizeOf(((CPPClass*)Py_TYPE(self))->fCppType);
378 }
379
380 uintptr_t address = (uintptr_t)(flags ? self->GetObjectRaw() : self->GetObject());
381 void* indexed_obj = (void*)(address+(uintptr_t)(idx*sz));
382
383 return BindCppObjectNoCast(indexed_obj, ((CPPClass*)Py_TYPE(self))->fCppType, flags);
384}
385
386//----------------------------------------------------------------------------
387static PyMethodDef op_methods[] = {
388 {(char*)"__destruct__", (PyCFunction)op_destruct, METH_NOARGS,
389 (char*)"call the C++ destructor"},
390 {(char*)"__dispatch__", (PyCFunction)op_dispatch, METH_VARARGS,
391 (char*)"dispatch to selected overload"},
392 {(char*)"__smartptr__", (PyCFunction)op_get_smartptr, METH_NOARGS,
393 (char*)"get associated smart pointer, if any"},
394 {(char*)"__getitem__", (PyCFunction)op_getitem, METH_O,
395 (char*)"pointer dereferencing"},
396 {(char*)"__reshape__", (PyCFunction)op_reshape, METH_O,
397 (char*)"cast pointer to 1D array type"},
398 {(char*)nullptr, nullptr, 0, nullptr}
399};
400
401
402//= CPyCppyy object proxy construction/destruction ===========================
403static CPPInstance* op_new(PyTypeObject* subtype, PyObject*, PyObject*)
404{
405// Create a new object proxy (holder only).
406 CPPInstance* pyobj = (CPPInstance*)subtype->tp_alloc(subtype, 0);
407 pyobj->fObject = nullptr;
409
410 return pyobj;
411}
412
413//----------------------------------------------------------------------------
414static void op_dealloc(CPPInstance* pyobj)
415{
416// Remove (Python-side) memory held by the object proxy.
417 PyObject_GC_UnTrack((PyObject*)pyobj);
418 op_dealloc_nofree(pyobj);
419 PyObject_GC_Del((PyObject*)pyobj);
420}
421
422//----------------------------------------------------------------------------
423static int op_clear(CPPInstance* pyobj)
424{
425// Garbage collector clear of held python member objects; this is a good time
426// to safely remove this object from the memory regulator.
429
430 return 0;
431}
432
433//----------------------------------------------------------------------------
434static inline PyObject* eqneq_binop(CPPClass* klass, PyObject* self, PyObject* obj, int op)
435{
436 using namespace Utility;
437
438// special case for C++11 style nullptr
439 if (obj == gNullPtrObject) {
440 void* rawcpp = ((CPPInstance*)self)->GetObjectRaw();
441 switch (op) {
442 case Py_EQ:
443 if (rawcpp == nullptr) Py_RETURN_TRUE;
445 case Py_NE:
446 if (rawcpp != nullptr) Py_RETURN_TRUE;
448 default:
449 return nullptr; // not implemented
450 }
451 }
452
453 if (!klass->fOperators)
454 klass->fOperators = new PyOperators{};
455
456 bool flipit = false;
457 PyObject* binop = op == Py_EQ ? klass->fOperators->fEq : klass->fOperators->fNe;
458 if (!binop) {
459 const char* cppop = op == Py_EQ ? "==" : "!=";
460 PyCallable* pyfunc = FindBinaryOperator(self, obj, cppop);
461 if (pyfunc) binop = (PyObject*)CPPOverload_New(cppop, pyfunc);
462 else {
463 Py_INCREF(Py_None);
464 binop = Py_None;
465 }
466 // sets the operator to Py_None if not found, indicating that search was done
467 if (op == Py_EQ) klass->fOperators->fEq = binop;
468 else klass->fOperators->fNe = binop;
469 }
470
471 if (binop == Py_None) { // can try !== or !!= as alternatives
472 binop = op == Py_EQ ? klass->fOperators->fNe : klass->fOperators->fEq;
473 if (binop && binop != Py_None) flipit = true;
474 }
475
476 if (!binop || binop == Py_None) return nullptr;
477
478 PyObject* args = PyTuple_New(1);
479 Py_INCREF(obj); PyTuple_SET_ITEM(args, 0, obj);
480// since this overload is "ours", don't have to worry about rebinding
481 ((CPPOverload*)binop)->fSelf = (CPPInstance*)self;
482 PyObject* result = CPPOverload_Type.tp_call(binop, args, nullptr);
483 ((CPPOverload*)binop)->fSelf = nullptr;
484 Py_DECREF(args);
485
486 if (!result) {
487 PyErr_Clear();
488 return nullptr;
489 }
490
491// successful result, but may need to reverse the outcome
492 if (!flipit) return result;
493
494 int istrue = PyObject_IsTrue(result);
495 Py_DECREF(result);
496 if (istrue) {
498 }
500}
501
502static inline void* cast_actual(void* obj) {
503 void* address = ((CPPInstance*)obj)->GetObject();
505 return address;
506
507 Cppyy::TCppType_t klass = ((CPPClass*)Py_TYPE((PyObject*)obj))->fCppType;
508 Cppyy::TCppType_t clActual = Cppyy::GetActualClass(klass, address);
509 if (clActual && clActual != klass) {
510 intptr_t offset = Cppyy::GetBaseOffset(
511 clActual, klass, address, -1 /* down-cast */, true /* report errors */);
512 if (offset != -1) address = (void*)((intptr_t)address + offset);
513 }
514
515 return address;
516}
517
518
519#define CPYCPPYY_ORDERED_OPERATOR_STUB(op, ometh, label) \
520 if (!ometh) { \
521 PyCallable* pyfunc = Utility::FindBinaryOperator((PyObject*)self, other, #op);\
522 if (pyfunc) \
523 ometh = (PyObject*)CPPOverload_New(#label, pyfunc); \
524 } \
525 meth = ometh;
526
527static PyObject* op_richcompare(CPPInstance* self, PyObject* other, int op)
528{
529// Rich set of comparison objects; currently supported:
530// == : Py_EQ
531// != : Py_NE
532//
533// < : Py_LT
534// <= : Py_LE
535// > : Py_GT
536// >= : Py_GE
537//
538
539// associative comparison operators
540 if (op == Py_EQ || op == Py_NE) {
541 // special case for None to compare True to a null-pointer
542 if ((PyObject*)other == Py_None && !self->fObject) {
543 if (op == Py_EQ) { Py_RETURN_TRUE; }
545 }
546
547 // use C++-side operators if available
548 PyObject* result = eqneq_binop((CPPClass*)Py_TYPE(self), (PyObject*)self, other, op);
549 if (!result && CPPInstance_Check(other))
550 result = eqneq_binop((CPPClass*)Py_TYPE(other), other, (PyObject*)self, op);
551 if (result) return result;
552
553 // default behavior: type + held pointer value defines identity; if both are
554 // CPPInstance objects, perform an additional autocast if need be
555 bool bIsEq = false;
556
557 if ((Py_TYPE(self) == Py_TYPE(other) && \
558 self->GetObject() == ((CPPInstance*)other)->GetObject())) {
559 // direct match
560 bIsEq = true;
561 } else if (CPPInstance_Check(other)) {
562 // try auto-cast match
563 void* addr1 = cast_actual(self);
564 void* addr2 = cast_actual(other);
565 bIsEq = addr1 && addr2 && (addr1 == addr2);
566 }
567
568 if ((op == Py_EQ && bIsEq) || (op == Py_NE && !bIsEq))
570
572 }
573
574// ordered comparison operators
575 else if (op == Py_LT || op == Py_LE || op == Py_GT || op == Py_GE) {
576 CPPClass* klass = (CPPClass*)Py_TYPE(self);
577 if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};
578 PyObject* meth = nullptr;
579
580 switch (op) {
581 case Py_LT:
583 break;
584 case Py_LE:
586 break;
587 case Py_GT:
589 break;
590 case Py_GE:
592 break;
593 }
594
595 if (!meth) {
596 PyErr_SetString(PyExc_NotImplementedError, "");
597 return nullptr;
598 }
599
600 return PyObject_CallFunctionObjArgs(meth, (PyObject*)self, other, nullptr);
601 }
602
603 Py_INCREF(Py_NotImplemented);
604 return Py_NotImplemented;
605}
606
607//----------------------------------------------------------------------------
609{
610// Build a representation string of the object proxy that shows the address
611// of the C++ object that is held, as well as its type.
612 PyObject* pyclass = (PyObject*)Py_TYPE(self);
613 if (CPPScope_Check(pyclass) && (((CPPScope*)pyclass)->fFlags & CPPScope::kIsPython))
614 return PyBaseObject_Type.tp_repr((PyObject*)self);
615 PyObject* modname = PyObject_GetAttr(pyclass, PyStrings::gModule);
616
617 Cppyy::TCppType_t klass = self->ObjectIsA();
618 std::string clName = klass ? Cppyy::GetFinalName(klass) : "<unknown>";
619 if (self->fFlags & CPPInstance::kIsPtrPtr)
620 clName.append("**");
621 else if (self->fFlags & CPPInstance::kIsReference)
622 clName.append("*");
623
624 PyObject* repr = nullptr;
625 if (self->IsSmart()) {
626 std::string smartPtrName = Cppyy::GetScopedFinalName(SMART_TYPE(self));
628 const_cast<char*>("<%s.%s object at %p held by %s at %p>"),
629 CPyCppyy_PyText_AsString(modname), clName.c_str(),
630 self->GetObject(), smartPtrName.c_str(), self->GetObjectRaw());
631 } else {
632 repr = CPyCppyy_PyText_FromFormat(const_cast<char*>("<%s.%s object at %p>"),
633 CPyCppyy_PyText_AsString(modname), clName.c_str(), self->GetObject());
634 }
635
636 Py_DECREF(modname);
637 return repr;
638}
639
640//----------------------------------------------------------------------------
642{
643// Cannot use PyLong_AsSize_t here, as it cuts of at PY_SSIZE_T_MAX, which is
644// only half of the max of std::size_t returned by the hash.
645 if (sizeof(unsigned long) >= sizeof(size_t))
646 return (Py_hash_t)PyLong_AsUnsignedLong(obj);
647 return (Py_hash_t)PyLong_AsUnsignedLongLong(obj);
648}
649
651{
652// Try to locate an std::hash for this type and use that if it exists
653 CPPClass* klass = (CPPClass*)Py_TYPE(self);
654 if (klass->fOperators && klass->fOperators->fHash) {
655 Py_hash_t h = 0;
656 PyObject* hashval = PyObject_CallFunctionObjArgs(klass->fOperators->fHash, (PyObject*)self, nullptr);
657 if (hashval) {
658 h = CPyCppyy_PyLong_AsHash_t(hashval);
659 Py_DECREF(hashval);
660 }
661 return h;
662 }
663
664 Cppyy::TCppScope_t stdhash = Cppyy::GetScope("std::hash<"+Cppyy::GetScopedFinalName(self->ObjectIsA())+">");
665 if (stdhash) {
666 PyObject* hashcls = CreateScopeProxy(stdhash);
667 PyObject* dct = PyObject_GetAttr(hashcls, PyStrings::gDict);
668 bool isValid = PyMapping_HasKeyString(dct, (char*)"__call__");
669 Py_DECREF(dct);
670 if (isValid) {
671 PyObject* hashobj = PyObject_CallObject(hashcls, nullptr);
672 if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};
673 klass->fOperators->fHash = hashobj;
674 Py_DECREF(hashcls);
675
676 Py_hash_t h = 0;
677 PyObject* hashval = PyObject_CallFunctionObjArgs(hashobj, (PyObject*)self, nullptr);
678 if (hashval) {
679 h = CPyCppyy_PyLong_AsHash_t(hashval);
680 Py_DECREF(hashval);
681 }
682 return h;
683 }
684 Py_DECREF(hashcls);
685 }
686
687// if not valid, simply reset the hash function so as to not kill performance
688 ((PyTypeObject*)Py_TYPE(self))->tp_hash = PyBaseObject_Type.tp_hash;
689 return PyBaseObject_Type.tp_hash((PyObject*)self);
690}
691
692//----------------------------------------------------------------------------
693static PyObject* op_str_internal(PyObject* pyobj, PyObject* lshift, bool isBound)
694{
695 static Cppyy::TCppScope_t sOStringStreamID = Cppyy::GetScope("std::ostringstream");
696 std::ostringstream s;
697 PyObject* pys = BindCppObjectNoCast(&s, sOStringStreamID);
698 Py_INCREF(pys);
699#if PY_VERSION_HEX >= 0x03000000
700// for py3 and later, a ref-count of 2 is okay to consider the object temporary, but
701// in this case, we can't lose our existing ostrinstring (otherwise, we'd have to peel
702// it out of the return value, if moves are used
703 Py_INCREF(pys);
704#endif
705
706 PyObject* res;
707 if (isBound) res = PyObject_CallFunctionObjArgs(lshift, pys, NULL);
708 else res = PyObject_CallFunctionObjArgs(lshift, pys, pyobj, NULL);
709
710 Py_DECREF(pys);
711#if PY_VERSION_HEX >= 0x03000000
712 Py_DECREF(pys);
713#endif
714
715 if (res) {
716 Py_DECREF(res);
717 return CPyCppyy_PyText_FromString(s.str().c_str());
718 }
719
720 return nullptr;
721}
722
723
724static inline bool ScopeFlagCheck(CPPInstance* self, CPPScope::EFlags flag) {
725 return ((CPPScope*)Py_TYPE((PyObject*)self))->fFlags & flag;
726}
727
728static inline void ScopeFlagSet(CPPInstance* self, CPPScope::EFlags flag) {
729 ((CPPScope*)Py_TYPE((PyObject*)self))->fFlags |= flag;
730}
731
733{
734// There are three possible options here:
735// 1. Available operator<< to convert through an ostringstream
736// 2. Cling's pretty printing
737// 3. Generic printing as done in op_repr
738//
739// Additionally, there may be a mapped __str__ from the C++ type defining `operator char*`
740// or `operator const char*`. Results are memoized for performance reasons.
741
742// 0. Protect against trying to print a typed nullptr object through an insertion operator
743 if (!self->GetObject())
744 return op_repr(self);
745
746// 1. Available operator<< to convert through an ostringstream
748 for (PyObject* pyname : {PyStrings::gLShift, PyStrings::gLShiftC, (PyObject*)0x01, (PyObject*)0x02}) {
750 continue;
751
752 else if (pyname == (PyObject*)0x01) {
753 // normal lookup failed; attempt lazy install of global operator<<(ostream&, type&)
754 std::string rcname = Utility::ClassName((PyObject*)self);
756 PyCallable* pyfunc = Utility::FindBinaryOperator("std::ostream", rcname, "<<", rnsID);
757 if (!pyfunc)
758 continue;
759
760 Utility::AddToClass((PyObject*)Py_TYPE((PyObject*)self), "__lshiftc__", pyfunc);
761
762 pyname = PyStrings::gLShiftC;
764
765 } else if (pyname == (PyObject*)0x02) {
766 // TODO: the only reason this still exists, is b/c friend functions are otherwise not found
767 // TODO: ToString() still leaks ...
768 const std::string& pretty = Cppyy::ToString(self->ObjectIsA(), self->GetObject());
769 if (!pretty.empty())
770 return CPyCppyy_PyText_FromString(pretty.c_str());
771 continue;
772 }
773
774 PyObject* lshift = PyObject_GetAttr(
775 pyname == PyStrings::gLShift ? (PyObject*)self : (PyObject*)Py_TYPE((PyObject*)self), pyname);
776
777 if (lshift) {
778 PyObject* result = op_str_internal((PyObject*)self, lshift, pyname == PyStrings::gLShift);
779 Py_DECREF(lshift);
780 if (result)
781 return result;
782 }
783
784 PyErr_Clear();
785 }
786
787 // failed ostream printing; don't try again
789 }
790
791// 2. Cling's pretty printing (not done through backend for performance reasons)
793 static PyObject* printValue = nullptr;
794 if (!printValue) {
795 PyObject* gbl = PyDict_GetItemString(PySys_GetObject((char*)"modules"), "cppyy.gbl");
796 PyObject* cl = PyObject_GetAttrString(gbl, (char*)"cling");
797 printValue = PyObject_GetAttrString(cl, (char*)"printValue");
798 Py_DECREF(cl);
799 // gbl is borrowed
800 if (printValue) {
801 Py_DECREF(printValue); // make borrowed
802 if (!PyCallable_Check(printValue))
803 printValue = nullptr; // unusable ...
804 }
805 if (!printValue) // unlikely
807 }
808
809 if (printValue) {
810 // as printValue only works well for templates taking pointer arguments, we'll
811 // have to force the issue by working with a by-ptr object
812 Cppyy::TCppObject_t cppobj = self->GetObjectRaw();
813 PyObject* byref = (PyObject*)self;
814 if (!(self->fFlags & CPPInstance::kIsReference)) {
817 } else {
818 Py_INCREF(byref);
819 }
820
821 // explicit template lookup
823 PyObject* OL = PyObject_GetItem(printValue, clName);
824 Py_DECREF(clName);
825
826 PyObject* pretty = OL ? PyObject_CallFunctionObjArgs(OL, byref, nullptr) : nullptr;
827 Py_XDECREF(OL);
828 Py_DECREF(byref);
829
830 PyObject* result = nullptr;
831 if (pretty) {
832 const std::string& pv = *(std::string*)((CPPInstance*)pretty)->GetObject();
833 if (!pv.empty() && pv.find("@0x") == std::string::npos)
835 Py_DECREF(pretty);
836 if (result) return result;
837 }
838
839 PyErr_Clear();
840 }
841
842 // if not available/specialized, don't try again
844 }
845
846// 3. Generic printing as done in op_repr
847 return op_repr(self);
848}
849
850//-----------------------------------------------------------------------------
852{
853 return PyBool_FromLong((long)(pyobj->fFlags & CPPInstance::kIsOwner));
854}
855
856//-----------------------------------------------------------------------------
857static int op_setownership(CPPInstance* pyobj, PyObject* value, void*)
858{
859// Set the ownership (True is python-owns) for the given object.
860 long shouldown = PyLong_AsLong(value);
861 if (shouldown == -1 && PyErr_Occurred()) {
862 PyErr_SetString(PyExc_ValueError, "__python_owns__ should be either True or False");
863 return -1;
864 }
865
866 (bool)shouldown ? pyobj->PythonOwns() : pyobj->CppOwns();
867
868 return 0;
869}
870
871
872//-----------------------------------------------------------------------------
873static PyGetSetDef op_getset[] = {
874 {(char*)"__python_owns__", (getter)op_getownership, (setter)op_setownership,
875 (char*)"If true, python manages the life time of this object", nullptr},
876 {(char*)nullptr, nullptr, nullptr, nullptr, nullptr}
877};
878
879
880//= CPyCppyy type number stubs to allow dynamic overrides =====================
881#define CPYCPPYY_STUB_BODY(name, op) \
882 bool previously_resolved_overload = (bool)meth; \
883 if (!meth) { \
884 PyErr_Clear(); \
885 PyCallable* pyfunc = Utility::FindBinaryOperator(left, right, #op); \
886 if (pyfunc) meth = (PyObject*)CPPOverload_New(#name, pyfunc); \
887 else { \
888 PyErr_SetString(PyExc_NotImplementedError, ""); \
889 return nullptr; \
890 } \
891 } \
892 PyObject* res = PyObject_CallFunctionObjArgs(meth, cppobj, other, nullptr);\
893 if (!res && previously_resolved_overload) { \
894 /* try again, in case (left, right) are different types than before */ \
895 PyErr_Clear(); \
896 PyCallable* pyfunc = Utility::FindBinaryOperator(left, right, #op); \
897 if (pyfunc) ((CPPOverload*&)meth)->AdoptMethod(pyfunc); \
898 else { \
899 PyErr_SetString(PyExc_NotImplementedError, ""); \
900 return nullptr; \
901 } \
902 /* use same overload with newly added function */ \
903 res = PyObject_CallFunctionObjArgs(meth, cppobj, other, nullptr); \
904 } \
905 return res;
906
907
908#define CPYCPPYY_OPERATOR_STUB(name, op, ometh) \
909static PyObject* op_##name##_stub(PyObject* left, PyObject* right) \
910{ \
911/* placeholder to lazily install and forward to 'ometh' if available */ \
912 CPPClass* klass = (CPPClass*)Py_TYPE(left); \
913 if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{}; \
914 PyObject*& meth = ometh; \
915 PyObject *cppobj = left, *other = right; \
916 CPYCPPYY_STUB_BODY(name, op) \
917}
918
919#define CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(name, op, lmeth, rmeth) \
920static PyObject* op_##name##_stub(PyObject* left, PyObject* right) \
921{ \
922/* placeholder to lazily install and forward do '(l/r)meth' if available */ \
923 CPPClass* klass; PyObject** pmeth; \
924 PyObject *cppobj, *other; \
925 if (CPPInstance_Check(left)) { \
926 klass = (CPPClass*)Py_TYPE(left); \
927 if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};\
928 pmeth = &lmeth; cppobj = left; other = right; \
929 } else if (CPPInstance_Check(right)) { \
930 klass = (CPPClass*)Py_TYPE(right); \
931 if (!klass->fOperators) klass->fOperators = new Utility::PyOperators{};\
932 pmeth = &rmeth; cppobj = right; other = left; \
933 } else { \
934 PyErr_SetString(PyExc_NotImplementedError, ""); \
935 return nullptr; \
936 } \
937 PyObject*& meth = *pmeth; \
938 CPYCPPYY_STUB_BODY(name, op) \
939}
940
941#define CPYCPPYY_UNARY_OPERATOR(name, op, label) \
942static PyObject* op_##name##_stub(PyObject* pyobj) \
943{ \
944/* placeholder to lazily install unary operators */ \
945 PyCallable* pyfunc = Utility::FindUnaryOperator((PyObject*)Py_TYPE(pyobj), #op);\
946 if (pyfunc && Utility::AddToClass((PyObject*)Py_TYPE(pyobj), #label, pyfunc))\
947 return PyObject_CallMethod(pyobj, (char*)#label, nullptr); \
948 PyErr_SetString(PyExc_NotImplementedError, ""); \
949 return nullptr; \
950}
951
952CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(add, +, klass->fOperators->fLAdd, klass->fOperators->fRAdd)
953CPYCPPYY_OPERATOR_STUB( sub, -, klass->fOperators->fSub)
954CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(mul, *, klass->fOperators->fLMul, klass->fOperators->fRMul)
955CPYCPPYY_OPERATOR_STUB( div, /, klass->fOperators->fDiv)
958CPYCPPYY_UNARY_OPERATOR(invert, ~, __invert__)
959
960//-----------------------------------------------------------------------------
961static PyNumberMethods op_as_number = {
962 (binaryfunc)op_add_stub, // nb_add
963 (binaryfunc)op_sub_stub, // nb_subtract
964 (binaryfunc)op_mul_stub, // nb_multiply
965#if PY_VERSION_HEX < 0x03000000
966 (binaryfunc)op_div_stub, // nb_divide
967#endif
968 0, // nb_remainder
969 0, // nb_divmod
970 0, // nb_power
971 (unaryfunc)op_neg_stub, // nb_negative
972 (unaryfunc)op_pos_stub, // nb_positive
973 0, // nb_absolute
974 (inquiry)op_nonzero, // nb_bool (nb_nonzero in p2)
975 (unaryfunc)op_invert_stub, // nb_invert
976 0, // nb_lshift
977 0, // nb_rshift
978 0, // nb_and
979 0, // nb_xor
980 0, // nb_or
981#if PY_VERSION_HEX < 0x03000000
982 0, // nb_coerce
983#endif
984 0, // nb_int
985 0, // nb_long (nb_reserved in p3)
986 0, // nb_float
987#if PY_VERSION_HEX < 0x03000000
988 0, // nb_oct
989 0, // nb_hex
990#endif
991 0, // nb_inplace_add
992 0, // nb_inplace_subtract
993 0, // nb_inplace_multiply
994#if PY_VERSION_HEX < 0x03000000
995 0, // nb_inplace_divide
996#endif
997 0, // nb_inplace_remainder
998 0, // nb_inplace_power
999 0, // nb_inplace_lshift
1000 0, // nb_inplace_rshift
1001 0, // nb_inplace_and
1002 0, // nb_inplace_xor
1003 0 // nb_inplace_or
1004#if PY_VERSION_HEX >= 0x02020000
1005 , 0 // nb_floor_divide
1006#if PY_VERSION_HEX < 0x03000000
1007 , 0 // nb_true_divide
1008#else
1009 , (binaryfunc)op_div_stub // nb_true_divide
1010#endif
1011 , 0 // nb_inplace_floor_divide
1012 , 0 // nb_inplace_true_divide
1013#endif
1014#if PY_VERSION_HEX >= 0x02050000
1015 , 0 // nb_index
1016#endif
1017#if PY_VERSION_HEX >= 0x03050000
1018 , 0 // nb_matrix_multiply
1019 , 0 // nb_inplace_matrix_multiply
1020#endif
1021};
1022
1023
1024//= CPyCppyy object proxy type ===============================================
1025PyTypeObject CPPInstance_Type = {
1027 (char*)"cppyy.CPPInstance", // tp_name
1028 sizeof(CPPInstance), // tp_basicsize
1029 0, // tp_itemsize
1030 (destructor)op_dealloc, // tp_dealloc
1031 0, // tp_vectorcall_offset / tp_print
1032 0, // tp_getattr
1033 0, // tp_setattr
1034 0, // tp_as_async / tp_compare
1035 (reprfunc)op_repr, // tp_repr
1036 &op_as_number, // tp_as_number
1037 0, // tp_as_sequence
1038 0, // tp_as_mapping
1039 (hashfunc)op_hash, // tp_hash
1040 0, // tp_call
1041 (reprfunc)op_str, // tp_str
1042 0, // tp_getattro
1043 0, // tp_setattro
1044 0, // tp_as_buffer
1045 Py_TPFLAGS_DEFAULT |
1046 Py_TPFLAGS_BASETYPE |
1047 Py_TPFLAGS_CHECKTYPES
1048#if PY_VERSION_HEX >= 0x03120000
1049 | Py_TPFLAGS_MANAGED_DICT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_MANAGED_WEAKREF
1050#endif
1051 , // tp_flags
1052 (char*)"cppyy object proxy (internal)", // tp_doc
1053 0, // tp_traverse
1054 (inquiry)op_clear, // tp_clear
1055 (richcmpfunc)op_richcompare, // tp_richcompare
1056 0, // tp_weaklistoffset
1057 0, // tp_iter
1058 0, // tp_iternext
1059 op_methods, // tp_methods
1060 0, // tp_members
1061 op_getset, // tp_getset
1062 0, // tp_base
1063 0, // tp_dict
1064 0, // tp_descr_get
1065 0, // tp_descr_set
1066 0, // tp_dictoffset
1067 0, // tp_init
1068 0, // tp_alloc
1069 (newfunc)op_new, // tp_new
1070 0, // tp_free
1071 0, // tp_is_gc
1072 0, // tp_bases
1073 0, // tp_mro
1074 0, // tp_cache
1075 0, // tp_subclasses
1076 0 // tp_weaklist
1077#if PY_VERSION_HEX >= 0x02030000
1078 , 0 // tp_del
1079#endif
1080#if PY_VERSION_HEX >= 0x02060000
1081 , 0 // tp_version_tag
1082#endif
1083#if PY_VERSION_HEX >= 0x03040000
1084 , 0 // tp_finalize
1085#endif
1086#if PY_VERSION_HEX >= 0x03080000
1087 , 0 // tp_vectorcall
1088#endif
1089#if PY_VERSION_HEX >= 0x030c0000
1090 , 0 // tp_watched
1091#endif
1092};
1093
1094} // namespace CPyCppyy
#define SMART_CLS(pyobj)
#define CPYCPPYY_UNARY_OPERATOR(name, op, label)
#define EXT_OBJECT(pyobj)
#define SMART_TYPE(pyobj)
#define CPYCPPYY_OPERATOR_STUB(name, op, ometh)
#define DATA_CACHE(pyobj)
#define DISPATCHPTR(pyobj)
#define CPYCPPYY_ORDERED_OPERATOR_STUB(op, ometh, label)
#define CPYCPPYY_ASSOCIATIVE_OPERATOR_STUB(name, op, lmeth, rmeth)
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
#define Py_RETURN_TRUE
Definition CPyCppyy.h:272
#define Py_RETURN_FALSE
Definition CPyCppyy.h:276
int Py_ssize_t
Definition CPyCppyy.h:215
#define PyInt_AsSsize_t
Definition CPyCppyy.h:216
#define CPyCppyy_PyText_AsString
Definition CPyCppyy.h:76
long Py_hash_t
Definition CPyCppyy.h:114
#define PyBool_FromLong
Definition CPyCppyy.h:251
#define CPyCppyy_PyText_FromFormat
Definition CPyCppyy.h:80
#define Py_RETURN_NONE
Definition CPyCppyy.h:268
#define CPyCppyy_PyText_Type
Definition CPyCppyy.h:94
#define CPyCppyy_PyText_FromString
Definition CPyCppyy.h:81
#define PyVarObject_HEAD_INIT(type, size)
Definition CPyCppyy.h:194
_object PyObject
std::ios_base::fmtflags fFlags
#define h(i)
Definition RSha256.hxx:106
@ kIsArray
Definition TDictionary.h:79
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
#define ARRAY_SIZE(array)
Definition civetweb.c:504
Cppyy::TCppType_t GetSmartIsA() const
bool IsSmart() const
Definition CPPInstance.h:59
void CastToArray(Py_ssize_t sz)
CPPInstance * Copy(void *cppinst, PyTypeObject *target=nullptr)
CI_DatamemberCache_t & GetDatamemberCache()
void SetSmart(PyObject *smart_type)
PyObject_HEAD void * fObject
Definition CPPInstance.h:47
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
bool IsExtended() const
Definition CPPInstance.h:58
void SetDispatchPtr(void *)
Utility::PyOperators * fOperators
Definition CPPScope.h:61
static bool RegisterPyObject(CPPInstance *pyobj, void *cppobj)
static bool UnregisterPyObject(CPPInstance *pyobj, PyObject *pyclass)
PyObject * gLShiftC
Definition PyStrings.cxx:49
std::string extract_namespace(const std::string &name)
PyCallable * FindBinaryOperator(PyObject *left, PyObject *right, const char *op, Cppyy::TCppScope_t scope=0)
Definition Utility.cxx:294
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
Definition Utility.cxx:182
std::string ClassName(PyObject *pyobj)
Definition Utility.cxx:994
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
PyTypeObject CPPInstance_Type
static PyObject * op_str_internal(PyObject *pyobj, PyObject *lshift, bool isBound)
static PyObject * op_div_stub(PyObject *left, PyObject *right)
static void ScopeFlagSet(CPPInstance *self, CPPScope::EFlags flag)
static Py_hash_t CPyCppyy_PyLong_AsHash_t(PyObject *obj)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
static int op_nonzero(CPPInstance *self)
static PyObject * op_mul_stub(PyObject *left, PyObject *right)
static PyMethodDef op_methods[]
static PyObject * op_repr(CPPInstance *self)
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
static PyObject * op_richcompare(CPPInstance *self, PyObject *other, int op)
std::vector< std::pair< ptrdiff_t, PyObject * > > CI_DatamemberCache_t
Definition CPPInstance.h:24
static int op_setownership(CPPInstance *pyobj, PyObject *value, void *)
bool CPPScope_Check(T *object)
Definition CPPScope.h:81
static PyObject * eqneq_binop(CPPClass *klass, PyObject *self, PyObject *obj, int op)
static PyObject * op_getownership(CPPInstance *pyobj, void *)
static PyObject * op_neg_stub(PyObject *pyobj)
static int op_clear(CPPInstance *pyobj)
static PyObject * op_sub_stub(PyObject *left, PyObject *right)
void op_dealloc_nofree(CPPInstance *)
bool CPPInstance_Check(T *object)
static PyObject * op_getitem(CPPInstance *self, PyObject *pyidx)
static PyObject * op_reshape(CPPInstance *self, PyObject *shape)
static PyGetSetDef op_getset[]
PyObject * gNullPtrObject
PyTypeObject CPPOverload_Type
static PyNumberMethods op_as_number
static void * cast_actual(void *obj)
static PyObject * op_str(CPPInstance *self)
static void op_dealloc(CPPInstance *pyobj)
static PyObject * op_pos_stub(PyObject *pyobj)
static PyObject * op_add_stub(PyObject *left, PyObject *right)
static Py_hash_t op_hash(CPPInstance *self)
static PyObject * op_dispatch(PyObject *self, PyObject *args, PyObject *)
static PyObject * op_invert_stub(PyObject *pyobj)
PyTypeObject CPPScope_Type
Definition CPPScope.cxx:645
static bool ScopeFlagCheck(CPPInstance *self, CPPScope::EFlags flag)
static PyObject * op_get_smartptr(CPPInstance *self)
static CPPInstance * op_new(PyTypeObject *subtype, PyObject *, PyObject *)
static PyObject * op_destruct(CPPInstance *self)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
RPY_EXPORTED size_t SizeOf(TCppType_t klass)
RPY_EXPORTED std::string ToString(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED void CallDestructor(TCppType_t type, TCppObject_t self)
void * TCppObject_t
Definition cpp_cppyy.h:21
RPY_EXPORTED void Destruct(TCppType_t type, TCppObject_t instance)
TCppScope_t TCppType_t
Definition cpp_cppyy.h:19
RPY_EXPORTED TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED void Deallocate(TCppType_t type, TCppObject_t instance)
RPY_EXPORTED void * CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
size_t TCppScope_t
Definition cpp_cppyy.h:18
RPY_EXPORTED std::string GetFinalName(TCppType_t type)