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);
144 if (ul == (unsigned long)-1 && PyErr_Occurred() && PyInt_Check(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 if (ret) {
482 tmpl_name.append(subtype);
483 tmpl_name.append(">");
484 }
486 // Error occurred in inner call to AddTypeName, which means it has
487 // also set a TypeError. We return and let the error propagate.
488 if (!ret) {
489 return false;
490 }
491 }
492
493 return true;
494 }
495
496 if (CPPScope_Check(tn)) {
498 if (arg) {
499 // try to specialize the type match for the given object
501 if (CPPInstance_Check(pyobj)) {
502 if (pyobj->fFlags & CPPInstance::kIsRValue)
503 tmpl_name.append("&&");
504 else {
505 if (pcnt) *pcnt += 1;
506 if ((pyobj->fFlags & CPPInstance::kIsReference) || pref == kPointer)
507 tmpl_name.push_back('*');
508 else if (pref != kValue)
509 tmpl_name.push_back('&');
510 }
511 }
512 }
513
514 return true;
515 }
516
517 if (tn == (PyObject*)&CPPOverload_Type) {
518 PyObject* tpName = arg ? \
519 PyObject_GetAttr(arg, PyStrings::gCppName) : \
520 CPyCppyy_PyText_FromString("void* (*)(...)");
523
524 return true;
525 }
526
527 if (arg && PyCallable_Check(arg)) {
528 // annotated/typed Python function
529 PyObject* annot = PyObject_GetAttr(arg, PyStrings::gAnnotations);
530 if (annot) {
531 if (PyDict_Check(annot) && 1 < PyDict_Size(annot)) {
533 if (ret) {
534 // dict is ordered, with the last value being the return type
535 std::ostringstream tpn;
536 tpn << (CPPScope_Check(ret) ? ClassName(ret) : AnnotationAsText(ret))
537 << " (*)(";
538
539 PyObject* values = PyDict_Values(annot);
540 for (Py_ssize_t i = 0; i < (PyList_GET_SIZE(values)-1); ++i) {
541 if (i) tpn << ", ";
542 PyObject* item = PyList_GET_ITEM(values, i);
543 tpn << (CPPScope_Check(item) ? full_scope(ClassName(item)) : AnnotationAsText(item));
544 }
545 Py_DECREF(values);
546
547 tpn << ')';
548 tmpl_name.append(tpn.str());
549
551 return true;
552
553 } else
554 PyErr_Clear();
555 }
557 } else
558 PyErr_Clear();
559
560 // ctypes function pointer
561 PyObject* argtypes = nullptr;
562 PyObject* ret = nullptr;
563 if ((argtypes = PyObject_GetAttrString(arg, "argtypes")) && (ret = PyObject_GetAttrString(arg, "restype"))) {
564 std::ostringstream tpn;
565 PyObject* pytc = PyObject_GetAttr(ret, PyStrings::gCTypesType);
566 tpn << CT2CppNameS(pytc, false)
567 << " (*)(";
569
570 for (Py_ssize_t i = 0; i < PySequence_Length(argtypes); ++i) {
571 if (i) tpn << ", ";
573 pytc = PyObject_GetAttr(item, PyStrings::gCTypesType);
574 tpn << CT2CppNameS(pytc, false);
577 }
578
579 tpn << ')';
580 tmpl_name.append(tpn.str());
581
582 Py_DECREF(ret);
584
585 return true;
586
587 } else {
588 PyErr_Clear();
591 }
592
593 // callable C++ type (e.g. std::function)
594 PyObject* tpName = PyObject_GetAttr(arg, PyStrings::gCppName);
595 if (tpName) {
597 tmpl_name.append(CPPScope_Check(arg) ? full_scope(cname) : cname);
599 return true;
600 }
601 PyErr_Clear();
602 }
603
604 for (auto nn : {PyStrings::gCppName, PyStrings::gName}) {
606 if (tpName) {
609 return true;
610 }
611 PyErr_Clear();
612 }
613
615 // last ditch attempt, works for things like int values; since this is a
616 // source of errors otherwise, it is limited to specific types and not
617 // generally used (str(obj) can print anything ...)
621 return true;
622 }
623
624// Give up with a TypeError
625
626// Try to get a readable representation of the argument
628 const char *repr_cstr = repr ? PyUnicode_AsUTF8(repr) : "<unprintable>";
629
630 PyErr_Format(PyExc_TypeError, "could not construct C++ name from template argument %s", repr_cstr);
631
633 return false;
634}
635
638{
639// Helper to construct the "<type, type, ...>" part of a templated name (either
640// for a class or method lookup
642
643// Note: directly appending to string is a lot faster than stringstream
644 std::string tmpl_name;
645 tmpl_name.reserve(128);
646 if (pyname)
648 tmpl_name.push_back('<');
649
650 if (pcnt) *pcnt = 0; // count number of times 'pref' is used
651
653 for (int i = argoff; i < nArgs; ++i) {
654 // add type as string to name
658 // some common numeric types (separated out for performance: checking for
659 // __cpp_name__ and/or __name__ is rather expensive)
660 } else {
661 if (!AddTypeName(tmpl_name, tn, (args ? PyTuple_GET_ITEM(args, i) : nullptr), pref, pcnt)) {
662 return "";
663 }
664 }
665
666 // add a comma, as needed (no space as internally, final names don't have them)
667 if (i != nArgs-1)
668 tmpl_name.push_back(',');
669 }
670
671// close template name
672 tmpl_name.push_back('>');
673
674 return tmpl_name;
675}
676
677//----------------------------------------------------------------------------
679{
680// helper to convert ctypes' `_type_` info to the equivalent C++ name
681 const char* name = "";
683 char tc = ((char*)CPyCppyy_PyText_AsString(pytc))[0];
684 switch (tc) {
685 case '?': name = "bool"; break;
686 case 'c': name = "char"; break;
687 case 'b': name = "char"; break;
688 case 'B': name = "unsigned char"; break;
689 case 'h': name = "short"; break;
690 case 'H': name = "unsigned short"; break;
691 case 'i': name = "int"; break;
692 case 'I': name = "unsigned int"; break;
693 case 'l': name = "long"; break;
694 case 'L': name = "unsigned long"; break;
695 case 'q': name = "long long"; break;
696 case 'Q': name = "unsigned long long"; break;
697 case 'f': name = "float"; break;
698 case 'd': name = "double"; break;
699 case 'g': name = "long double"; break;
700 case 'z': name = "const char*"; break;
701 default: name = (allow_voidp ? "void*" : nullptr); break;
702 }
703 }
704
705 return name;
706}
707
708//----------------------------------------------------------------------------
709static inline bool check_scope(const std::string& name)
710{
712}
713
715 const std::vector<std::string>& argtypes, std::ostringstream& code)
716{
717// Generate function setup to be used in callbacks (wrappers and overrides).
718 int nArgs = (int)argtypes.size();
719
720// return value and argument type converters
721 bool isVoid = retType == "void";
722 if (!isVoid)
723 code << " CPYCPPYY_STATIC std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>> "
724 "retconv{CPyCppyy::CreateConverter(\""
725 << retType << "\"), CPyCppyy::DestroyConverter};\n";
726 std::vector<bool> arg_is_ptr;
727 if (nArgs) {
728 arg_is_ptr.resize(nArgs);
729 code << " CPYCPPYY_STATIC std::vector<std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>>> argcvs;\n"
730 << " if (argcvs.empty()) {\n"
731 << " argcvs.reserve(" << nArgs << ");\n";
732 for (int i = 0; i < nArgs; ++i) {
733 arg_is_ptr[i] = false;
734 code << " argcvs.emplace_back(CPyCppyy::CreateConverter(\"";
735 const std::string& at = argtypes[i];
736 const std::string& res_at = Cppyy::ResolveName(at);
737 const std::string& cpd = TypeManip::compound(res_at);
738 if (!cpd.empty() && check_scope(res_at)) {
739 // in case of a pointer, the original argument needs to be used to ensure
740 // the pointer-value remains comparable
741 //
742 // in case of a reference, there is no extra indirection on the C++ side as
743 // would be when converting a data member, so adjust the converter
744 arg_is_ptr[i] = cpd.back() == '*';
745 if (arg_is_ptr[i] || cpd.back() == '&') {
746 code << res_at.substr(0, res_at.size()-1);
747 } else code << at;
748 } else
749 code << at;
750 code << "\"), CPyCppyy::DestroyConverter);\n";
751 }
752 code << " }\n";
753 }
754
755// declare return value (TODO: this does not work for most non-builtin values)
756 if (!isVoid)
757 code << " " << retType << " ret{};\n";
758
759// acquire GIL
760 code << " PyGILState_STATE state = PyGILState_Ensure();\n";
761
762// build argument tuple if needed
763 if (nArgs) {
764 code << " std::vector<PyObject*> pyargs;\n";
765 code << " pyargs.reserve(" << nArgs << ");\n"
766 << " try {\n";
767 for (int i = 0; i < nArgs; ++i) {
768 code << " pyargs.emplace_back(argcvs[" << i << "]->FromMemory((void*)";
769 if (!arg_is_ptr[i]) code << '&';
770 code << "arg" << i << "));\n"
771 << " if (!pyargs.back()) throw " << i << ";\n";
772 }
773 code << " } catch(int) {\n"
774 << " for (auto pyarg : pyargs) Py_XDECREF(pyarg);\n"
775 << " CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc;\n"
776 << " }\n";
777 }
778}
779
780void CPyCppyy::Utility::ConstructCallbackReturn(const std::string& retType, int nArgs, std::ostringstream& code)
781{
782// Generate code for return value conversion and error handling.
783 bool isVoid = retType == "void";
784 bool isPtr = Cppyy::ResolveName(retType).back() == '*';
785
786 if (nArgs)
787 code << " for (auto pyarg : pyargs) Py_DECREF(pyarg);\n";
788 code << " bool cOk = (bool)pyresult;\n"
789 " if (pyresult) {\n";
790 if (isPtr) {
791 // If the return type is a CPPInstance, owned by Python, and the ref-count down
792 // to 1, the return will hold a dangling pointer, so set it to nullptr instead.
793 code << " if (!CPyCppyy::Instance_IsLively(pyresult))\n"
794 " ret = nullptr;\n"
795 " else {\n";
796 }
797 code << (isVoid ? "" : " cOk = retconv->ToMemory(pyresult, (void*)&ret);\n")
798 << " Py_DECREF(pyresult);\n }\n";
799 if (isPtr) code << " }\n";
800 code << " if (!cOk) {" // assume error set when converter failed
801// TODO: On Windows, throwing a C++ exception here makes the code hang; leave
802// the error be which allows at least one layer of propagation
803#ifdef _WIN32
804 " /* do nothing */ }\n"
805#else
806 " CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc; }\n"
807#endif
808 " PyGILState_Release(state);\n"
809 " return";
810 code << (isVoid ? ";\n }\n" : " ret;\n }\n");
811}
812
813
814//----------------------------------------------------------------------------
815static std::map<void*, PyObject*> sStdFuncLookup;
816static std::map<std::string, PyObject*> sStdFuncMakerLookup;
818 const std::string& retType, const std::string& signature, void* address)
819{
820// Convert a function pointer to an equivalent std::function<> object.
821 static int maker_count = 0;
822
823 auto pf = sStdFuncLookup.find(address);
824 if (pf != sStdFuncLookup.end()) {
825 Py_INCREF(pf->second);
826 return pf->second;
827 }
828
829 PyObject* maker = nullptr;
830
832 if (pm == sStdFuncMakerLookup.end()) {
833 std::ostringstream fname;
834 fname << "ptr2func" << ++maker_count;
835
836 std::ostringstream code;
837 code << "namespace __cppyy_internal { std::function<"
838 << retType << signature << "> " << fname.str()
839 << "(intptr_t faddr) { return (" << retType << "(*)" << signature << ")faddr;} }";
840
841 if (!Cppyy::Compile(code.str())) {
842 PyErr_SetString(PyExc_TypeError, "conversion to std::function failed");
843 return nullptr;
844 }
845
846 PyObject* pyscope = CreateScopeProxy("__cppyy_internal");
847 maker = PyObject_GetAttrString(pyscope, fname.str().c_str());
849 if (!maker)
850 return nullptr;
851
852 // cache the new maker (TODO: does it make sense to use weakrefs?)
854 } else
855 maker = pm->second;
856
857 PyObject* args = PyTuple_New(1);
858 PyTuple_SET_ITEM(args, 0, PyLong_FromLongLong((intptr_t)address));
859 PyObject* func = PyObject_Call(maker, args, NULL);
860 Py_DECREF(args);
861
862 if (func) { // prevent moving this func object, since then it can not be reused
863 ((CPPInstance*)func)->fFlags |= CPPInstance::kIsLValue;
864 Py_INCREF(func); // TODO: use weak? The C++ maker doesn't go away either
865 sStdFuncLookup[address] = func;
866 }
867
868 return func;
869}
870
871
872//----------------------------------------------------------------------------
874{
875// Initialize a proxy class for use by python, and add it to the module.
876
877// finalize proxy type
878 if (PyType_Ready(pytype) < 0)
879 return false;
880
881// add proxy type to the given module
882 Py_INCREF(pytype); // PyModule_AddObject steals reference
883 if (PyModule_AddObject(module, (char*)name, (PyObject*)pytype) < 0) {
885 return false;
886 }
887
888// declare success
889 return true;
890}
891
892//----------------------------------------------------------------------------
894{
895// Retrieve a linear buffer pointer from the given pyobject.
896
897// special case: don't handle character strings here (yes, they're buffers, but not quite)
899 return 0;
900
901// special case: bytes array
902 if ((!check || tc == '*' || tc == 'B') && PyByteArray_CheckExact(pyobject)) {
905 }
906
907// new-style buffer interface
910 return 0; // PyObject_GetBuffer() crashes on some platforms for some zero-sized seqeunces
911 PyErr_Clear();
913 memset(&bufinfo, 0, sizeof(Py_buffer));
915 if (tc == '*' || strchr(bufinfo.format, tc)
916 // if `long int` and `int` are the same size (on Windows and 32bit Linux,
917 // for example), `ctypes` isn't too picky about the type format, so make
918 // sure both integer types pass the type check
919 || (sizeof(long int) == sizeof(int) && ((tc == 'I' && strchr(bufinfo.format, 'L')) ||
920 (tc == 'i' && strchr(bufinfo.format, 'l'))))
921 // complex float is 'Zf' in bufinfo.format, but 'z' in single char
922 || (tc == 'z' && strstr(bufinfo.format, "Zf"))
923 // allow 'signed char' ('b') from array to pass through '?' (bool as from struct)
924 || (tc == '?' && strchr(bufinfo.format, 'b'))
925 ) {
926 buf = bufinfo.buf;
927
928 if (check && bufinfo.itemsize != size) {
930 "buffer itemsize (%ld) does not match expected size (%d)", bufinfo.itemsize, size);
932 return 0;
933 }
934
935 Py_ssize_t buflen = 0;
936 if (buf && bufinfo.ndim == 0)
937 buflen = bufinfo.len/bufinfo.itemsize;
938 else if (buf && bufinfo.ndim == 1)
939 buflen = bufinfo.shape ? bufinfo.shape[0] : bufinfo.len/bufinfo.itemsize;
941 if (buflen)
942 return buflen;
943 } else {
944 // have buf, but format mismatch: bail out now, otherwise the old
945 // code will return based on itemsize match
947 return 0;
948 }
949 } else if (bufinfo.obj)
951 PyErr_Clear();
952 }
953
954// attempt to retrieve pointer through old-style buffer interface
955 PyBufferProcs* bufprocs = Py_TYPE(pyobject)->tp_as_buffer;
956
957 PySequenceMethods* seqmeths = Py_TYPE(pyobject)->tp_as_sequence;
958 if (seqmeths != 0 && bufprocs != 0
959#if PY_VERSION_HEX < 0x03000000
960 && bufprocs->bf_getwritebuffer != 0
961 && (*(bufprocs->bf_getsegcount))(pyobject, 0) == 1
962#else
963 && bufprocs->bf_getbuffer != 0
964#endif
965 ) {
966
967 // get the buffer
968#if PY_VERSION_HEX < 0x03000000
969 Py_ssize_t buflen = (*(bufprocs->bf_getwritebuffer))(pyobject, 0, &buf);
970#else
972 (*(bufprocs->bf_getbuffer))(pyobject, &bufinfo, PyBUF_WRITABLE);
973 buf = (char*)bufinfo.buf;
974 Py_ssize_t buflen = bufinfo.len;
976#endif
977
978 if (buf && check == true) {
979 // determine buffer compatibility (use "buf" as a status flag)
980 PyObject* pytc = tc != '*' ? PyObject_GetAttr(pyobject, PyStrings::gTypeCode) : nullptr;
981 if (pytc != 0) { // for array objects
983 if (!(cpytc == tc || (tc == '?' && cpytc == 'b')))
984 buf = 0; // no match
986 } else if (seqmeths->sq_length &&
987 (int)(buflen/(*(seqmeths->sq_length))(pyobject)) == size) {
988 // this is a gamble ... may or may not be ok, but that's for the user
989 PyErr_Clear();
990 } else if (buflen == size) {
991 // also a gamble, but at least 1 item will fit into the buffer, so very likely ok ...
992 PyErr_Clear();
993 } else {
994 buf = 0; // not compatible
995
996 // clarify error message
997 auto error = FetchPyError();
999 (char*)"%s and given element size (%ld) do not match needed (%d)",
1000 CPyCppyy_PyText_AsString(error.fValue.get()),
1001 seqmeths->sq_length ? (long)(buflen/(*(seqmeths->sq_length))(pyobject)) : (long)buflen,
1002 size);
1003 error.fValue.reset(pyvalue2);
1004 RestorePyError(error);
1005 }
1006 }
1007
1008 if (!buf) return 0;
1009 return buflen/(size ? size : 1);
1010 }
1011
1012 return 0;
1013}
1014
1015//----------------------------------------------------------------------------
1016std::string CPyCppyy::Utility::MapOperatorName(const std::string& name, bool bTakesParams, bool* stubbed)
1017{
1018// Map the given C++ operator name on the python equivalent.
1019 if (8 < name.size() && name.substr(0, 8) == "operator") {
1020 std::string op = name.substr(8, std::string::npos);
1021
1022 // stripping ...
1023 std::string::size_type start = 0, end = op.size();
1024 while (start < end && isspace(op[start])) ++start;
1025 while (start < end && isspace(op[end-1])) --end;
1026 op = op.substr(start, end - start);
1027
1028 // certain operators should be removed completely (e.g. operator delete & friends)
1029 if (gOpRemove.find(op) != gOpRemove.end())
1030 return "";
1031
1032 // check first if none, to prevent spurious deserializing downstream
1033 TC2POperatorMapping_t::iterator pop = gC2POperatorMapping.find(op);
1034 if (pop == gC2POperatorMapping.end() && gOpSkip.find(op) == gOpSkip.end()) {
1036 pop = gC2POperatorMapping.find(op);
1037 }
1038
1039 // map C++ operator to python equivalent, or made up name if no equivalent exists
1040 if (pop != gC2POperatorMapping.end()) {
1041 return pop->second;
1042
1043 } else if (op == "*") {
1044 // dereference v.s. multiplication of two instances
1045 if (!bTakesParams) return "__deref__";
1046 if (stubbed) *stubbed = true;
1047 return "__mul__";
1048
1049 } else if (op == "/") {
1050 // no unary, but is stubbed
1051 return CPPYY__div__;
1052
1053 } else if (op == "+") {
1054 // unary positive v.s. addition of two instances
1055 if (!bTakesParams) return "__pos__";
1056 if (stubbed) *stubbed = true;
1057 return "__add__";
1058
1059 } else if (op == "-") {
1060 // unary negative v.s. subtraction of two instances
1061 if (!bTakesParams) return "__neg__";
1062 if (stubbed) *stubbed = true;
1063 return "__sub__";
1064
1065 } else if (op == "++") {
1066 // prefix v.s. postfix increment
1067 return bTakesParams ? "__postinc__" : "__preinc__";
1068
1069 } else if (op == "--") {
1070 // prefix v.s. postfix decrement
1071 return bTakesParams ? "__postdec__" : "__predec__";
1072 }
1073
1074 }
1075
1076// might get here, as not all operator methods are handled (new, delete, etc.)
1077 return name;
1078}
1079
1080//----------------------------------------------------------------------------
1082{
1083// Retrieve the class name from the given Python instance.
1084 std::string clname = "<unknown>";
1086 PyObject* pyname = PyObject_GetAttr(pyclass, PyStrings::gCppName);
1087 if (!pyname) {
1088 PyErr_Clear();
1089 pyname = PyObject_GetAttr(pyclass, PyStrings::gName);
1090 }
1091
1092 if (pyname) {
1095 } else
1096 PyErr_Clear();
1097 return clname;
1098}
1099
1100//----------------------------------------------------------------------------
1101static std::set<std::string> sIteratorTypes;
1102bool CPyCppyy::Utility::IsSTLIterator(const std::string& classname)
1103{
1104// attempt to recognize STL iterators (TODO: probably belongs in the backend), using
1105// a couple of common container classes with different iterator protocols (note that
1106// mapping iterators are handled separately in the pythonizations) as exemplars (the
1107// actual, resolved, names will be compiler-specific) that are picked b/c they are
1108// baked into the CoreLegacy dictionary
1109 if (sIteratorTypes.empty()) {
1110 std::string tt = "<int>::";
1111 for (auto c : {"std::vector", "std::list", "std::deque"}) {
1112 for (auto i : {"iterator", "const_iterator"}) {
1113 const std::string& itname = Cppyy::ResolveName(c+tt+i);
1114 auto pos = itname.find('<');
1115 if (pos != std::string::npos)
1116 sIteratorTypes.insert(itname.substr(0, pos));
1117 }
1118 }
1119 }
1120
1121 auto pos = classname.find('<');
1122 if (pos != std::string::npos)
1123 return sIteratorTypes.find(classname.substr(0, pos)) != sIteratorTypes.end();
1124 return false;
1125}
1126
1127
1128//----------------------------------------------------------------------------
1139
1140
1141//----------------------------------------------------------------------------
1143{
1144// Re-acquire the GIL before calling PyErr_Occurred() in case it has been
1145// released; note that the p2.2 code assumes that there are no callbacks in
1146// C++ to python (or at least none returning errors).
1147#if PY_VERSION_HEX >= 0x02030000
1148 PyGILState_STATE gstate = PyGILState_Ensure();
1151#else
1152 if (PyThreadState_GET())
1153 return PyErr_Occurred();
1154 PyObject* e = 0;
1155#endif
1156
1157 return e;
1158}
1159
1160
1161//----------------------------------------------------------------------------
1163{
1164 // create a PyError_t RAII object that will capture and store the exception data
1166#if PY_VERSION_HEX >= 0x030c0000
1167 error.fValue.reset(PyErr_GetRaisedException());
1168#else
1169 PyObject *pytype = nullptr;
1170 PyObject *pyvalue = nullptr;
1171 PyObject *pytrace = nullptr;
1173 error.fType.reset(pytype);
1174 error.fValue.reset(pyvalue);
1175 error.fTrace.reset(pytrace);
1176#endif
1177 return error;
1178}
1179
1180
1181//----------------------------------------------------------------------------
1183{
1184#if PY_VERSION_HEX >= 0x030c0000
1185 PyErr_SetRaisedException(error.fValue.release());
1186#else
1187 PyErr_Restore(error.fType.release(), error.fValue.release(), error.fTrace.release());
1188#endif
1189}
1190
1191
1192//----------------------------------------------------------------------------
1193size_t CPyCppyy::Utility::FetchError(std::vector<PyError_t>& errors, bool is_cpp)
1194{
1195// Fetch the current python error, if any, and store it for future use.
1196 if (PyErr_Occurred()) {
1197 errors.emplace_back(FetchPyError());
1198 errors.back().fIsCpp = is_cpp;
1199 }
1200 return errors.size();
1201}
1202
1203//----------------------------------------------------------------------------
1205{
1206// Use the collected exceptions to build up a detailed error log.
1207 if (errors.empty()) {
1208 // should not happen ...
1211 return;
1212 }
1213
1214// if a _single_ exception was thrown from C++, assume it has priority (see below)
1215 PyError_t* unique_from_cpp = nullptr;
1216 for (auto& e : errors) {
1217 if (e.fIsCpp) {
1218 if (!unique_from_cpp)
1219 unique_from_cpp = &e;
1220 else {
1221 // two C++ exceptions, resort to default behavior
1222 unique_from_cpp = nullptr;
1223 break;
1224 }
1225 }
1226 }
1227
1228 if (unique_from_cpp) {
1229 // report only this error; the idea here is that all other errors come from
1230 // the bindings (e.g. argument conversion errors), while the exception from
1231 // C++ means that it originated from an otherwise successful call
1232
1233 // bind the original C++ object, rather than constructing from topmsg, as it
1234 // is expected to have informative state
1236 } else {
1237 // try to consolidate Python exceptions, otherwise select default
1238 PyObject* exc_type = nullptr;
1239 for (auto& e : errors) {
1240#if PY_VERSION_HEX >= 0x030c0000
1241 PyObject* pytype = (PyObject*)Py_TYPE(e.fValue.get());
1242#else
1243 PyObject* pytype = e.fType.get();
1244#endif
1245 if (!exc_type) exc_type = pytype;
1246 else if (exc_type != pytype) {
1247 exc_type = defexc;
1248 break;
1249 }
1250 }
1251
1252 // add the details to the topmsg
1253 PyObject* separator = CPyCppyy_PyText_FromString("\n ");
1254 for (auto& e : errors) {
1255 PyObject *pyvalue = e.fValue.get();
1256 CPyCppyy_PyText_Append(&topmsg, separator);
1259 } else if (pyvalue) {
1261 if (!excstr) {
1262 PyErr_Clear();
1264 }
1266 } else {
1268 CPyCppyy_PyText_FromString("unknown exception"));
1269 }
1270 }
1271
1272 Py_DECREF(separator);
1273
1274 // set the python exception
1276 }
1277
1279}
1280
1281
1282//----------------------------------------------------------------------------
1283static bool includesDone = false;
1285{
1286// setup Python API for callbacks
1287 if (!includesDone) {
1288 bool okay = Cppyy::Compile(
1289 // basic API (converters etc.)
1290 "#include \"CPyCppyy/API.h\"\n"
1291
1292 // utilities from the CPyCppyy public API
1293 "#include \"CPyCppyy/DispatchPtr.h\"\n"
1294 "#include \"CPyCppyy/PyException.h\"\n"
1295 );
1297 }
1298
1299 return includesDone;
1300}
#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
_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:1101
static bool includesDone
Definition Utility.cxx:1283
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:816
static std::set< std::string > gOpSkip
Definition Utility.cxx:33
static std::map< void *, PyObject * > sStdFuncLookup
Definition Utility.cxx:815
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:709
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
unsigned long long PY_ULONG_LONG
Definition cpp_cppyy.h:24
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:678
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
Definition Utility.cxx:714
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
Definition Utility.cxx:780
void RestorePyError(PyError_t &error)
Definition Utility.cxx:1182
void SetDetailedException(std::vector< PyError_t > &&errors, PyObject *topmsg, PyObject *defexc)
Definition Utility.cxx:1204
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition Utility.cxx:893
std::string ConstructTemplateArgs(PyObject *pyname, PyObject *tpArgs, PyObject *args=nullptr, ArgPreference=kNone, int argoff=0, int *pcnt=nullptr)
Definition Utility.cxx:636
PyObject * FuncPtr2StdFunction(const std::string &retType, const std::string &signature, void *address)
Definition Utility.cxx:817
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:1193
std::string MapOperatorName(const std::string &name, bool bTakesParames, bool *stubbed=nullptr)
Definition Utility.cxx:1016
bool InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
Definition Utility.cxx:873
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
Definition Utility.cxx:186
PyError_t FetchPyError()
Definition Utility.cxx:1162
bool IsSTLIterator(const std::string &classname)
Definition Utility.cxx:1102
std::string ClassName(PyObject *pyobj)
Definition Utility.cxx:1081
PyObject * PyErr_Occurred_WithGIL()
Definition Utility.cxx:1142
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:40
intptr_t TCppMethod_t
Definition cpp_cppyy.h:38
RPY_EXPORTED bool Compile(const std::string &code, bool silent=false)
RPY_EXPORTED TCppScope_t gGlobalScope
Definition cpp_cppyy.h:69
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:34
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