Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPyCppyyModule.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CallContext.h"
4#include "Converters.h"
5#include "CPPDataMember.h"
6#include "CPPExcInstance.h"
7#include "CPPInstance.h"
8#include "CPPOverload.h"
9#include "CPPScope.h"
10#include "CustomPyTypes.h"
11#include "LowLevelViews.h"
12#include "MemoryRegulator.h"
13#include "ProxyWrappers.h"
14#include "PyStrings.h"
15#include "TemplateProxy.h"
16#include "TupleOfInstances.h"
17#include "Utility.h"
18
19#define CPYCPPYY_INTERNAL 1
21namespace CPyCppyy {
22void* Instance_AsVoidPtr(PyObject* pyobject);
24 void* addr, const std::string& classname, bool python_owns = false);
25} // namespace CPyCppyy
26#undef CPYCPPYY_INTERNAL
27
28// Standard
29#include <algorithm>
30#include <map>
31#include <set>
32#include <string>
33#include <iostream>
34#include <sstream>
35#include <utility>
36#include <vector>
37
38
39// Note: as of py3.11, dictionary objects no longer carry a function pointer for
40// the lookup, so it can no longer be shimmed and "from cppyy.interactive import *"
41// thus no longer works.
42#if PY_VERSION_HEX < 0x030b0000
43
44//- from Python's dictobject.c -------------------------------------------------
45#if PY_VERSION_HEX >= 0x03030000
46 typedef struct PyDictKeyEntry {
47 /* Cached hash code of me_key. */
48 Py_hash_t me_hash;
49 PyObject *me_key;
50 PyObject *me_value; /* This field is only meaningful for combined tables */
51 } PyDictEntry;
52
53 typedef struct _dictkeysobject {
54 Py_ssize_t dk_refcnt;
55 Py_ssize_t dk_size;
56 dict_lookup_func dk_lookup;
57 Py_ssize_t dk_usable;
58#if PY_VERSION_HEX >= 0x03060000
59 Py_ssize_t dk_nentries;
60 union {
61 int8_t as_1[8];
62 int16_t as_2[4];
63 int32_t as_4[2];
64#if SIZEOF_VOID_P > 4
65 int64_t as_8[1];
66#endif
67 } dk_indices;
68#else
69 PyDictKeyEntry dk_entries[1];
70#endif
71 } PyDictKeysObject;
72
73#define CPYCPPYY_GET_DICT_LOOKUP(mp) \
74 ((dict_lookup_func&)mp->ma_keys->dk_lookup)
75
76#else
77
78#define CPYCPPYY_GET_DICT_LOOKUP(mp) \
79 ((dict_lookup_func&)mp->ma_lookup)
80
81#endif
82
83#endif // PY_VERSION_HEX < 0x030b0000
84
85//- data -----------------------------------------------------------------------
87{
88 return CPyCppyy_PyText_FromString("nullptr");
89}
90
92{
93 Py_FatalError("deallocating nullptr");
94}
95
97{
98 return 0;
99}
100
101static PyNumberMethods nullptr_as_number = {
102 0, 0, 0,
103#if PY_VERSION_HEX < 0x03000000
104 0,
105#endif
106 0, 0, 0, 0, 0, 0,
107 (inquiry)nullptr_nonzero, // tp_nonzero (nb_bool in p3)
108 0, 0, 0, 0, 0, 0,
109#if PY_VERSION_HEX < 0x03000000
110 0, // nb_coerce
111#endif
112 0, 0, 0,
113#if PY_VERSION_HEX < 0x03000000
114 0, 0,
115#endif
116 0, 0, 0,
117#if PY_VERSION_HEX < 0x03000000
118 0, // nb_inplace_divide
119#endif
120 0, 0, 0, 0, 0, 0, 0
121#if PY_VERSION_HEX >= 0x02020000
122 , 0 // nb_floor_divide
123#if PY_VERSION_HEX < 0x03000000
124 , 0 // nb_true_divide
125#else
126 , 0 // nb_true_divide
127#endif
128 , 0, 0
129#endif
130#if PY_VERSION_HEX >= 0x02050000
131 , 0 // nb_index
132#endif
133#if PY_VERSION_HEX >= 0x03050000
134 , 0 // nb_matrix_multiply
135 , 0 // nb_inplace_matrix_multiply
136#endif
137};
138
139static PyTypeObject PyNullPtr_t_Type = {
140 PyVarObject_HEAD_INIT(&PyType_Type, 0)
141 "nullptr_t", // tp_name
142 sizeof(PyObject), // tp_basicsize
143 0, // tp_itemsize
144 nullptr_dealloc, // tp_dealloc (never called)
145 0, 0, 0, 0,
146 nullptr_repr, // tp_repr
147 &nullptr_as_number, // tp_as_number
148 0, 0,
149 (hashfunc)_Py_HashPointer, // tp_hash
150 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
152#if PY_VERSION_HEX >= 0x02030000
153 , 0 // tp_del
154#endif
155#if PY_VERSION_HEX >= 0x02060000
156 , 0 // tp_version_tag
157#endif
158#if PY_VERSION_HEX >= 0x03040000
159 , 0 // tp_finalize
160#endif
161#if PY_VERSION_HEX >= 0x03080000
162 , 0 // tp_vectorcall
163#endif
164#if PY_VERSION_HEX >= 0x030c0000
165 , 0 // tp_watched
166#endif
167};
168
169
171{
172 return CPyCppyy_PyText_FromString("type default");
173}
174
176{
177 Py_FatalError("deallocating default");
178}
179
180static PyTypeObject PyDefault_t_Type = {
181 PyVarObject_HEAD_INIT(&PyType_Type, 0)
182 "default_t", // tp_name
183 sizeof(PyObject), // tp_basicsize
184 0, // tp_itemsize
185 default_dealloc, // tp_dealloc (never called)
186 0, 0, 0, 0,
187 default_repr, // tp_repr
188 0, 0, 0,
189 (hashfunc)_Py_HashPointer, // tp_hash
190 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, 0, 0, 0, 0, 0, 0, 0,
191 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
192#if PY_VERSION_HEX >= 0x02030000
193 , 0 // tp_del
194#endif
195#if PY_VERSION_HEX >= 0x02060000
196 , 0 // tp_version_tag
197#endif
198#if PY_VERSION_HEX >= 0x03040000
199 , 0 // tp_finalize
200#endif
201#if PY_VERSION_HEX >= 0x03080000
202 , 0 // tp_vectorcall
203#endif
204#if PY_VERSION_HEX >= 0x030c0000
205 , 0 // tp_watched
206#endif
207};
208
209namespace {
210
211PyObject _CPyCppyy_NullPtrStruct = {
212 _PyObject_EXTRA_INIT
214};
215
216PyObject _CPyCppyy_DefaultStruct = {
217 _PyObject_EXTRA_INIT
219};
220
221// TODO: refactor with Converters.cxx
222struct CPyCppyy_tagCDataObject { // non-public (but stable)
223 PyObject_HEAD
224 char* b_ptr;
225 int b_needsfree;
226};
227
228} // unnamed namespace
229
230namespace CPyCppyy {
231 PyObject* gThisModule = nullptr;
233 PyObject* gNullPtrObject = nullptr;
239 std::set<Cppyy::TCppType_t> gPinnedTypes;
240 std::ostringstream gCapturedError;
241 std::streambuf* gOldErrorBuffer = nullptr;
242
243 std::map<std::string, std::vector<PyObject*>> &pythonizations()
244 {
245 static std::map<std::string, std::vector<PyObject*>> pyzMap;
246 return pyzMap;
247 }
248}
249
250
251//- private helpers ------------------------------------------------------------
252namespace {
253
254using namespace CPyCppyy;
255
256
257//----------------------------------------------------------------------------
258#if PY_VERSION_HEX < 0x030b0000
259namespace {
260
261class GblGetter {
262public:
263 GblGetter() {
264 PyObject* cppyy = PyImport_AddModule((char*)"cppyy");
265 fGbl = PyObject_GetAttrString(cppyy, (char*)"gbl");
266 }
267 ~GblGetter() { Py_DECREF(fGbl); }
268
269 PyObject* operator*() { return fGbl; }
270
271private:
272 PyObject* fGbl;
273};
274
275} // unnamed namespace
276
277#if PY_VERSION_HEX >= 0x03060000
278inline Py_ssize_t OrgDictLookup(PyDictObject* mp, PyObject* key,
279 Py_hash_t hash, PyObject*** value_addr, Py_ssize_t* hashpos)
280{
281 return (*gDictLookupOrg)(mp, key, hash, value_addr, hashpos);
282}
283#define CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos) \
284 OrgDictLookup(mp, key, hash, value_addr, hashpos)
285
286Py_ssize_t CPyCppyyLookDictString(PyDictObject* mp, PyObject* key,
287 Py_hash_t hash, PyObject*** value_addr, Py_ssize_t* hashpos)
288
289#elif PY_VERSION_HEX >= 0x03030000
290inline PyDictKeyEntry* OrgDictLookup(
291 PyDictObject* mp, PyObject* key, Py_hash_t hash, PyObject*** value_addr)
292{
293 return (*gDictLookupOrg)(mp, key, hash, value_addr);
294}
295
296#define CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos) \
297 OrgDictLookup(mp, key, hash, value_addr)
298
299PyDictKeyEntry* CPyCppyyLookDictString(
300 PyDictObject* mp, PyObject* key, Py_hash_t hash, PyObject*** value_addr)
301
302#else /* < 3.3 */
303
304inline PyDictEntry* OrgDictLookup(PyDictObject* mp, PyObject* key, long hash)
305{
306 return (*gDictLookupOrg)(mp, key, hash);
307}
308
309#define CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos) \
310 OrgDictLookup(mp, key, hash)
311
312PyDictEntry* CPyCppyyLookDictString(PyDictObject* mp, PyObject* key, long hash)
313#endif
314{
315 static GblGetter gbl;
316#if PY_VERSION_HEX >= 0x03060000
317 Py_ssize_t ep;
318#else
319 PyDictEntry* ep;
320#endif
321
322// first search dictionary itself
323 ep = CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos);
325 return ep;
326
327#if PY_VERSION_HEX >= 0x03060000
328 if (ep >= 0)
329#else
330 if (!ep || (ep->me_key && ep->me_value))
331#endif
332 return ep;
333
334// filter for builtins
335 if (PyDict_GetItem(PyEval_GetBuiltins(), key) != 0)
336 return ep;
337
338// normal lookup failed, attempt to get C++ enum/global/class from top-level
339 gDictLookupActive = true;
340
341// attempt to get C++ enum/global/class from top-level
342 PyObject* val = PyObject_GetAttr(*gbl, key);
343
344 if (val) {
345 // success ...
346
347 if (CPPDataMember_CheckExact(val)) {
348 // don't want to add to dictionary (the proper place would be the
349 // dictionary of the (meta)class), but modifying ep will be noticed no
350 // matter what; just return the actual value and live with the copy in
351 // the dictionary (mostly, this is correct)
352 PyObject* actual_val = Py_TYPE(val)->tp_descr_get(val, nullptr, nullptr);
353 Py_DECREF(val);
354 val = actual_val;
355 }
356
357 // add reference to C++ entity in the given dictionary
358 CPYCPPYY_GET_DICT_LOOKUP(mp) = gDictLookupOrg; // prevent recursion
359 if (PyDict_SetItem((PyObject*)mp, key, val) == 0) {
360 ep = CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos);
361 } else {
362#if PY_VERSION_HEX >= 0x03060000
363 ep = -1;
364#else
365 ep->me_key = nullptr;
366 ep->me_value = nullptr;
367#endif
368 }
369 CPYCPPYY_GET_DICT_LOOKUP(mp) = CPyCppyyLookDictString; // restore
370
371 // done with val
372 Py_DECREF(val);
373 } else
374 PyErr_Clear();
375
376#if PY_VERSION_HEX >= 0x03030000
377 if (mp->ma_keys->dk_usable <= 0) {
378 // big risk that this lookup will result in a resize, so force it here
379 // to be able to reset the lookup function; of course, this is nowhere
380 // near fool-proof, but should cover interactive usage ...
382 const int maxinsert = 5;
383 PyObject* buf[maxinsert];
384 for (int varmax = 1; varmax <= maxinsert; ++varmax) {
385 for (int ivar = 0; ivar < varmax; ++ivar) {
386 buf[ivar] = CPyCppyy_PyText_FromFormat("__CPYCPPYY_FORCE_RESIZE_%d", ivar);
387 PyDict_SetItem((PyObject*)mp, buf[ivar], Py_None);
388 }
389 for (int ivar = 0; ivar < varmax; ++ivar) {
390 PyDict_DelItem((PyObject*)mp, buf[ivar]);
391 Py_DECREF(buf[ivar]);
392 }
393 if (0 < mp->ma_keys->dk_usable)
394 break;
395 }
396
397 // make sure the entry pointer is still valid by re-doing the lookup
398 ep = CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos);
399
400 // full reset of all lookup functions
402 CPYCPPYY_GET_DICT_LOOKUP(mp) = CPyCppyyLookDictString; // restore
403 }
404#endif
405
406// stopped calling into the reflection system
407 gDictLookupActive = false;
408 return ep;
409}
410
411#endif // PY_VERSION_HEX < 0x030b0000
412
413//----------------------------------------------------------------------------
414static PyObject* SetCppLazyLookup(PyObject*, PyObject* args)
415{
416#if PY_VERSION_HEX < 0x030b0000
417// Modify the given dictionary to install the lookup function that also
418// tries the global C++ namespace before failing. Called on a module's dictionary,
419// this allows for lazy lookups. This works fine for p3.2 and earlier, but should
420// not be used beyond interactive code for p3.3 and later b/c resizing causes the
421// lookup function to revert to the default (lookdict_unicode_nodummy).
422 PyDictObject* dict = nullptr;
423 if (!PyArg_ParseTuple(args, const_cast<char*>("O!"), &PyDict_Type, &dict))
424 return nullptr;
425
426 CPYCPPYY_GET_DICT_LOOKUP(dict) = CPyCppyyLookDictString;
427#else
428// As of py3.11, there is no longer a lookup function pointer in the dict object
429// to replace. Since this feature is not widely advertised, it's simply dropped
430 PyErr_Warn(PyExc_RuntimeWarning, (char*)"lazy lookup is no longer supported");
431 (void)args; // avoid warning about unused parameter
432#endif
433
435}
436
437//----------------------------------------------------------------------------
438static PyObject* MakeCppTemplateClass(PyObject*, PyObject* args)
439{
440// Create a binding for a templated class instantiation.
441
442// args is class name + template arguments; build full instantiation
443 Py_ssize_t nArgs = PyTuple_GET_SIZE(args);
444 if (nArgs < 2) {
445 PyErr_Format(PyExc_TypeError, "too few arguments for template instantiation");
446 return nullptr;
447 }
448
449// build "< type, type, ... >" part of class name (modifies pyname)
450 const std::string& tmpl_name =
451 Utility::ConstructTemplateArgs(PyTuple_GET_ITEM(args, 0), args, nullptr, Utility::kNone, 1);
452 if (!tmpl_name.size())
453 return nullptr;
454
455 return CreateScopeProxy(tmpl_name);
456}
457
458//----------------------------------------------------------------------------
459static char* GCIA_kwlist[] = {(char*)"instance", (char*)"field", (char*)"byref", NULL};
460static void* GetCPPInstanceAddress(const char* fname, PyObject* args, PyObject* kwds)
461{
462// Helper to get the address (address-of-address) of various object proxy types.
463 CPPInstance* pyobj = 0; PyObject* pyname = 0; int byref = 0;
464 if (PyArg_ParseTupleAndKeywords(args, kwds, const_cast<char*>("O|O!b"), GCIA_kwlist,
465 &pyobj, &CPyCppyy_PyText_Type, &pyname, &byref)) {
466
467 if (CPPInstance_Check(pyobj)) {
468 if (pyname != 0) {
469 // locate property proxy for offset info
470 CPPDataMember* pyprop = nullptr;
471
472 PyObject* pyclass = (PyObject*)Py_TYPE((PyObject*)pyobj);
473 PyObject* dict = PyObject_GetAttr(pyclass, PyStrings::gDict);
474 pyprop = (CPPDataMember*)PyObject_GetItem(dict, pyname);
475 Py_DECREF(dict);
476
477 if (CPPDataMember_Check(pyprop)) {
478 // this is an address of a value (i.e. &myobj->prop)
479 void* addr = (void*)pyprop->GetAddress(pyobj);
480 Py_DECREF(pyprop);
481 return addr;
482 }
483
484 Py_XDECREF(pyprop);
485
486 PyErr_Format(PyExc_TypeError,
487 "%s is not a valid data member", CPyCppyy_PyText_AsString(pyname));
488 return nullptr;
489 }
490
491 // this is an address of an address (i.e. &myobj, with myobj of type MyObj*)
492 // note that the return result may be null
493 if (!byref) return ((CPPInstance*)pyobj)->GetObject();
494 return &((CPPInstance*)pyobj)->GetObjectRaw();
495
496 } else if (CPyCppyy_PyText_Check(pyobj)) {
497 // special cases for access to the CPyCppyy API
498 std::string req = CPyCppyy_PyText_AsString((PyObject*)pyobj);
499 if (req == "Instance_AsVoidPtr")
500 return (void*)&Instance_AsVoidPtr;
501 else if (req == "Instance_FromVoidPtr")
502 return (void*)&Instance_FromVoidPtr;
503 }
504 }
505
506 if (!PyErr_Occurred())
507 PyErr_Format(PyExc_ValueError, "invalid argument for %s", fname);
508 return nullptr;
509}
510
511//----------------------------------------------------------------------------
512static PyObject* addressof(PyObject* /* dummy */, PyObject* args, PyObject* kwds)
513{
514// Return object proxy address as a value (cppyy-style), or the same for an array.
515 void* addr = GetCPPInstanceAddress("addressof", args, kwds);
516 if (addr)
517 return PyLong_FromLongLong((intptr_t)addr);
518 else if (!PyErr_Occurred()) {
519 return PyLong_FromLong(0);
520 } else if (PyTuple_CheckExact(args) && PyTuple_GET_SIZE(args) == 1) {
521 PyErr_Clear();
522 PyObject* arg0 = PyTuple_GET_ITEM(args, 0);
523
524 // nullptr special case
525 if (arg0 == gNullPtrObject || (PyInt_Check(arg0) && PyInt_AsLong(arg0) == 0))
526 return PyLong_FromLong(0);
527
528 // overload if unambiguous
529 if (CPPOverload_CheckExact(arg0)) {
530 const auto& methods = ((CPPOverload*)arg0)->fMethodInfo->fMethods;
531 if (methods.size() != 1) {
532 PyErr_SetString(PyExc_TypeError, "overload is not unambiguous");
533 return nullptr;
534 }
535
536 Cppyy::TCppFuncAddr_t caddr = methods[0]->GetFunctionAddress();
537 return PyLong_FromLongLong((intptr_t)caddr);
538 }
539
540 // C functions (incl. ourselves)
541 if (PyCFunction_Check(arg0)) {
542 void* caddr = (void*)PyCFunction_GetFunction(arg0);
543 return PyLong_FromLongLong((intptr_t)caddr);
544 }
545
546 // final attempt: any type of buffer
547 Utility::GetBuffer(arg0, '*', 1, addr, false);
548 if (addr) return PyLong_FromLongLong((intptr_t)addr);
549 }
550
551// error message if not already set
552 if (!PyErr_Occurred()) {
553 if (PyTuple_CheckExact(args) && PyTuple_GET_SIZE(args)) {
554 PyObject* str = PyObject_Str(PyTuple_GET_ITEM(args, 0));
555 if (str && CPyCppyy_PyText_Check(str))
556 PyErr_Format(PyExc_TypeError, "unknown object %s", CPyCppyy_PyText_AsString(str));
557 else
558 PyErr_Format(PyExc_TypeError, "unknown object at %p", (void*)PyTuple_GET_ITEM(args, 0));
559 Py_XDECREF(str);
560 }
561 }
562 return nullptr;
563}
564
565//----------------------------------------------------------------------------
566static PyObject* AsCObject(PyObject* /* unused */, PyObject* args, PyObject* kwds)
567{
568// Return object proxy as an opaque CObject.
569 void* addr = GetCPPInstanceAddress("as_cobject", args, kwds);
570 if (addr)
571 return CPyCppyy_PyCapsule_New((void*)addr, nullptr, nullptr);
572 return nullptr;
573}
574
575//----------------------------------------------------------------------------
576static PyObject* AsCapsule(PyObject* /* unused */, PyObject* args, PyObject* kwds)
577{
578// Return object proxy as an opaque PyCapsule.
579 void* addr = GetCPPInstanceAddress("as_capsule", args, kwds);
580 if (addr)
581#if PY_VERSION_HEX < 0x02060000
582 return PyCObject_FromVoidPtr(addr, nullptr);
583#else
584 return PyCapsule_New(addr, nullptr, nullptr);
585#endif
586 return nullptr;
587}
588
589//----------------------------------------------------------------------------
590static PyObject* AsCTypes(PyObject* /* unused */, PyObject* args, PyObject* kwds)
591{
592// Return object proxy as a ctypes c_void_p
593 void* addr = GetCPPInstanceAddress("as_ctypes", args, kwds);
594 if (!addr)
595 return nullptr;
596
597// TODO: refactor code below with converters code
598 static PyTypeObject* ct_cvoidp = nullptr;
599 if (!ct_cvoidp) {
600 PyObject* ctmod = PyImport_ImportModule("ctypes"); // ref-count kept
601 if (!ctmod) return nullptr;
602
603 ct_cvoidp = (PyTypeObject*)PyObject_GetAttrString(ctmod, "c_void_p");
604 Py_DECREF(ctmod);
605 if (!ct_cvoidp) return nullptr;
606 Py_DECREF(ct_cvoidp); // module keeps a reference
607 }
608
609 PyObject* ref = ct_cvoidp->tp_new(ct_cvoidp, nullptr, nullptr);
610 *(void**)((CPyCppyy_tagCDataObject*)ref)->b_ptr = addr;
611 ((CPyCppyy_tagCDataObject*)ref)->b_needsfree = 0;
612 return ref;
613}
614
615//----------------------------------------------------------------------------
616static PyObject* AsMemoryView(PyObject* /* unused */, PyObject* pyobject)
617{
618// Return a raw memory view on arrays of PODs.
619 if (!CPPInstance_Check(pyobject)) {
620 PyErr_SetString(PyExc_TypeError, "C++ object proxy expected");
621 return nullptr;
622 }
623
624 CPPInstance* pyobj = (CPPInstance*)pyobject;
625 Cppyy::TCppType_t klass = ((CPPClass*)Py_TYPE(pyobject))->fCppType;
626
627 Py_ssize_t array_len = pyobj->ArrayLength();
628
629 if (array_len < 0 || !Cppyy::IsAggregate(klass)) {
630 PyErr_SetString(
631 PyExc_TypeError, "object is not a proxy to an array of PODs of known size");
632 return nullptr;
633 }
634
635 Py_buffer view;
636
637 view.obj = pyobject;
638 view.buf = pyobj->GetObject();
639 view.itemsize = Cppyy::SizeOf(klass);
640 view.len = view.itemsize * array_len;
641 view.readonly = 0;
642 view.format = NULL; // i.e. "B" assumed
643 view.ndim = 1;
644 view.shape = NULL;
645 view.strides = NULL;
646 view.suboffsets = NULL;
647 view.internal = NULL;
648
649 return PyMemoryView_FromBuffer(&view);
650}
651
652//----------------------------------------------------------------------------
653static PyObject* BindObject(PyObject*, PyObject* args, PyObject* kwds)
654{
655// From a long representing an address or a PyCapsule/CObject, bind to a class.
656 Py_ssize_t argc = PyTuple_GET_SIZE(args);
657 if (argc != 2) {
658 PyErr_Format(PyExc_TypeError,
659 "bind_object takes 2 positional arguments but (" PY_SSIZE_T_FORMAT " were given)", argc);
660 return nullptr;
661 }
662
663// convert 2nd argument first (used for both pointer value and instance cases)
664 Cppyy::TCppType_t cast_type = 0;
665 PyObject* arg1 = PyTuple_GET_ITEM(args, 1);
666 if (!CPyCppyy_PyText_Check(arg1)) { // not string, then class
667 if (CPPScope_Check(arg1))
668 cast_type = ((CPPClass*)arg1)->fCppType;
669 else
670 arg1 = PyObject_GetAttr(arg1, PyStrings::gName);
671 } else
672 Py_INCREF(arg1);
673
674 if (!cast_type && arg1) {
676 Py_DECREF(arg1);
677 }
678
679 if (!cast_type) {
680 PyErr_SetString(PyExc_TypeError,
681 "bind_object expects a valid class or class name as an argument");
682 return nullptr;
683 }
684
685// next, convert the first argument, some pointer value or a pre-existing instance
686 PyObject* arg0 = PyTuple_GET_ITEM(args, 0);
687
688 if (CPPInstance_Check(arg0)) {
689 // if this instance's class has a relation to the requested one, calculate the
690 // offset, erase if from any caches, and update the pointer and type
691 CPPInstance* arg0_pyobj = (CPPInstance*)arg0;
692 Cppyy::TCppType_t cur_type = arg0_pyobj->ObjectIsA(false /* check_smart */);
693
694 bool isPython = CPPScope_Check(arg1) && \
695 (((CPPClass*)arg1)->fFlags & CPPScope::kIsPython);
696
697 if (cur_type == cast_type && !isPython) {
698 Py_INCREF(arg0); // nothing to do
699 return arg0;
700 }
701
702 int direction = 0;
703 Cppyy::TCppType_t base = 0, derived = 0;
704 if (Cppyy::IsSubtype(cast_type, cur_type)) {
705 derived = cast_type;
706 base = cur_type;
707 direction = -1; // down-cast
708 } else if (Cppyy::IsSubtype(cur_type, cast_type)) {
709 base = cast_type;
710 derived = cur_type;
711 direction = 1; // up-cast
712 } else {
713 PyErr_SetString(PyExc_TypeError,
714 "provided instance and provided target type are unrelated");
715 return nullptr;
716 }
717
718 Cppyy::TCppObject_t address = (Cppyy::TCppObject_t)arg0_pyobj->GetObject();
719 ptrdiff_t offset = Cppyy::GetBaseOffset(derived, base, address, direction);
720
721 // it's debatable whether a new proxy should be created rather than updating
722 // the old, but changing the old object would be changing the behavior of all
723 // code that has a reference to it, which may not be the intention if the cast
724 // is on a C++ data member; this probably is the "least surprise" option
725
726 // ownership is taken over as needed, again following the principle of "least
727 // surprise" as most likely only the cast object will be retained
728 bool owns = arg0_pyobj->fFlags & CPPInstance::kIsOwner;
729
730 if (!isPython) {
731 // ordinary C++ class
733 (void*)((intptr_t)address + offset), cast_type, owns ? CPPInstance::kIsOwner : 0);
734 if (owns && pyobj) arg0_pyobj->CppOwns();
735 return pyobj;
736
737 } else {
738 // rebinding to a Python-side class, create a fresh instance first to be able to
739 // perform a lookup of the original dispatch object and if found, return original
740 void* cast_address = (void*)((intptr_t)address + offset);
741 PyObject* pyobj = ((PyTypeObject*)arg1)->tp_new((PyTypeObject*)arg1, nullptr, nullptr);
742 ((CPPInstance*)pyobj)->GetObjectRaw() = cast_address;
743
744 PyObject* dispproxy = CPyCppyy::GetScopeProxy(cast_type);
746 /* Note: the resultant object is borrowed */
747 if (CPPInstance_Check(res) && ((CPPInstance*)res)->GetObject() == cast_address) {
748 ((CPPInstance*)pyobj)->CppOwns(); // make sure C++ object isn't deleted
749 Py_DECREF(pyobj); // on DECREF (is default, but still)
750 pyobj = res;
751 } else {
752 if (res) Py_DECREF(res); // most likely Py_None
753 else PyErr_Clear(); // should not happen
754 }
755 Py_DECREF(dispproxy);
756
757 if (pyobj && owns) {
758 arg0_pyobj->CppOwns();
759 ((CPPInstance*)pyobj)->PythonOwns();
760 }
761
762 return pyobj;
763 }
764 }
765
766// not a pre-existing object; get the address and bind
767 void* addr = nullptr;
768 if (arg0 != &_CPyCppyy_NullPtrStruct) {
769 addr = CPyCppyy_PyCapsule_GetPointer(arg0, nullptr);
770 if (PyErr_Occurred()) {
771 PyErr_Clear();
772
773 addr = PyLong_AsVoidPtr(arg0);
774 if (PyErr_Occurred()) {
775 PyErr_Clear();
776
777 // last chance, perhaps it's a buffer/array (return from void*)
778 Py_ssize_t buflen = Utility::GetBuffer(PyTuple_GetItem(args, 0), '*', 1, addr, false);
779 if (!addr || !buflen) {
780 PyErr_SetString(PyExc_TypeError,
781 "bind_object requires a CObject/Capsule, long integer, buffer, or instance as first argument");
782 return nullptr;
783 }
784 }
785 }
786 }
787
788 bool do_cast = false;
789 if (kwds) {
790 PyObject* cast = PyDict_GetItemString(kwds, "cast");
791 do_cast = cast && PyObject_IsTrue(cast);
792 }
793
794 if (do_cast)
795 return BindCppObject(addr, cast_type);
796
797 return BindCppObjectNoCast(addr, cast_type);
798}
799
800//----------------------------------------------------------------------------
801static PyObject* Move(PyObject*, PyObject* pyobject)
802{
803// Prepare the given C++ object for moving.
804 if (!CPPInstance_Check(pyobject)) {
805 PyErr_SetString(PyExc_TypeError, "C++ object expected");
806 return nullptr;
807 }
808
809 ((CPPInstance*)pyobject)->fFlags |= CPPInstance::kIsRValue;
810 Py_INCREF(pyobject);
811 return pyobject;
812}
813
814
815//----------------------------------------------------------------------------
816static PyObject* AddPythonization(PyObject*, PyObject* args)
817{
818// Remove a previously registered pythonizor from the given scope.
819 PyObject* pythonizor = nullptr; const char* scope;
820 if (!PyArg_ParseTuple(args, const_cast<char*>("Os"), &pythonizor, &scope))
821 return nullptr;
822
823 if (!PyCallable_Check(pythonizor)) {
824 PyObject* pystr = PyObject_Str(pythonizor);
825 PyErr_Format(PyExc_TypeError,
826 "given \'%s\' object is not callable", CPyCppyy_PyText_AsString(pystr));
827 Py_DECREF(pystr);
828 return nullptr;
829 }
830
831 Py_INCREF(pythonizor);
832 pythonizations()[scope].push_back(pythonizor);
833
835}
836
837
838//----------------------------------------------------------------------------
839static PyObject* RemovePythonization(PyObject*, PyObject* args)
840{
841// Remove a previously registered pythonizor from the given scope.
842 PyObject* pythonizor = nullptr; const char* scope;
843 if (!PyArg_ParseTuple(args, const_cast<char*>("Os"), &pythonizor, &scope))
844 return nullptr;
845
846 auto &pyzMap = pythonizations();
847 auto p1 = pyzMap.find(scope);
848 if (p1 != pyzMap.end()) {
849 auto p2 = std::find(p1->second.begin(), p1->second.end(), pythonizor);
850 if (p2 != p1->second.end()) {
851 p1->second.erase(p2);
853 }
854 }
855
857}
858
859//----------------------------------------------------------------------------
860static PyObject* PinType(PyObject*, PyObject* pyclass)
861{
862// Add a pinning so that objects of type `derived' are interpreted as
863// objects of type `base'.
864 if (!CPPScope_Check(pyclass)) {
865 PyErr_SetString(PyExc_TypeError, "C++ class expected");
866 return nullptr;
867 }
868
869 gPinnedTypes.insert(((CPPClass*)pyclass)->fCppType);
870
872}
873
874//----------------------------------------------------------------------------
876{
877// Add a type reducer to map type2 to type2 on function returns.
878 const char *reducable, *reduced;
879 if (!PyArg_ParseTuple(args, const_cast<char*>("ss"), &reducable, &reduced))
880 return nullptr;
881
882 Cppyy::AddTypeReducer(reducable, reduced);
883
885}
886
887//----------------------------------------------------------------------------
888static PyObject* SetMemoryPolicy(PyObject*, PyObject* args)
889{
890// Set the global memory policy, which affects object ownership when objects
891// are passed as function arguments.
892 PyObject* policy = nullptr;
893 if (!PyArg_ParseTuple(args, const_cast<char*>("O!"), &PyInt_Type, &policy))
894 return nullptr;
895
896 long old = (long)CallContext::sMemoryPolicy;
897
898 long l = PyInt_AS_LONG(policy);
900 return PyInt_FromLong(old);
901 }
902
903 PyErr_Format(PyExc_ValueError, "Unknown policy %ld", l);
904 return nullptr;
905}
906
907//----------------------------------------------------------------------------
908static PyObject* SetGlobalSignalPolicy(PyObject*, PyObject* args)
909{
910// Set the global signal policy, which determines whether a jmp address
911// should be saved to return to after a C++ segfault.
912 PyObject* setProtected = 0;
913 if (!PyArg_ParseTuple(args, const_cast<char*>("O"), &setProtected))
914 return nullptr;
915
916 if (CallContext::SetGlobalSignalPolicy(PyObject_IsTrue(setProtected))) {
918 }
919
921}
922
923//----------------------------------------------------------------------------
924static PyObject* SetOwnership(PyObject*, PyObject* args)
925{
926// Set the ownership (True is python-owns) for the given object.
927 CPPInstance* pyobj = nullptr; PyObject* pykeep = nullptr;
928 if (!PyArg_ParseTuple(args, const_cast<char*>("O!O!"),
929 &CPPInstance_Type, (void*)&pyobj, &PyInt_Type, &pykeep))
930 return nullptr;
931
932 (bool)PyLong_AsLong(pykeep) ? pyobj->PythonOwns() : pyobj->CppOwns();
933
935}
936
937//----------------------------------------------------------------------------
939{
940// Add a smart pointer to the list of known smart pointer types.
941 const char* type_name;
942 if (!PyArg_ParseTuple(args, const_cast<char*>("s"), &type_name))
943 return nullptr;
944
945 Cppyy::AddSmartPtrType(type_name);
946
948}
949
950//----------------------------------------------------------------------------
951static PyObject* BeginCaptureStderr(PyObject*, PyObject*)
952{
953 gOldErrorBuffer = std::cerr.rdbuf();
954 std::cerr.rdbuf(gCapturedError.rdbuf());
955
957}
958
959//----------------------------------------------------------------------------
960static PyObject* EndCaptureStderr(PyObject*, PyObject*)
961{
962// restore old rdbuf and return captured result
963 std::cerr.rdbuf(gOldErrorBuffer);
964 gOldErrorBuffer = nullptr;
965
966 std::string capturedError = std::move(gCapturedError).str();
967
968 gCapturedError.str("");
969 gCapturedError.clear();
970
971 return Py_BuildValue("s", capturedError.c_str());
972}
973} // unnamed namespace
974
975
976//- data -----------------------------------------------------------------------
977static PyMethodDef gCPyCppyyMethods[] = {
978 {(char*) "CreateScopeProxy", (PyCFunction)CPyCppyy::CreateScopeProxy,
979 METH_VARARGS, (char*)"cppyy internal function"},
980 {(char*) "MakeCppTemplateClass", (PyCFunction)MakeCppTemplateClass,
981 METH_VARARGS, (char*)"cppyy internal function"},
982 {(char*) "_set_cpp_lazy_lookup", (PyCFunction)SetCppLazyLookup,
983 METH_VARARGS, (char*)"cppyy internal function"},
984 {(char*) "_DestroyPyStrings", (PyCFunction)CPyCppyy::DestroyPyStrings,
985 METH_NOARGS, (char*)"cppyy internal function"},
986 {(char*) "addressof", (PyCFunction)addressof,
987 METH_VARARGS | METH_KEYWORDS, (char*)"Retrieve address of proxied object or field as a value."},
988 {(char*) "as_cobject", (PyCFunction)AsCObject,
989 METH_VARARGS | METH_KEYWORDS, (char*)"Retrieve address of proxied object or field in a CObject."},
990 {(char*) "as_capsule", (PyCFunction)AsCapsule,
991 METH_VARARGS | METH_KEYWORDS, (char*)"Retrieve address of proxied object or field in a PyCapsule."},
992 {(char*) "as_ctypes", (PyCFunction)AsCTypes,
993 METH_VARARGS | METH_KEYWORDS, (char*)"Retrieve address of proxied object or field in a ctypes c_void_p."},
994 {(char*) "as_memoryview", (PyCFunction)AsMemoryView,
995 METH_O, (char*)"Represent an array of objects as raw memory."},
996 {(char*)"bind_object", (PyCFunction)BindObject,
997 METH_VARARGS | METH_KEYWORDS, (char*) "Create an object of given type, from given address."},
998 {(char*) "move", (PyCFunction)Move,
999 METH_O, (char*)"Cast the C++ object to become movable."},
1000 {(char*) "add_pythonization", (PyCFunction)AddPythonization,
1001 METH_VARARGS, (char*)"Add a pythonizor."},
1002 {(char*) "remove_pythonization", (PyCFunction)RemovePythonization,
1003 METH_VARARGS, (char*)"Remove a pythonizor."},
1004 {(char*) "_pin_type", (PyCFunction)PinType,
1005 METH_O, (char*)"Install a type pinning."},
1006 {(char*) "_add_type_reducer", (PyCFunction)AddTypeReducer,
1007 METH_VARARGS, (char*)"Add a type reducer."},
1008 {(char*) "SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
1009 METH_VARARGS, (char*)"Determines object ownership model."},
1010 {(char*) "SetGlobalSignalPolicy", (PyCFunction)SetGlobalSignalPolicy,
1011 METH_VARARGS, (char*)"Trap signals in safe mode to prevent interpreter abort."},
1012 {(char*) "SetOwnership", (PyCFunction)SetOwnership,
1013 METH_VARARGS, (char*)"Modify held C++ object ownership."},
1014 {(char*) "AddSmartPtrType", (PyCFunction)AddSmartPtrType,
1015 METH_VARARGS, (char*) "Add a smart pointer to the list of known smart pointer types."},
1016 {(char*) "_begin_capture_stderr", (PyCFunction)BeginCaptureStderr,
1017 METH_NOARGS, (char*) "Begin capturing stderr to a in memory buffer."},
1018 {(char*) "_end_capture_stderr", (PyCFunction)EndCaptureStderr,
1019 METH_NOARGS, (char*) "End capturing stderr and returns the captured buffer."},
1020 {nullptr, nullptr, 0, nullptr}
1021};
1022
1023
1024#if PY_VERSION_HEX >= 0x03000000
1025struct module_state {
1026 PyObject *error;
1027};
1028
1029#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
1030
1031static int cpycppyymodule_traverse(PyObject* m, visitproc visit, void* arg)
1032{
1033 Py_VISIT(GETSTATE(m)->error);
1034 return 0;
1035}
1036
1037static int cpycppyymodule_clear(PyObject* m)
1038{
1039 Py_CLEAR(GETSTATE(m)->error);
1040 return 0;
1041}
1042
1043
1044static struct PyModuleDef moduledef = {
1045 PyModuleDef_HEAD_INIT,
1046 "libcppyy",
1047 nullptr,
1048 sizeof(struct module_state),
1050 nullptr,
1051 cpycppyymodule_traverse,
1052 cpycppyymodule_clear,
1053 nullptr
1054};
1055
1056
1057//----------------------------------------------------------------------------
1058#define CPYCPPYY_INIT_ERROR return nullptr
1059extern "C" PyObject* PyInit_libcppyy()
1060#else
1061#define CPYCPPYY_INIT_ERROR return
1062extern "C" void initlibcppyy()
1063#endif
1064{
1065// Initialization of extension module libcppyy.
1066
1067// load commonly used python strings
1070
1071// setup interpreter
1072#if PY_VERSION_HEX < 0x03090000
1073 PyEval_InitThreads();
1074#endif
1075
1076#if PY_VERSION_HEX < 0x030b0000
1077// prepare for laziness (the insert is needed to capture the most generic lookup
1078// function, just in case ...)
1079 PyObject* dict = PyDict_New();
1080 PyObject* notstring = PyInt_FromLong(5);
1081 PyDict_SetItem(dict, notstring, notstring);
1082 Py_DECREF(notstring);
1083#if PY_VERSION_HEX >= 0x03030000
1084 gDictLookupOrg = (dict_lookup_func)((PyDictObject*)dict)->ma_keys->dk_lookup;
1085#else
1086 gDictLookupOrg = (dict_lookup_func)((PyDictObject*)dict)->ma_lookup;
1087#endif
1088 Py_DECREF(dict);
1089#endif // PY_VERSION_HEX < 0x030b0000
1090
1091// setup this module
1092#if PY_VERSION_HEX >= 0x03000000
1093 gThisModule = PyModule_Create(&moduledef);
1094#else
1095 gThisModule = Py_InitModule(const_cast<char*>("libcppyy"), gCPyCppyyMethods);
1096#endif
1097 if (!gThisModule)
1099
1100// keep gThisModule, but do not increase its reference count even as it is borrowed,
1101// or a self-referencing cycle would be created
1102
1103// external types
1104 gPyTypeMap = PyDict_New();
1105 PyModule_AddObject(gThisModule, "type_map", gPyTypeMap); // steals reference
1106
1107// Pythonizations ...
1108 PyModule_AddObject(gThisModule, "UserExceptions", PyDict_New());
1109
1110// inject meta type
1111 if (!Utility::InitProxy(gThisModule, &CPPScope_Type, "CPPScope"))
1113
1114// inject object proxy type
1115 if (!Utility::InitProxy(gThisModule, &CPPInstance_Type, "CPPInstance"))
1117
1118// inject exception object proxy type
1119 if (!Utility::InitProxy(gThisModule, &CPPExcInstance_Type, "CPPExcInstance"))
1121
1122// inject method proxy type
1123 if (!Utility::InitProxy(gThisModule, &CPPOverload_Type, "CPPOverload"))
1125
1126// inject template proxy type
1127 if (!Utility::InitProxy(gThisModule, &TemplateProxy_Type, "TemplateProxy"))
1129
1130// inject property proxy type
1131 if (!Utility::InitProxy(gThisModule, &CPPDataMember_Type, "CPPDataMember"))
1133
1134// inject custom data types
1135#if PY_VERSION_HEX < 0x03000000
1138
1141#endif
1142
1145
1146 if (!Utility::InitProxy(gThisModule, &TupleOfInstances_Type, "InstanceArray"))
1148
1149 if (!Utility::InitProxy(gThisModule, &LowLevelView_Type, "LowLevelView"))
1151
1152 if (!Utility::InitProxy(gThisModule, &PyNullPtr_t_Type, "nullptr_t"))
1154
1155// custom iterators
1156 if (PyType_Ready(&InstanceArrayIter_Type) < 0)
1158
1159 if (PyType_Ready(&IndexIter_Type) < 0)
1161
1162 if (PyType_Ready(&VectorIter_Type) < 0)
1164
1165// inject identifiable nullptr and default
1166 gNullPtrObject = (PyObject*)&_CPyCppyy_NullPtrStruct;
1167 Py_INCREF(gNullPtrObject);
1168 PyModule_AddObject(gThisModule, (char*)"nullptr", gNullPtrObject);
1169
1170 gDefaultObject = (PyObject*)&_CPyCppyy_DefaultStruct;
1171 Py_INCREF(gDefaultObject);
1172 PyModule_AddObject(gThisModule, (char*)"default", gDefaultObject);
1173
1174// C++-specific exceptions
1175 PyObject* cppfatal = PyErr_NewException((char*)"cppyy.ll.FatalError", nullptr, nullptr);
1176 PyModule_AddObject(gThisModule, (char*)"FatalError", cppfatal);
1177
1178 gBusException = PyErr_NewException((char*)"cppyy.ll.BusError", cppfatal, nullptr);
1179 PyModule_AddObject(gThisModule, (char*)"BusError", gBusException);
1180 gSegvException = PyErr_NewException((char*)"cppyy.ll.SegmentationViolation", cppfatal, nullptr);
1181 PyModule_AddObject(gThisModule, (char*)"SegmentationViolation", gSegvException);
1182 gIllException = PyErr_NewException((char*)"cppyy.ll.IllegalInstruction", cppfatal, nullptr);
1183 PyModule_AddObject(gThisModule, (char*)"IllegalInstruction", gIllException);
1184 gAbrtException = PyErr_NewException((char*)"cppyy.ll.AbortSignal", cppfatal, nullptr);
1185 PyModule_AddObject(gThisModule, (char*)"AbortSignal", gAbrtException);
1186
1187// policy labels
1188 PyModule_AddObject(gThisModule, (char*)"kMemoryHeuristics",
1189 PyInt_FromLong((int)CallContext::kUseHeuristics));
1190 PyModule_AddObject(gThisModule, (char*)"kMemoryStrict",
1191 PyInt_FromLong((int)CallContext::kUseStrict));
1192
1193// gbl namespace is injected in cppyy.py
1194
1195// create the memory regulator
1196 static MemoryRegulator s_memory_regulator;
1197
1198#if PY_VERSION_HEX >= 0x03000000
1199 Py_INCREF(gThisModule);
1200 return gThisModule;
1201#endif
1202}
static PyObject * default_repr(PyObject *)
#define CPYCPPYY_ORGDICT_LOOKUP(mp, key, hash, value_addr, hashpos)
static PyObject * nullptr_repr(PyObject *)
static PyNumberMethods nullptr_as_number
#define CPYCPPYY_INIT_ERROR
static void default_dealloc(PyObject *)
void initlibcppyy()
static PyTypeObject PyDefault_t_Type
static void nullptr_dealloc(PyObject *)
static int nullptr_nonzero(PyObject *)
static PyMethodDef gCPyCppyyMethods[]
static PyTypeObject PyNullPtr_t_Type
#define CPYCPPYY_GET_DICT_LOOKUP(mp)
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, long)
Definition CPyCppyy.h:44
#define Py_RETURN_TRUE
Definition CPyCppyy.h:272
#define Py_RETURN_FALSE
Definition CPyCppyy.h:276
#define PY_SSIZE_T_FORMAT
Definition CPyCppyy.h:218
static void * CPyCppyy_PyCapsule_GetPointer(PyObject *capsule, const char *)
Definition CPyCppyy.h:104
#define CPyCppyy_PyText_AsString
Definition CPyCppyy.h:76
static PyObject * CPyCppyy_PyCapsule_New(void *cobj, const char *, void(*destr)(void *))
Definition CPyCppyy.h:98
long Py_hash_t
Definition CPyCppyy.h:114
static PyObject * PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObject *arg)
Definition CPyCppyy.h:367
#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 CPyCppyy_PyText_Check
Definition CPyCppyy.h:74
#define PyVarObject_HEAD_INIT(type, size)
Definition CPyCppyy.h:194
_object PyObject
static struct PyModuleDef moduledef
#define GETSTATE(m)
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
TTime operator*(const TTime &t1, const TTime &t2)
Definition TTime.h:85
void * GetAddress(CPPInstance *pyobj)
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
PyObject * gDispGet
Definition PyStrings.cxx:69
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition Utility.cxx:808
std::string ConstructTemplateArgs(PyObject *pyname, PyObject *tpArgs, PyObject *args=nullptr, ArgPreference=kNone, int argoff=0, int *pcnt=nullptr)
Definition Utility.cxx:580
bool InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
Definition Utility.cxx:788
PyTypeObject CPPInstance_Type
PyObject * gAbrtException
PyObject * gDefaultObject
bool gDictLookupActive
Definition Utility.cxx:28
PyTypeObject VectorIter_Type
PyTypeObject CPPExcInstance_Type
PyObject * GetScopeProxy(Cppyy::TCppScope_t)
std::ostringstream gCapturedError
dict_lookup_func gDictLookupOrg
Definition Utility.cxx:27
PyTypeObject CustomInstanceMethod_Type
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
bool CPPDataMember_CheckExact(T *object)
PyTypeObject RefFloat_Type
Custom "builtins," detectable by type, for pass by ref and improved performance.
PyObject * gSegvException
std::set< Cppyy::TCppType_t > gPinnedTypes
PyObject * DestroyPyStrings()
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
std::map< std::string, std::vector< PyObject * > > & pythonizations()
bool CPPScope_Check(T *object)
Definition CPPScope.h:81
bool CreatePyStrings()
Definition PyStrings.cxx:84
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
Definition API.cxx:121
bool CPPInstance_Check(T *object)
PyTypeObject IndexIter_Type
PyObject * gNullPtrObject
PyTypeObject CPPOverload_Type
PyTypeObject TemplateProxy_Type
PyObject * gThisModule
Definition CPPMethod.cxx:30
PyTypeObject InstanceArrayIter_Type
bool CPPDataMember_Check(T *object)
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
Definition API.cxx:106
PyTypeObject CPPScope_Type
Definition CPPScope.cxx:645
PyObject * gIllException
PyTypeObject LowLevelView_Type
PyObject * gPyTypeMap
bool CPPOverload_CheckExact(T *object)
Definition CPPOverload.h:96
PyTypeObject CPPDataMember_Type
PyObject * gBusException
std::streambuf * gOldErrorBuffer
PyTypeObject TupleOfInstances_Type
Representation of C-style array of instances.
PyTypeObject RefInt_Type
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 void AddSmartPtrType(const std::string &)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
void * TCppObject_t
Definition cpp_cppyy.h:21
TCppScope_t TCppType_t
Definition cpp_cppyy.h:19
RPY_EXPORTED void AddTypeReducer(const std::string &reducable, const std::string &reduced)
RPY_EXPORTED bool IsAggregate(TCppType_t type)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
void * TCppFuncAddr_t
Definition cpp_cppyy.h:25
void(off) SmallVectorTemplateBase< T
static ECallFlags sMemoryPolicy
Definition CallContext.h:78
static bool SetGlobalSignalPolicy(bool setProtected)
static bool SetMemoryPolicy(ECallFlags e)
PyObject_HEAD char * b_ptr
PyObject * error
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4