Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Utility.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "Utility.h"
4#include "CPPFunction.h"
5#include "CPPInstance.h"
6#include "CPPOverload.h"
7#include "ProxyWrappers.h"
8#include "PyCallable.h"
9#include "PyStrings.h"
10#include "CustomPyTypes.h"
11#include "TemplateProxy.h"
12#include "TypeManip.h"
13
14// Standard
15#include <limits.h>
16#include <string.h>
17#include <algorithm>
18#include <list>
19#include <mutex>
20#include <set>
21#include <sstream>
22#include <utility>
23
24
25//- data _____________________________________________________________________
26#if PY_VERSION_HEX < 0x030b0000
29#endif
30
31typedef std::map<std::string, std::string> TC2POperatorMapping_t;
33static std::set<std::string> gOpSkip;
34static std::set<std::string> gOpRemove;
35
36namespace CPyCppyy {
37// special objects
40}
41
42namespace {
43
44 using namespace CPyCppyy::Utility;
45
46 struct InitOperatorMapping_t {
47 public:
48 InitOperatorMapping_t() {
49 // Initialize the global map of operator names C++ -> python.
50
51 gOpSkip.insert("[]"); // __s/getitem__, depends on return type
52 gOpSkip.insert("+"); // __add__, depends on # of args (see __pos__)
53 gOpSkip.insert("-"); // __sub__, id. (eq. __neg__)
54 gOpSkip.insert("*"); // __mul__ or __deref__
55 gOpSkip.insert("++"); // __postinc__ or __preinc__
56 gOpSkip.insert("--"); // __postdec__ or __predec__
57
58 gOpRemove.insert("new"); // this and the following not handled at all
59 gOpRemove.insert("new[]");
60 gOpRemove.insert("delete");
61 gOpRemove.insert("delete[]");
62
63 gC2POperatorMapping["[]"] = "__getitem__";
64 gC2POperatorMapping["()"] = "__call__";
65 gC2POperatorMapping["%"] = "__mod__";
66 gC2POperatorMapping["**"] = "__pow__";
67 gC2POperatorMapping["<<"] = "__lshift__";
68 gC2POperatorMapping[">>"] = "__rshift__";
69 gC2POperatorMapping["&"] = "__and__";
70 gC2POperatorMapping["&&"] = "__dand__";
71 gC2POperatorMapping["|"] = "__or__";
72 gC2POperatorMapping["||"] = "__dor__";
73 gC2POperatorMapping["^"] = "__xor__";
74 gC2POperatorMapping["~"] = "__invert__";
75 gC2POperatorMapping[","] = "__comma__";
76 gC2POperatorMapping["+="] = "__iadd__";
77 gC2POperatorMapping["-="] = "__isub__";
78 gC2POperatorMapping["*="] = "__imul__";
80 gC2POperatorMapping["%="] = "__imod__";
81 gC2POperatorMapping["**="] = "__ipow__";
82 gC2POperatorMapping["<<="] = "__ilshift__";
83 gC2POperatorMapping[">>="] = "__irshift__";
84 gC2POperatorMapping["&="] = "__iand__";
85 gC2POperatorMapping["|="] = "__ior__";
86 gC2POperatorMapping["^="] = "__ixor__";
87 gC2POperatorMapping["=="] = "__eq__";
88 gC2POperatorMapping["!="] = "__ne__";
89 gC2POperatorMapping[">"] = "__gt__";
90 gC2POperatorMapping["<"] = "__lt__";
91 gC2POperatorMapping[">="] = "__ge__";
92 gC2POperatorMapping["<="] = "__le__";
93
94 // the following type mappings are "exact"
95 gC2POperatorMapping["const char*"] = "__str__";
96 gC2POperatorMapping["char*"] = "__str__";
97 gC2POperatorMapping["const char *"] = gC2POperatorMapping["const char*"];
98 gC2POperatorMapping["char *"] = gC2POperatorMapping["char*"];
99 gC2POperatorMapping["int"] = "__int__";
101 gC2POperatorMapping["double"] = "__float__";
102
103 // the following type mappings are "okay"; the assumption is that they
104 // are not mixed up with the ones above or between themselves (and if
105 // they are, that it is done consistently)
106 gC2POperatorMapping["short"] = "__int__";
107 gC2POperatorMapping["unsigned short"] = "__int__";
108 gC2POperatorMapping["unsigned int"] = CPPYY__long__;
109 gC2POperatorMapping["unsigned long"] = CPPYY__long__;
110 gC2POperatorMapping["long long"] = CPPYY__long__;
111 gC2POperatorMapping["unsigned long long"] = CPPYY__long__;
112 gC2POperatorMapping["float"] = "__float__";
113
114 gC2POperatorMapping["->"] = "__follow__"; // not an actual python operator
115 gC2POperatorMapping["="] = "__assign__"; // id.
116
117#if PY_VERSION_HEX < 0x03000000
118 gC2POperatorMapping["bool"] = "__cpp_nonzero__";
119#else
120 gC2POperatorMapping["bool"] = "__cpp_bool__";
121#endif
122 }
124
125 inline std::string full_scope(const std::string& tpname) {
126 return tpname[0] == ':' ? tpname : "::"+tpname;
127 }
128
129} // unnamed namespace
130
131
132//- public functions ---------------------------------------------------------
134{
135// Convert <pybject> to C++ unsigned long, with bounds checking, allow int -> ulong.
136 if (PyFloat_Check(pyobject)) {
137 PyErr_SetString(PyExc_TypeError, "can\'t convert float to unsigned long");
138 return (unsigned long)-1;
139 } else if (pyobject == CPyCppyy::gDefaultObject) {
140 return (unsigned long)0;
141 }
142
143 unsigned long ul = PyLong_AsUnsignedLong(pyobject);
145 PyErr_Clear();
146 long i = PyInt_AS_LONG(pyobject);
147 if (0 <= i) {
148 ul = (unsigned long)i;
149 } else {
151 "can\'t convert negative value to unsigned long");
152 return (unsigned long)-1;
153 }
154 }
155
156 return ul;
157}
158
159//----------------------------------------------------------------------------
161{
162// Convert <pyobject> to C++ unsigned long long, with bounds checking.
163 if (PyFloat_Check(pyobject)) {
164 PyErr_SetString(PyExc_TypeError, "can\'t convert float to unsigned long long");
165 return -1;
166 } else if (pyobject == CPyCppyy::gDefaultObject) {
167 return (unsigned long)0;
168 }
169
172 PyErr_Clear();
173 long i = PyInt_AS_LONG(pyobject);
174 if (0 <= i) {
175 ull = (PY_ULONG_LONG)i;
176 } else {
178 "can\'t convert negative value to unsigned long long");
179 }
180 }
181
182 return ull;
183}
184
185//----------------------------------------------------------------------------
187 PyObject* pyclass, const char* label, PyCFunction cfunc, int flags)
188{
189// Add the given function to the class under name 'label'.
190
191// use list for clean-up (.so's are unloaded only at interpreter shutdown)
192 static std::list<PyMethodDef> s_pymeths;
193
194 s_pymeths.push_back(PyMethodDef());
195 PyMethodDef* pdef = &s_pymeths.back();
196 pdef->ml_name = const_cast<char*>(label);
197 pdef->ml_meth = cfunc;
198 pdef->ml_flags = flags;
199 pdef->ml_doc = nullptr;
200
201 PyObject* func = PyCFunction_New(pdef, nullptr);
204 bool isOk = PyType_Type.tp_setattro(pyclass, name, method) == 0;
207 Py_DECREF(func);
208
209 if (PyErr_Occurred())
210 return false;
211
212 if (!isOk) {
213 PyErr_Format(PyExc_TypeError, "could not add method %s", label);
214 return false;
215 }
216
217 return true;
218}
219
220//----------------------------------------------------------------------------
221bool CPyCppyy::Utility::AddToClass(PyObject* pyclass, const char* label, const char* func)
222{
223// Add the given function to the class under name 'label'.
224 PyObject* pyfunc = PyObject_GetAttrString(pyclass, const_cast<char*>(func));
225 if (!pyfunc)
226 return false;
227
228 PyObject* pylabel = CPyCppyy_PyText_InternFromString(const_cast<char*>(label));
229 bool isOk = PyType_Type.tp_setattro(pyclass, pylabel, pyfunc) == 0;
231
233 return isOk;
234}
235
236//----------------------------------------------------------------------------
238{
239// Add the given function to the class under name 'label'.
241 (CPPOverload*)PyObject_GetAttrString(pyclass, const_cast<char*>(label));
242
243 if (!method || !CPPOverload_Check(method)) {
244 // not adding to existing CPPOverload; add callable directly to the class
245 if (PyErr_Occurred())
246 PyErr_Clear();
248 method = CPPOverload_New(label, pyfunc);
249 PyObject* pylabel = CPyCppyy_PyText_InternFromString(const_cast<char*>(label));
250 bool isOk = PyType_Type.tp_setattro(pyclass, pylabel, (PyObject*)method) == 0;
253 return isOk;
254 }
255
256 method->AdoptMethod(pyfunc);
257
259 return true;
260}
261
262
263//----------------------------------------------------------------------------
264static inline
265CPyCppyy::PyCallable* BuildOperator(const std::string& lcname, const std::string& rcname,
266 const char* op, Cppyy::TCppScope_t scope, bool reverse=false)
267{
268// Helper to find a function with matching signature in 'funcs'.
269 std::string opname = "operator";
270 opname += op;
271
273 if (idx == (Cppyy::TCppIndex_t)-1)
274 return nullptr;
275
277 if (!reverse)
278 return new CPyCppyy::CPPFunction(scope, meth);
280}
281
282//----------------------------------------------------------------------------
284{
285// Find a callable matching named operator (op) and klass arguments in the global
286// namespace or the klass' namespace.
287
289 return nullptr;
290
292 const std::string& lcname = Cppyy::GetScopedFinalName(klass->fCppType);
293 Cppyy::TCppScope_t scope = Cppyy::GetScope(TypeManip::extract_namespace(lcname));
294 return FindBinaryOperator(lcname, "", op, scope, false);
295}
296
297//----------------------------------------------------------------------------
299 const char* op, Cppyy::TCppScope_t scope)
300{
301// Find a callable matching the named operator (op) and the (left, right)
302// arguments in the global or these objects' namespaces.
303
304 bool reverse = false;
305 if (!CPPInstance_Check(left)) {
306 if (CPPInstance_Check(right))
307 reverse = true;
308 else
309 return nullptr;
310 }
311
312// retrieve the class names to match the signature of any found global functions
313 const std::string& lcname = ClassName(left);
314 const std::string& rcname = ClassName(right);
315 return FindBinaryOperator(lcname, rcname, op, scope, reverse);
316}
317
318//----------------------------------------------------------------------------
320 const std::string& lcname, const std::string& rcname,
321 const char* op, Cppyy::TCppScope_t scope, bool reverse)
322{
323// Find a global function with a matching signature; search __gnu_cxx, std::__1,
324// and __cppyy_internal pro-actively (as there's AFAICS no way to unearth 'using'
325// information).
326
327 if (rcname == "<unknown>" || lcname == "<unknown>")
328 return nullptr;
329
330 PyCallable* pyfunc = 0;
331
332 if (!scope) {
333 // TODO: the following should remain sync with what clingwrapper does in its
334 // type remapper; there must be a better way?
335 if (lcname == "str" || lcname == "unicode" || lcname == "complex")
336 scope = Cppyy::GetScope("std");
337 else scope = Cppyy::GetScope(TypeManip::extract_namespace(lcname));
338 }
339 if (scope)
340 pyfunc = BuildOperator(lcname, rcname, op, scope, reverse);
341
342 if (!pyfunc && scope != Cppyy::gGlobalScope) // search in global scope anyway
344
345 if (!pyfunc) {
346 // For GNU on clang, search the internal __gnu_cxx namespace for binary operators (is
347 // typically the case for STL iterators operator==/!=.
348 // TODO: only look in __gnu_cxx for iterators (and more generally: do lookups in the
349 // namespace where the class is defined
350 static Cppyy::TCppScope_t gnucxx = Cppyy::GetScope("__gnu_cxx");
351 if (gnucxx)
352 pyfunc = BuildOperator(lcname, rcname, op, gnucxx, reverse);
353 }
354
355 if (!pyfunc) {
356 // Same for clang (on Mac only?). TODO: find proper pre-processor magic to only use those
357 // specific namespaces that are actually around; although to be sure, this isn't expensive.
358 static Cppyy::TCppScope_t std__1 = Cppyy::GetScope("std::__1");
359
360 if (std__1
362 && lcname.find("__wrap_iter") == std::string::npos // wrapper call does not compile
363#endif
364 ) {
365 pyfunc = BuildOperator(lcname, rcname, op, std__1, reverse);
366 }
367 }
368
369 if (!pyfunc) {
370 // One more, mostly for Mac, but again not sure whether this is not a general issue. Some
371 // operators are declared as friends only in classes, so then they're not found in the
372 // global namespace, so this helper let's the compiler resolve the operator.
373 static Cppyy::TCppScope_t s_intern = Cppyy::GetScope("__cppyy_internal");
374 if (s_intern) {
375 std::stringstream fname, proto;
376 if (strncmp(op, "==", 2) == 0) { fname << "is_equal<"; }
377 else if (strncmp(op, "!=", 2) == 0) { fname << "is_not_equal<"; }
378 else { fname << "not_implemented<"; }
379 fname << lcname << ", " << rcname << ">";
380 proto << "const " << lcname << "&, const " << rcname;
383 }
384 }
385
386 return pyfunc;
387}
388
389//----------------------------------------------------------------------------
390static inline std::string AnnotationAsText(PyObject* pyobj)
391{
394 if (!pystr) {
395 PyErr_Clear();
397 }
398
399 std::string str = CPyCppyy_PyText_AsString(pystr);
401 return str;
402 }
404}
405
406static bool AddTypeName(std::string& tmpl_name, PyObject* tn, PyObject* arg,
408{
409// Determine the appropriate C++ type for a given Python type; this is a helper because
410// it can recurse if the type is list or tuple and needs matching on std::vector.
411 using namespace CPyCppyy;
412 using namespace CPyCppyy::Utility;
413
414 if (tn == (PyObject*)&PyInt_Type) {
415 if (arg) {
416#if PY_VERSION_HEX < 0x03000000
417 long l = PyInt_AS_LONG(arg);
418 tmpl_name.append((l < INT_MIN || INT_MAX < l) ? "long" : "int");
419#else
421 if (ll == (PY_LONG_LONG)-1 && PyErr_Occurred()) {
422 PyErr_Clear();
424 if (ull == (PY_ULONG_LONG)-1 && PyErr_Occurred()) {
425 PyErr_Clear();
426 tmpl_name.append("int"); // still out of range, will fail later
427 } else
428 tmpl_name.append("unsigned long long"); // since already failed long long
429 } else
430 tmpl_name.append((ll < INT_MIN || INT_MAX < ll) ? \
431 ((ll < LONG_MIN || LONG_MAX < ll) ? "long long" : "long") : "int");
432#endif
433 } else
434 tmpl_name.append("int");
435
436 return true;
437 }
438
439#if PY_VERSION_HEX < 0x03000000
440 if (tn == (PyObject*)&PyLong_Type) {
441 if (arg) {
443 if (ll == (PY_LONG_LONG)-1 && PyErr_Occurred()) {
444 PyErr_Clear();
446 if (ull == (PY_ULONG_LONG)-1 && PyErr_Occurred()) {
447 PyErr_Clear();
448 tmpl_name.append("long"); // still out of range, will fail later
449 } else
450 tmpl_name.append("unsigned long long"); // since already failed long long
451 } else
452 tmpl_name.append((ll < LONG_MIN || LONG_MAX < ll) ? "long long" : "long");
453 } else
454 tmpl_name.append("long");
455
456 return true;
457 }
458#endif
459
460 if (tn == (PyObject*)&PyFloat_Type) {
461 // special case for floats (Python-speak for double) if from argument (only)
462 tmpl_name.append(arg ? "double" : "float");
463 return true;
464 }
465
466#if PY_VERSION_HEX < 0x03000000
467 if (tn == (PyObject*)&PyString_Type) {
468#else
469 if (tn == (PyObject*)&PyUnicode_Type) {
470#endif
471 tmpl_name.append("std::string");
472 return true;
473 }
474
475 if (tn == (PyObject*)&PyList_Type || tn == (PyObject*)&PyTuple_Type) {
476 if (arg && PySequence_Size(arg)) {
477 std::string subtype{"std::initializer_list<"};
481 tmpl_name.append(subtype);
482 tmpl_name.append(">");
483 }
485 }
486
487 return true;
488 }
489
490 if (CPPScope_Check(tn)) {
492 if (arg) {
493 // try to specialize the type match for the given object
495 if (CPPInstance_Check(pyobj)) {
496 if (pyobj->fFlags & CPPInstance::kIsRValue)
497 tmpl_name.append("&&");
498 else {
499 if (pcnt) *pcnt += 1;
500 if ((pyobj->fFlags & CPPInstance::kIsReference) || pref == kPointer)
501 tmpl_name.push_back('*');
502 else if (pref != kValue)
503 tmpl_name.push_back('&');
504 }
505 }
506 }
507
508 return true;
509 }
510
511 if (tn == (PyObject*)&CPPOverload_Type) {
512 PyObject* tpName = arg ? \
513 PyObject_GetAttr(arg, PyStrings::gCppName) : \
514 CPyCppyy_PyText_FromString("void* (*)(...)");
517
518 return true;
519 }
520
521 if (arg && PyCallable_Check(arg)) {
522 // annotated/typed Python function
523 PyObject* annot = PyObject_GetAttr(arg, PyStrings::gAnnotations);
524 if (annot) {
525 if (PyDict_Check(annot) && 1 < PyDict_Size(annot)) {
527 if (ret) {
528 // dict is ordered, with the last value being the return type
529 std::ostringstream tpn;
530 tpn << (CPPScope_Check(ret) ? ClassName(ret) : AnnotationAsText(ret))
531 << " (*)(";
532
533 PyObject* values = PyDict_Values(annot);
534 for (Py_ssize_t i = 0; i < (PyList_GET_SIZE(values)-1); ++i) {
535 if (i) tpn << ", ";
536 PyObject* item = PyList_GET_ITEM(values, i);
537 tpn << (CPPScope_Check(item) ? full_scope(ClassName(item)) : AnnotationAsText(item));
538 }
539 Py_DECREF(values);
540
541 tpn << ')';
542 tmpl_name.append(tpn.str());
543
545 return true;
546
547 } else
548 PyErr_Clear();
549 }
551 } else
552 PyErr_Clear();
553
554 // ctypes function pointer
555 PyObject* argtypes = nullptr;
556 PyObject* ret = nullptr;
557 if ((argtypes = PyObject_GetAttrString(arg, "argtypes")) && (ret = PyObject_GetAttrString(arg, "restype"))) {
558 std::ostringstream tpn;
559 PyObject* pytc = PyObject_GetAttr(ret, PyStrings::gCTypesType);
560 tpn << CT2CppNameS(pytc, false)
561 << " (*)(";
563
564 for (Py_ssize_t i = 0; i < PySequence_Length(argtypes); ++i) {
565 if (i) tpn << ", ";
567 pytc = PyObject_GetAttr(item, PyStrings::gCTypesType);
568 tpn << CT2CppNameS(pytc, false);
571 }
572
573 tpn << ')';
574 tmpl_name.append(tpn.str());
575
576 Py_DECREF(ret);
578
579 return true;
580
581 } else {
582 PyErr_Clear();
585 }
586
587 // callable C++ type (e.g. std::function)
588 PyObject* tpName = PyObject_GetAttr(arg, PyStrings::gCppName);
589 if (tpName) {
591 tmpl_name.append(CPPScope_Check(arg) ? full_scope(cname) : cname);
593 return true;
594 }
595 PyErr_Clear();
596 }
597
598 for (auto nn : {PyStrings::gCppName, PyStrings::gName}) {
600 if (tpName) {
603 return true;
604 }
605 PyErr_Clear();
606 }
607
609 // last ditch attempt, works for things like int values; since this is a
610 // source of errors otherwise, it is limited to specific types and not
611 // generally used (str(obj) can print anything ...)
615 return true;
616 }
617
618 return false;
619}
620
623{
624// Helper to construct the "<type, type, ...>" part of a templated name (either
625// for a class or method lookup
627
628// Note: directly appending to string is a lot faster than stringstream
629 std::string tmpl_name;
630 tmpl_name.reserve(128);
631 if (pyname)
633 tmpl_name.push_back('<');
634
635 if (pcnt) *pcnt = 0; // count number of times 'pref' is used
636
638 for (int i = argoff; i < nArgs; ++i) {
639 // add type as string to name
643 // some common numeric types (separated out for performance: checking for
644 // __cpp_name__ and/or __name__ is rather expensive)
645 } else {
646 if (!AddTypeName(tmpl_name, tn, (args ? PyTuple_GET_ITEM(args, i) : nullptr), pref, pcnt)) {
648 "could not construct C++ name from provided template argument.");
649 return "";
650 }
651 }
652
653 // add a comma, as needed (no space as internally, final names don't have them)
654 if (i != nArgs-1)
655 tmpl_name.push_back(',');
656 }
657
658// close template name
659 tmpl_name.push_back('>');
660
661 return tmpl_name;
662}
663
664//----------------------------------------------------------------------------
666{
667// helper to convert ctypes' `_type_` info to the equivalent C++ name
668 const char* name = "";
670 char tc = ((char*)CPyCppyy_PyText_AsString(pytc))[0];
671 switch (tc) {
672 case '?': name = "bool"; break;
673 case 'c': name = "char"; break;
674 case 'b': name = "char"; break;
675 case 'B': name = "unsigned char"; break;
676 case 'h': name = "short"; break;
677 case 'H': name = "unsigned short"; break;
678 case 'i': name = "int"; break;
679 case 'I': name = "unsigned int"; break;
680 case 'l': name = "long"; break;
681 case 'L': name = "unsigned long"; break;
682 case 'q': name = "long long"; break;
683 case 'Q': name = "unsigned long long"; break;
684 case 'f': name = "float"; break;
685 case 'd': name = "double"; break;
686 case 'g': name = "long double"; break;
687 case 'z': name = "const char*"; break;
688 default: name = (allow_voidp ? "void*" : nullptr); break;
689 }
690 }
691
692 return name;
693}
694
695//----------------------------------------------------------------------------
696static inline bool check_scope(const std::string& name)
697{
699}
700
702 const std::vector<std::string>& argtypes, std::ostringstream& code)
703{
704// Generate function setup to be used in callbacks (wrappers and overrides).
705 int nArgs = (int)argtypes.size();
706
707// return value and argument type converters
708 bool isVoid = retType == "void";
709 if (!isVoid)
710 code << " CPYCPPYY_STATIC std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>> "
711 "retconv{CPyCppyy::CreateConverter(\""
712 << retType << "\"), CPyCppyy::DestroyConverter};\n";
713 std::vector<bool> arg_is_ptr;
714 if (nArgs) {
715 arg_is_ptr.resize(nArgs);
716 code << " CPYCPPYY_STATIC std::vector<std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>>> argcvs;\n"
717 << " if (argcvs.empty()) {\n"
718 << " argcvs.reserve(" << nArgs << ");\n";
719 for (int i = 0; i < nArgs; ++i) {
720 arg_is_ptr[i] = false;
721 code << " argcvs.emplace_back(CPyCppyy::CreateConverter(\"";
722 const std::string& at = argtypes[i];
723 const std::string& res_at = Cppyy::ResolveName(at);
724 const std::string& cpd = TypeManip::compound(res_at);
725 if (!cpd.empty() && check_scope(res_at)) {
726 // in case of a pointer, the original argument needs to be used to ensure
727 // the pointer-value remains comparable
728 //
729 // in case of a reference, there is no extra indirection on the C++ side as
730 // would be when converting a data member, so adjust the converter
731 arg_is_ptr[i] = cpd.back() == '*';
732 if (arg_is_ptr[i] || cpd.back() == '&') {
733 code << res_at.substr(0, res_at.size()-1);
734 } else code << at;
735 } else
736 code << at;
737 code << "\"), CPyCppyy::DestroyConverter);\n";
738 }
739 code << " }\n";
740 }
741
742// declare return value (TODO: this does not work for most non-builtin values)
743 if (!isVoid)
744 code << " " << retType << " ret{};\n";
745
746// acquire GIL
747 code << " PyGILState_STATE state = PyGILState_Ensure();\n";
748
749// build argument tuple if needed
750 if (nArgs) {
751 code << " std::vector<PyObject*> pyargs;\n";
752 code << " pyargs.reserve(" << nArgs << ");\n"
753 << " try {\n";
754 for (int i = 0; i < nArgs; ++i) {
755 code << " pyargs.emplace_back(argcvs[" << i << "]->FromMemory((void*)";
756 if (!arg_is_ptr[i]) code << '&';
757 code << "arg" << i << "));\n"
758 << " if (!pyargs.back()) throw " << i << ";\n";
759 }
760 code << " } catch(int) {\n"
761 << " for (auto pyarg : pyargs) Py_XDECREF(pyarg);\n"
762 << " CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc;\n"
763 << " }\n";
764 }
765}
766
767void CPyCppyy::Utility::ConstructCallbackReturn(const std::string& retType, int nArgs, std::ostringstream& code)
768{
769// Generate code for return value conversion and error handling.
770 bool isVoid = retType == "void";
771 bool isPtr = Cppyy::ResolveName(retType).back() == '*';
772
773 if (nArgs)
774 code << " for (auto pyarg : pyargs) Py_DECREF(pyarg);\n";
775 code << " bool cOk = (bool)pyresult;\n"
776 " if (pyresult) {\n";
777 if (isPtr) {
778 // If the return type is a CPPInstance, owned by Python, and the ref-count down
779 // to 1, the return will hold a dangling pointer, so set it to nullptr instead.
780 code << " if (!CPyCppyy::Instance_IsLively(pyresult))\n"
781 " ret = nullptr;\n"
782 " else {\n";
783 }
784 code << (isVoid ? "" : " cOk = retconv->ToMemory(pyresult, (void*)&ret);\n")
785 << " Py_DECREF(pyresult);\n }\n";
786 if (isPtr) code << " }\n";
787 code << " if (!cOk) {" // assume error set when converter failed
788// TODO: On Windows, throwing a C++ exception here makes the code hang; leave
789// the error be which allows at least one layer of propagation
790#ifdef _WIN32
791 " /* do nothing */ }\n"
792#else
793 " CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc; }\n"
794#endif
795 " PyGILState_Release(state);\n"
796 " return";
797 code << (isVoid ? ";\n }\n" : " ret;\n }\n");
798}
799
800
801//----------------------------------------------------------------------------
802static std::map<void*, PyObject*> sStdFuncLookup;
803static std::map<std::string, PyObject*> sStdFuncMakerLookup;
805 const std::string& retType, const std::string& signature, void* address)
806{
807// Convert a function pointer to an equivalent std::function<> object.
808 static int maker_count = 0;
809
810 auto pf = sStdFuncLookup.find(address);
811 if (pf != sStdFuncLookup.end()) {
812 Py_INCREF(pf->second);
813 return pf->second;
814 }
815
816 PyObject* maker = nullptr;
817
819 if (pm == sStdFuncMakerLookup.end()) {
820 std::ostringstream fname;
821 fname << "ptr2func" << ++maker_count;
822
823 std::ostringstream code;
824 code << "namespace __cppyy_internal { std::function<"
825 << retType << signature << "> " << fname.str()
826 << "(intptr_t faddr) { return (" << retType << "(*)" << signature << ")faddr;} }";
827
828 if (!Cppyy::Compile(code.str())) {
829 PyErr_SetString(PyExc_TypeError, "conversion to std::function failed");
830 return nullptr;
831 }
832
833 PyObject* pyscope = CreateScopeProxy("__cppyy_internal");
834 maker = PyObject_GetAttrString(pyscope, fname.str().c_str());
836 if (!maker)
837 return nullptr;
838
839 // cache the new maker (TODO: does it make sense to use weakrefs?)
841 } else
842 maker = pm->second;
843
844 PyObject* args = PyTuple_New(1);
845 PyTuple_SET_ITEM(args, 0, PyLong_FromLongLong((intptr_t)address));
846 PyObject* func = PyObject_Call(maker, args, NULL);
847 Py_DECREF(args);
848
849 if (func) { // prevent moving this func object, since then it can not be reused
850 ((CPPInstance*)func)->fFlags |= CPPInstance::kIsLValue;
851 Py_INCREF(func); // TODO: use weak? The C++ maker doesn't go away either
852 sStdFuncLookup[address] = func;
853 }
854
855 return func;
856}
857
858
859//----------------------------------------------------------------------------
861{
862// Initialize a proxy class for use by python, and add it to the module.
863
864// finalize proxy type
865 if (PyType_Ready(pytype) < 0)
866 return false;
867
868// add proxy type to the given module
869 Py_INCREF(pytype); // PyModule_AddObject steals reference
870 if (PyModule_AddObject(module, (char*)name, (PyObject*)pytype) < 0) {
872 return false;
873 }
874
875// declare success
876 return true;
877}
878
879//----------------------------------------------------------------------------
881{
882// Retrieve a linear buffer pointer from the given pyobject.
883
884// special case: don't handle character strings here (yes, they're buffers, but not quite)
886 return 0;
887
888// special case: bytes array
889 if ((!check || tc == '*' || tc == 'B') && PyByteArray_CheckExact(pyobject)) {
892 }
893
894// new-style buffer interface
897 return 0; // PyObject_GetBuffer() crashes on some platforms for some zero-sized seqeunces
898 PyErr_Clear();
900 memset(&bufinfo, 0, sizeof(Py_buffer));
902 if (tc == '*' || strchr(bufinfo.format, tc)
903 // if `long int` and `int` are the same size (on Windows and 32bit Linux,
904 // for example), `ctypes` isn't too picky about the type format, so make
905 // sure both integer types pass the type check
906 || (sizeof(long int) == sizeof(int) && ((tc == 'I' && strchr(bufinfo.format, 'L')) ||
907 (tc == 'i' && strchr(bufinfo.format, 'l'))))
908 // complex float is 'Zf' in bufinfo.format, but 'z' in single char
909 || (tc == 'z' && strstr(bufinfo.format, "Zf"))
910 // allow 'signed char' ('b') from array to pass through '?' (bool as from struct)
911 || (tc == '?' && strchr(bufinfo.format, 'b'))
912 ) {
913 buf = bufinfo.buf;
914
915 if (check && bufinfo.itemsize != size) {
917 "buffer itemsize (%ld) does not match expected size (%d)", bufinfo.itemsize, size);
919 return 0;
920 }
921
922 Py_ssize_t buflen = 0;
923 if (buf && bufinfo.ndim == 0)
924 buflen = bufinfo.len/bufinfo.itemsize;
925 else if (buf && bufinfo.ndim == 1)
926 buflen = bufinfo.shape ? bufinfo.shape[0] : bufinfo.len/bufinfo.itemsize;
928 if (buflen)
929 return buflen;
930 } else {
931 // have buf, but format mismatch: bail out now, otherwise the old
932 // code will return based on itemsize match
934 return 0;
935 }
936 } else if (bufinfo.obj)
938 PyErr_Clear();
939 }
940
941// attempt to retrieve pointer through old-style buffer interface
942 PyBufferProcs* bufprocs = Py_TYPE(pyobject)->tp_as_buffer;
943
944 PySequenceMethods* seqmeths = Py_TYPE(pyobject)->tp_as_sequence;
945 if (seqmeths != 0 && bufprocs != 0
946#if PY_VERSION_HEX < 0x03000000
947 && bufprocs->bf_getwritebuffer != 0
948 && (*(bufprocs->bf_getsegcount))(pyobject, 0) == 1
949#else
950 && bufprocs->bf_getbuffer != 0
951#endif
952 ) {
953
954 // get the buffer
955#if PY_VERSION_HEX < 0x03000000
956 Py_ssize_t buflen = (*(bufprocs->bf_getwritebuffer))(pyobject, 0, &buf);
957#else
959 (*(bufprocs->bf_getbuffer))(pyobject, &bufinfo, PyBUF_WRITABLE);
960 buf = (char*)bufinfo.buf;
961 Py_ssize_t buflen = bufinfo.len;
963#endif
964
965 if (buf && check == true) {
966 // determine buffer compatibility (use "buf" as a status flag)
967 PyObject* pytc = tc != '*' ? PyObject_GetAttr(pyobject, PyStrings::gTypeCode) : nullptr;
968 if (pytc != 0) { // for array objects
970 if (!(cpytc == tc || (tc == '?' && cpytc == 'b')))
971 buf = 0; // no match
973 } else if (seqmeths->sq_length &&
974 (int)(buflen/(*(seqmeths->sq_length))(pyobject)) == size) {
975 // this is a gamble ... may or may not be ok, but that's for the user
976 PyErr_Clear();
977 } else if (buflen == size) {
978 // also a gamble, but at least 1 item will fit into the buffer, so very likely ok ...
979 PyErr_Clear();
980 } else {
981 buf = 0; // not compatible
982
983 // clarify error message
984 auto error = FetchPyError();
986 (char*)"%s and given element size (%ld) do not match needed (%d)",
987 CPyCppyy_PyText_AsString(error.fValue.get()),
988 seqmeths->sq_length ? (long)(buflen/(*(seqmeths->sq_length))(pyobject)) : (long)buflen,
989 size);
990 error.fValue.reset(pyvalue2);
991 RestorePyError(error);
992 }
993 }
994
995 if (!buf) return 0;
996 return buflen/(size ? size : 1);
997 }
998
999 return 0;
1000}
1001
1002//----------------------------------------------------------------------------
1003std::string CPyCppyy::Utility::MapOperatorName(const std::string& name, bool bTakesParams, bool* stubbed)
1004{
1005// Map the given C++ operator name on the python equivalent.
1006 if (8 < name.size() && name.substr(0, 8) == "operator") {
1007 std::string op = name.substr(8, std::string::npos);
1008
1009 // stripping ...
1010 std::string::size_type start = 0, end = op.size();
1011 while (start < end && isspace(op[start])) ++start;
1012 while (start < end && isspace(op[end-1])) --end;
1013 op = op.substr(start, end - start);
1014
1015 // certain operators should be removed completely (e.g. operator delete & friends)
1016 if (gOpRemove.find(op) != gOpRemove.end())
1017 return "";
1018
1019 // check first if none, to prevent spurious deserializing downstream
1020 TC2POperatorMapping_t::iterator pop = gC2POperatorMapping.find(op);
1021 if (pop == gC2POperatorMapping.end() && gOpSkip.find(op) == gOpSkip.end()) {
1023 pop = gC2POperatorMapping.find(op);
1024 }
1025
1026 // map C++ operator to python equivalent, or made up name if no equivalent exists
1027 if (pop != gC2POperatorMapping.end()) {
1028 return pop->second;
1029
1030 } else if (op == "*") {
1031 // dereference v.s. multiplication of two instances
1032 if (!bTakesParams) return "__deref__";
1033 if (stubbed) *stubbed = true;
1034 return "__mul__";
1035
1036 } else if (op == "/") {
1037 // no unary, but is stubbed
1038 return CPPYY__div__;
1039
1040 } else if (op == "+") {
1041 // unary positive v.s. addition of two instances
1042 if (!bTakesParams) return "__pos__";
1043 if (stubbed) *stubbed = true;
1044 return "__add__";
1045
1046 } else if (op == "-") {
1047 // unary negative v.s. subtraction of two instances
1048 if (!bTakesParams) return "__neg__";
1049 if (stubbed) *stubbed = true;
1050 return "__sub__";
1051
1052 } else if (op == "++") {
1053 // prefix v.s. postfix increment
1054 return bTakesParams ? "__postinc__" : "__preinc__";
1055
1056 } else if (op == "--") {
1057 // prefix v.s. postfix decrement
1058 return bTakesParams ? "__postdec__" : "__predec__";
1059 }
1060
1061 }
1062
1063// might get here, as not all operator methods are handled (new, delete, etc.)
1064 return name;
1065}
1066
1067//----------------------------------------------------------------------------
1069{
1070// Retrieve the class name from the given Python instance.
1071 std::string clname = "<unknown>";
1073 PyObject* pyname = PyObject_GetAttr(pyclass, PyStrings::gCppName);
1074 if (!pyname) {
1075 PyErr_Clear();
1076 pyname = PyObject_GetAttr(pyclass, PyStrings::gName);
1077 }
1078
1079 if (pyname) {
1082 } else
1083 PyErr_Clear();
1084 return clname;
1085}
1086
1087//----------------------------------------------------------------------------
1088static std::set<std::string> sIteratorTypes;
1089bool CPyCppyy::Utility::IsSTLIterator(const std::string& classname)
1090{
1091// attempt to recognize STL iterators (TODO: probably belongs in the backend), using
1092// a couple of common container classes with different iterator protocols (note that
1093// mapping iterators are handled separately in the pythonizations) as exemplars (the
1094// actual, resolved, names will be compiler-specific) that are picked b/c they are
1095// baked into the CoreLegacy dictionary
1096 if (sIteratorTypes.empty()) {
1097 std::string tt = "<int>::";
1098 for (auto c : {"std::vector", "std::list", "std::deque"}) {
1099 for (auto i : {"iterator", "const_iterator"}) {
1100 const std::string& itname = Cppyy::ResolveName(c+tt+i);
1101 auto pos = itname.find('<');
1102 if (pos != std::string::npos)
1103 sIteratorTypes.insert(itname.substr(0, pos));
1104 }
1105 }
1106 }
1107
1108 auto pos = classname.find('<');
1109 if (pos != std::string::npos)
1110 return sIteratorTypes.find(classname.substr(0, pos)) != sIteratorTypes.end();
1111 return false;
1112}
1113
1114
1115//----------------------------------------------------------------------------
1126
1127
1128//----------------------------------------------------------------------------
1130{
1131// Re-acquire the GIL before calling PyErr_Occurred() in case it has been
1132// released; note that the p2.2 code assumes that there are no callbacks in
1133// C++ to python (or at least none returning errors).
1134#if PY_VERSION_HEX >= 0x02030000
1135 PyGILState_STATE gstate = PyGILState_Ensure();
1138#else
1139 if (PyThreadState_GET())
1140 return PyErr_Occurred();
1141 PyObject* e = 0;
1142#endif
1143
1144 return e;
1145}
1146
1147
1148//----------------------------------------------------------------------------
1150{
1151 // create a PyError_t RAII object that will capture and store the exception data
1153#if PY_VERSION_HEX >= 0x030c0000
1154 error.fValue.reset(PyErr_GetRaisedException());
1155#else
1156 PyObject *pytype = nullptr;
1157 PyObject *pyvalue = nullptr;
1158 PyObject *pytrace = nullptr;
1160 error.fType.reset(pytype);
1161 error.fValue.reset(pyvalue);
1162 error.fTrace.reset(pytrace);
1163#endif
1164 return error;
1165}
1166
1167
1168//----------------------------------------------------------------------------
1170{
1171#if PY_VERSION_HEX >= 0x030c0000
1172 PyErr_SetRaisedException(error.fValue.release());
1173#else
1174 PyErr_Restore(error.fType.release(), error.fValue.release(), error.fTrace.release());
1175#endif
1176}
1177
1178
1179//----------------------------------------------------------------------------
1180size_t CPyCppyy::Utility::FetchError(std::vector<PyError_t>& errors, bool is_cpp)
1181{
1182// Fetch the current python error, if any, and store it for future use.
1183 if (PyErr_Occurred()) {
1184 errors.emplace_back(FetchPyError());
1185 errors.back().fIsCpp = is_cpp;
1186 }
1187 return errors.size();
1188}
1189
1190//----------------------------------------------------------------------------
1192{
1193// Use the collected exceptions to build up a detailed error log.
1194 if (errors.empty()) {
1195 // should not happen ...
1198 return;
1199 }
1200
1201// if a _single_ exception was thrown from C++, assume it has priority (see below)
1202 PyError_t* unique_from_cpp = nullptr;
1203 for (auto& e : errors) {
1204 if (e.fIsCpp) {
1205 if (!unique_from_cpp)
1206 unique_from_cpp = &e;
1207 else {
1208 // two C++ exceptions, resort to default behavior
1209 unique_from_cpp = nullptr;
1210 break;
1211 }
1212 }
1213 }
1214
1215 if (unique_from_cpp) {
1216 // report only this error; the idea here is that all other errors come from
1217 // the bindings (e.g. argument conversion errors), while the exception from
1218 // C++ means that it originated from an otherwise successful call
1219
1220 // bind the original C++ object, rather than constructing from topmsg, as it
1221 // is expected to have informative state
1223 } else {
1224 // try to consolidate Python exceptions, otherwise select default
1225 PyObject* exc_type = nullptr;
1226 for (auto& e : errors) {
1227#if PY_VERSION_HEX >= 0x030c0000
1228 PyObject* pytype = (PyObject*)Py_TYPE(e.fValue.get());
1229#else
1230 PyObject* pytype = e.fType.get();
1231#endif
1232 if (!exc_type) exc_type = pytype;
1233 else if (exc_type != pytype) {
1234 exc_type = defexc;
1235 break;
1236 }
1237 }
1238
1239 // add the details to the topmsg
1240 PyObject* separator = CPyCppyy_PyText_FromString("\n ");
1241 for (auto& e : errors) {
1242 PyObject *pyvalue = e.fValue.get();
1243 CPyCppyy_PyText_Append(&topmsg, separator);
1246 } else if (pyvalue) {
1248 if (!excstr) {
1249 PyErr_Clear();
1251 }
1253 } else {
1255 CPyCppyy_PyText_FromString("unknown exception"));
1256 }
1257 }
1258
1259 Py_DECREF(separator);
1260
1261 // set the python exception
1263 }
1264
1266}
1267
1268
1269//----------------------------------------------------------------------------
1270static bool includesDone = false;
1272{
1273// setup Python API for callbacks
1274 if (!includesDone) {
1275 bool okay = Cppyy::Compile(
1276 // basic API (converters etc.)
1277 "#include \"CPyCppyy/API.h\"\n"
1278
1279 // utilities from the CPyCppyy public API
1280 "#include \"CPyCppyy/DispatchPtr.h\"\n"
1281 "#include \"CPyCppyy/PyException.h\"\n"
1282 );
1284 }
1285
1286 return includesDone;
1287}
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
#define CPPYY__long__
Definition CPyCppyy.h:109
#define CPPYY__div__
Definition CPyCppyy.h:111
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, long)
Definition CPyCppyy.h:44
#define CPyCppyy_PyText_InternFromString
Definition CPyCppyy.h:82
int Py_ssize_t
Definition CPyCppyy.h:215
#define PyBytes_Check
Definition CPyCppyy.h:61
#define CPyCppyy_PyText_Append
Definition CPyCppyy.h:83
#define CPyCppyy_PyText_AsString
Definition CPyCppyy.h:76
#define CPyCppyy_PyText_AppendAndDel
Definition CPyCppyy.h:84
void CPyCppyy_PyBuffer_Release(PyObject *, Py_buffer *view)
Definition CPyCppyy.h:282
#define CPyCppyy_PyText_FromFormat
Definition CPyCppyy.h:80
#define CPyCppyy_PyText_FromString
Definition CPyCppyy.h:81
#define CPPYY__idiv__
Definition CPyCppyy.h:110
#define CPyCppyy_PyText_Check
Definition CPyCppyy.h:74
unsigned long long PY_ULONG_LONG
Definition Cppyy.h:27
_object PyObject
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 cname
char name[80]
Definition TGX11.cxx:110
static std::set< std::string > sIteratorTypes
Definition Utility.cxx:1088
static bool includesDone
Definition Utility.cxx:1270
static TC2POperatorMapping_t gC2POperatorMapping
Definition Utility.cxx:32
static CPyCppyy::PyCallable * BuildOperator(const std::string &lcname, const std::string &rcname, const char *op, Cppyy::TCppScope_t scope, bool reverse=false)
Definition Utility.cxx:265
static std::set< std::string > gOpRemove
Definition Utility.cxx:34
static std::map< std::string, PyObject * > sStdFuncMakerLookup
Definition Utility.cxx:803
static std::set< std::string > gOpSkip
Definition Utility.cxx:33
static std::map< void *, PyObject * > sStdFuncLookup
Definition Utility.cxx:802
static bool AddTypeName(std::string &tmpl_name, PyObject *tn, PyObject *arg, CPyCppyy::Utility::ArgPreference pref, int *pcnt=nullptr)
Definition Utility.cxx:406
static bool check_scope(const std::string &name)
Definition Utility.cxx:696
std::map< std::string, std::string > TC2POperatorMapping_t
Definition Utility.cxx:31
static std::string AnnotationAsText(PyObject *pyobj)
Definition Utility.cxx:390
const char * proto
Definition civetweb.c:18822
const_iterator end() const
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
PyCallable * FindBinaryOperator(PyObject *left, PyObject *right, const char *op, Cppyy::TCppScope_t scope=0)
Definition Utility.cxx:298
std::string CT2CppNameS(PyObject *pytc, bool allow_voidp)
Definition Utility.cxx:665
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
Definition Utility.cxx:701
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
Definition Utility.cxx:767
void RestorePyError(PyError_t &error)
Definition Utility.cxx:1169
void SetDetailedException(std::vector< PyError_t > &&errors, PyObject *topmsg, PyObject *defexc)
Definition Utility.cxx:1191
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition Utility.cxx:880
std::string ConstructTemplateArgs(PyObject *pyname, PyObject *tpArgs, PyObject *args=nullptr, ArgPreference=kNone, int argoff=0, int *pcnt=nullptr)
Definition Utility.cxx:621
PyObject * FuncPtr2StdFunction(const std::string &retType, const std::string &signature, void *address)
Definition Utility.cxx:804
PyCallable * FindUnaryOperator(PyObject *pyclass, const char *op)
Definition Utility.cxx:283
size_t FetchError(std::vector< PyError_t > &, bool is_cpp=false)
Definition Utility.cxx:1180
std::string MapOperatorName(const std::string &name, bool bTakesParames, bool *stubbed=nullptr)
Definition Utility.cxx:1003
bool InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
Definition Utility.cxx:860
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
Definition Utility.cxx:186
PyError_t FetchPyError()
Definition Utility.cxx:1149
bool IsSTLIterator(const std::string &classname)
Definition Utility.cxx:1089
std::string ClassName(PyObject *pyobj)
Definition Utility.cxx:1068
PyObject * PyErr_Occurred_WithGIL()
Definition Utility.cxx:1129
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
unsigned long PyLongOrInt_AsULong(PyObject *pyobject)
Definition Utility.cxx:133
PyObject * gDefaultObject
PyObject * CustomInstanceMethod_New(PyObject *func, PyObject *self, PyObject *pyclass)
bool gDictLookupActive
Definition Utility.cxx:28
dict_lookup_func gDictLookupOrg
Definition Utility.cxx:27
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
bool CPPOverload_Check(T *object)
Definition CPPOverload.h:94
bool CPPScope_Check(T *object)
Definition CPPScope.h:81
PY_ULONG_LONG PyLongOrInt_AsULong64(PyObject *pyobject)
Definition Utility.cxx:160
bool CPPInstance_Check(T *object)
PyObject * gNullPtrObject
size_t TCppIndex_t
Definition cpp_cppyy.h:24
intptr_t TCppMethod_t
Definition cpp_cppyy.h:22
RPY_EXPORTED bool Compile(const std::string &code, bool silent=false)
RPY_EXPORTED TCppScope_t gGlobalScope
Definition cpp_cppyy.h:53
RPY_EXPORTED TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
size_t TCppScope_t
Definition cpp_cppyy.h:18
RPY_EXPORTED TCppIndex_t GetGlobalOperator(TCppType_t scope, const std::string &lc, const std::string &rc, const std::string &op)
std::unique_ptr< PyObject, PyObjectDeleter > fTrace
Definition Utility.h:104
std::unique_ptr< PyObject, PyObjectDeleter > fValue
Definition Utility.h:106
std::unique_ptr< PyObject, PyObjectDeleter > fType
Definition Utility.h:103
TLine l
Definition textangle.C:4
auto * tt
Definition textangle.C:16