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