Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
clingwrapper.cxx
Go to the documentation of this file.
1// Bindings
2#include "capi.h"
3#include "cpp_cppyy.h"
4#include "callcontext.h"
5
6// ROOT
7#include "TBaseClass.h"
8#include "TClass.h"
9#include "TClassRef.h"
10#include "TClassTable.h"
11#include "TClassEdit.h"
12#include "TCollection.h"
13#include "TDataMember.h"
14#include "TDataType.h"
15#include "TEnum.h"
16#include "TEnumConstant.h"
17#include "TEnv.h"
18#include "TError.h"
19#include "TException.h"
20#include "TFunction.h"
21#include "TFunctionTemplate.h"
22#include "TGlobal.h"
23#include "THashList.h"
24#include "TInterpreter.h"
25#include "TList.h"
26#include "TListOfDataMembers.h"
27#include "TListOfEnums.h"
28#include "TMethod.h"
29#include "TMethodArg.h"
30#include "TROOT.h"
31#include "TSystem.h"
32
33// Standard
34#include <assert.h>
35#include <algorithm> // for std::count, std::remove
36#include <stdexcept>
37#include <map>
38#include <new>
39#include <set>
40#include <sstream>
41#include <signal.h>
42#include <stdlib.h> // for getenv
43#include <string.h>
44#include <typeinfo>
45
46// temp
47#include <iostream>
49// --temp
50
51
52// small number that allows use of stack for argument passing
53const int SMALL_ARGS_N = 8;
54
55// data for life time management ---------------------------------------------
56typedef std::vector<TClassRef> ClassRefs_t;
58static const ClassRefs_t::size_type GLOBAL_HANDLE = 1;
59static const ClassRefs_t::size_type STD_HANDLE = GLOBAL_HANDLE + 1;
60
61typedef std::map<std::string, ClassRefs_t::size_type> Name2ClassRefIndex_t;
63
64namespace {
65
66static inline Cppyy::TCppType_t find_memoized(const std::string& name)
67{
68 auto icr = g_name2classrefidx.find(name);
69 if (icr != g_name2classrefidx.end())
70 return (Cppyy::TCppType_t)icr->second;
71 return (Cppyy::TCppType_t)0;
72}
73
74class CallWrapper {
75public:
76 typedef const void* DeclId_t;
77
78public:
79 CallWrapper(TFunction* f) : fDecl(f->GetDeclId()), fName(f->GetName()), fTF(nullptr) {}
80 CallWrapper(DeclId_t fid, const std::string& n) : fDecl(fid), fName(n), fTF(nullptr) {}
81 ~CallWrapper() {
82 if (fTF && fDecl == fTF->GetDeclId())
83 delete fTF;
84 }
85
86public:
88 DeclId_t fDecl;
89 std::string fName;
90 TFunction* fTF;
91};
92
93}
94
95static std::vector<CallWrapper*> gWrapperHolder;
96static inline CallWrapper* new_CallWrapper(TFunction* f)
97{
98 CallWrapper* wrap = new CallWrapper(f);
99 gWrapperHolder.push_back(wrap);
100 return wrap;
101}
102
103static inline CallWrapper* new_CallWrapper(CallWrapper::DeclId_t fid, const std::string& n)
104{
105 CallWrapper* wrap = new CallWrapper(fid, n);
106 gWrapperHolder.push_back(wrap);
107 return wrap;
108}
109
110typedef std::vector<TGlobal*> GlobalVars_t;
112
113static std::set<std::string> gSTLNames;
114
115
116// data ----------------------------------------------------------------------
118
119// builtin types (including a few common STL templates as long as they live in
120// the global namespace b/c of choices upstream)
121static std::set<std::string> g_builtins =
122 {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short",
123 "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
124 "float", "double", "long double", "void",
125 "allocator", "array", "basic_string", "complex", "initializer_list", "less", "list",
126 "map", "pair", "set", "vector"};
127
128// smart pointer types
129static std::set<std::string> gSmartPtrTypes =
130 {"auto_ptr", "std::auto_ptr", "shared_ptr", "std::shared_ptr",
131 "unique_ptr", "std::unique_ptr", "weak_ptr", "std::weak_ptr"};
132
133// to filter out ROOT names
134static std::set<std::string> gInitialNames;
135static std::set<std::string> gRootSOs;
136
137// configuration
138static bool gEnableFastPath = true;
139
140
141// global initialization -----------------------------------------------------
142namespace {
143
144// names copied from TUnixSystem
145#ifdef WIN32
146const int SIGBUS = 0; // simple placeholders for ones that don't exist
147const int SIGSYS = 0;
148const int SIGPIPE = 0;
149const int SIGQUIT = 0;
150const int SIGWINCH = 0;
151const int SIGALRM = 0;
152const int SIGCHLD = 0;
153const int SIGURG = 0;
154const int SIGUSR1 = 0;
155const int SIGUSR2 = 0;
156#endif
157
158static struct Signalmap_t {
159 int fCode;
160 const char *fSigName;
161} gSignalMap[kMAXSIGNALS] = { // the order of the signals should be identical
162 { SIGBUS, "bus error" }, // to the one in TSysEvtHandler.h
163 { SIGSEGV, "segmentation violation" },
164 { SIGSYS, "bad argument to system call" },
165 { SIGPIPE, "write on a pipe with no one to read it" },
166 { SIGILL, "illegal instruction" },
167 { SIGABRT, "abort" },
168 { SIGQUIT, "quit" },
169 { SIGINT, "interrupt" },
170 { SIGWINCH, "window size change" },
171 { SIGALRM, "alarm clock" },
172 { SIGCHLD, "death of a child" },
173 { SIGURG, "urgent data arrived on an I/O channel" },
174 { SIGFPE, "floating point exception" },
175 { SIGTERM, "termination signal" },
176 { SIGUSR1, "user-defined signal 1" },
177 { SIGUSR2, "user-defined signal 2" }
178};
179
180static void inline do_trace(int sig) {
181 std::cerr << " *** Break *** " << (sig < kMAXSIGNALS ? gSignalMap[sig].fSigName : "") << std::endl;
183}
184
185class TExceptionHandlerImp : public TExceptionHandler {
186public:
187 virtual void HandleException(Int_t sig) {
188 if (TROOT::Initialized()) {
189 if (gException) {
190 gInterpreter->RewindDictionary();
191 gInterpreter->ClearFileBusy();
192 }
193
194 if (!getenv("CPPYY_CRASH_QUIET"))
195 do_trace(sig);
196
197 // jump back, if catch point set
198 Throw(sig);
199 }
200
201 do_trace(sig);
202 gSystem->Exit(128 + sig);
203 }
204};
205
206class ApplicationStarter {
207public:
208 ApplicationStarter() {
209 // initialize ROOT early to guarantee proper order of shutdown later on (gROOT is a
210 // macro that resolves to the ROOT::GetROOT() function call)
211 (void)gROOT;
212
213 // setup dummy holders for global and std namespaces
214 assert(g_classrefs.size() == GLOBAL_HANDLE);
216 g_classrefs.push_back(TClassRef(""));
217
218 // aliases for std (setup already in pythonify)
220 g_name2classrefidx["::std"] = g_name2classrefidx["std"];
221 g_classrefs.push_back(TClassRef("std"));
222
223 // add a dummy global to refer to as null at index 0
224 g_globalvars.push_back(nullptr);
225
226 // disable fast path if requested
227 if (getenv("CPPYY_DISABLE_FASTPATH")) gEnableFastPath = false;
228
229 // fill the set of STL names
230 const char* stl_names[] = {"allocator", "auto_ptr", "bad_alloc", "bad_cast",
231 "bad_exception", "bad_typeid", "basic_filebuf", "basic_fstream", "basic_ifstream",
232 "basic_ios", "basic_iostream", "basic_istream", "basic_istringstream",
233 "basic_ofstream", "basic_ostream", "basic_ostringstream", "basic_streambuf",
234 "basic_string", "basic_stringbuf", "basic_stringstream", "binary_function",
235 "binary_negate", "bitset", "byte", "char_traits", "codecvt_byname", "codecvt", "collate",
236 "collate_byname", "compare", "complex", "ctype_byname", "ctype", "default_delete",
237 "deque", "divides", "domain_error", "equal_to", "exception", "forward_list", "fpos",
238 "function", "greater_equal", "greater", "gslice_array", "gslice", "hash", "indirect_array",
239 "integer_sequence", "invalid_argument", "ios_base", "istream_iterator", "istreambuf_iterator",
240 "istrstream", "iterator_traits", "iterator", "length_error", "less_equal", "less",
241 "list", "locale", "localedef utility", "locale utility", "logic_error", "logical_and",
242 "logical_not", "logical_or", "map", "mask_array", "mem_fun", "mem_fun_ref", "messages",
243 "messages_byname", "minus", "modulus", "money_get", "money_put", "moneypunct",
244 "moneypunct_byname", "multimap", "multiplies", "multiset", "negate", "not_equal_to",
245 "num_get", "num_put", "numeric_limits", "numpunct", "numpunct_byname",
246 "ostream_iterator", "ostreambuf_iterator", "ostrstream", "out_of_range",
247 "overflow_error", "pair", "plus", "pointer_to_binary_function",
248 "pointer_to_unary_function", "priority_queue", "queue", "range_error",
249 "raw_storage_iterator", "reverse_iterator", "runtime_error", "set", "shared_ptr",
250 "slice_array", "slice", "stack", "string", "strstream", "strstreambuf",
251 "time_get_byname", "time_get", "time_put_byname", "time_put", "unary_function",
252 "unary_negate", "unique_ptr", "underflow_error", "unordered_map", "unordered_multimap",
253 "unordered_multiset", "unordered_set", "valarray", "vector", "weak_ptr", "wstring"};
254 for (auto& name : stl_names)
255 gSTLNames.insert(name);
256
257 // set opt level (default to 2 if not given; Cling itself defaults to 0)
258 int optLevel = 2;
259 if (getenv("CPPYY_OPT_LEVEL")) optLevel = atoi(getenv("CPPYY_OPT_LEVEL"));
260 if (optLevel != 0) {
261 std::ostringstream s;
262 s << "#pragma cling optimize " << optLevel;
263 gInterpreter->ProcessLine(s.str().c_str());
264 }
265
266 // load frequently used headers
267 const char* code =
268 "#include <iostream>\n"
269 "#include <string>\n"
270 "#include <DllImport.h>\n" // defines R__EXTERN
271 "#include <vector>\n"
272 "#include <utility>";
273 gInterpreter->ProcessLine(code);
274
275 // make sure we run in batch mode as far as ROOT graphics is concerned
276 if (!getenv("ROOTSYS"))
277 gROOT->SetBatch(kTRUE);
278
279 // create helpers for comparing thingies
280 gInterpreter->Declare(
281 "namespace __cppyy_internal { template<class C1, class C2>"
282 " bool is_equal(const C1& c1, const C2& c2) { return (bool)(c1 == c2); } }");
283 gInterpreter->Declare(
284 "namespace __cppyy_internal { template<class C1, class C2>"
285 " bool is_not_equal(const C1& c1, const C2& c2) { return (bool)(c1 != c2); } }");
286
287 // retrieve all initial (ROOT) C++ names in the global scope to allow filtering later
288 if (!getenv("CPPYY_NO_ROOT_FILTER")) {
289 gROOT->GetListOfGlobals(true); // force initialize
290 gROOT->GetListOfGlobalFunctions(true); // id.
291 std::set<std::string> initial;
293 gInitialNames = initial;
294
295#ifndef WIN32
296 gRootSOs.insert("libCore.so ");
297 gRootSOs.insert("libRIO.so ");
298 gRootSOs.insert("libThread.so ");
299 gRootSOs.insert("libMathCore.so ");
300#else
301 gRootSOs.insert("libCore.dll ");
302 gRootSOs.insert("libRIO.dll ");
303 gRootSOs.insert("libThread.dll ");
304 gRootSOs.insert("libMathCore.dll ");
305#endif
306 }
307
308 // start off with a reasonable size placeholder for wrappers
309 gWrapperHolder.reserve(1024);
310
311 // create an exception handler to process signals
312 gExceptionHandler = new TExceptionHandlerImp{};
313 }
314
315 ~ApplicationStarter() {
316 for (auto wrap : gWrapperHolder)
317 delete wrap;
318 delete gExceptionHandler; gExceptionHandler = nullptr;
319 }
320} _applicationStarter;
321
322} // unnamed namespace
323
324
325// local helpers -------------------------------------------------------------
326static inline
328{
329 assert((ClassRefs_t::size_type)scope < g_classrefs.size());
330 return g_classrefs[(ClassRefs_t::size_type)scope];
331}
332
333static inline
335 CallWrapper* wrap = ((CallWrapper*)method);
336 if (!wrap->fTF || wrap->fTF->GetDeclId() != wrap->fDecl) {
337 MethodInfo_t* mi = gInterpreter->MethodInfo_Factory(wrap->fDecl);
338 wrap->fTF = new TFunction(mi);
339 }
340 return wrap->fTF;
341}
342
343static inline
344char* cppstring_to_cstring(const std::string& cppstr)
345{
346 char* cstr = (char*)malloc(cppstr.size()+1);
347 memcpy(cstr, cppstr.c_str(), cppstr.size()+1);
348 return cstr;
349}
350
351static inline
352bool match_name(const std::string& tname, const std::string fname)
353{
354// either match exactly, or match the name as template
355 if (fname.rfind(tname, 0) == 0) {
356 if ((tname.size() == fname.size()) ||
357 (tname.size() < fname.size() && fname[tname.size()] == '<'))
358 return true;
359 }
360 return false;
361}
362
363static inline
364bool is_missclassified_stl(const std::string& name)
365{
366 std::string::size_type pos = name.find('<');
367 if (pos != std::string::npos)
368 return gSTLNames.find(name.substr(0, pos)) != gSTLNames.end();
369 return gSTLNames.find(name) != gSTLNames.end();
370}
371
372
373// direct interpreter access -------------------------------------------------
374bool Cppyy::Compile(const std::string& code)
375{
376 return gInterpreter->Declare(code.c_str());
377}
378
379
380// name to opaque C++ scope representation -----------------------------------
381std::string Cppyy::ResolveName(const std::string& cppitem_name)
382{
383// Fully resolve the given name to the final type name.
384
385// try memoized type cache, in case seen before
386 TCppType_t klass = find_memoized(cppitem_name);
387 if (klass) return GetScopedFinalName(klass);
388
389// remove global scope '::' if present
390 std::string tclean = cppitem_name.compare(0, 2, "::") == 0 ?
391 cppitem_name.substr(2, std::string::npos) : cppitem_name;
392
393// classes (most common)
394 tclean = TClassEdit::CleanType(tclean.c_str());
395 if (tclean.empty() /* unknown, eg. an operator */) return cppitem_name;
396
397// reduce [N] to []
398 if (tclean[tclean.size()-1] == ']')
399 tclean = tclean.substr(0, tclean.rfind('[')) + "[]";
400
401 if (tclean.rfind("byte", 0) == 0 || tclean.rfind("std::byte", 0) == 0)
402 return tclean;
403
404// check data types list (accept only builtins as typedefs will
405// otherwise not be resolved)
406 TDataType* dt = gROOT->GetType(tclean.c_str());
407 if (dt && dt->GetType() != kOther_t) return dt->GetFullTypeName();
408
409// special case for enums
410 if (IsEnum(cppitem_name))
411 return ResolveEnum(cppitem_name);
412
413// special case for clang's builtin __type_pack_element (which does not resolve)
414 if (cppitem_name.rfind("__type_pack_element", 0) != std::string::npos) {
415 // shape is "__type_pack_element<index,type1,type2,...,typeN>cpd": extract
416 // first the index, and from there the indexed type; finally, restore the
417 // qualifiers
418 const char* str = cppitem_name.c_str();
419 char* endptr = nullptr;
420 unsigned long index = strtoul(str+20, &endptr, 0);
421
422 std::string tmplvars{endptr};
423 auto start = tmplvars.find(',') + 1;
424 auto end = tmplvars.find(',', start);
425 while (index != 0) {
426 start = end+1;
427 end = tmplvars.find(',', start);
428 if (end == std::string::npos) end = tmplvars.rfind('>');
429 --index;
430 }
431
432 std::string resolved = tmplvars.substr(start, end-start);
433 auto cpd = tmplvars.rfind('>');
434 if (cpd != std::string::npos && cpd+1 != tmplvars.size())
435 return resolved + tmplvars.substr(cpd+1, std::string::npos);
436 return resolved;
437 }
438
439// typedefs
440 return TClassEdit::ResolveTypedef(tclean.c_str(), true);
441}
442
443static std::map<std::string, std::string> resolved_enum_types;
444std::string Cppyy::ResolveEnum(const std::string& enum_type)
445{
446// The underlying type of a an enum may be any kind of integer.
447// Resolve that type via a workaround (note: this function assumes
448// that the enum_type name is a valid enum type name)
449 auto res = resolved_enum_types.find(enum_type);
450 if (res != resolved_enum_types.end())
451 return res->second;
452
453// desugar the type before resolving
454 std::string et_short = TClassEdit::ShortType(enum_type.c_str(), 1);
455 if (et_short.find("(anonymous") == std::string::npos) {
456 std::ostringstream decl;
457 // TODO: now presumed fixed with https://sft.its.cern.ch/jira/browse/ROOT-6988
458 for (auto& itype : {"unsigned int"}) {
459 decl << "std::is_same<"
460 << itype
461 << ", std::underlying_type<"
462 << et_short
463 << ">::type>::value;";
464 if (gInterpreter->ProcessLine(decl.str().c_str())) {
465 // TODO: "re-sugaring" like this is brittle, but the top
466 // should be re-translated into AST-based code anyway
467 std::string resugared;
468 if (et_short.size() != enum_type.size()) {
469 auto pos = enum_type.find(et_short);
470 if (pos != std::string::npos) {
471 resugared = enum_type.substr(0, pos) + itype;
472 if (pos+et_short.size() < enum_type.size())
473 resugared += enum_type.substr(pos+et_short.size(), std::string::npos);
474 }
475 }
476 if (resugared.empty()) resugared = itype;
477 resolved_enum_types[enum_type] = resugared;
478 return resugared;
479 }
480 }
481 }
482
483// failed or anonymous ... signal upstream to special case this
484 int ipos = (int)enum_type.size()-1;
485 for (; 0 <= ipos; --ipos) {
486 char c = enum_type[ipos];
487 if (isspace(c)) continue;
488 if (isalnum(c) || c == '_' || c == '>' || c == ')') break;
489 }
490 bool isConst = enum_type.find("const ", 6) != std::string::npos;
491 std::string restype = isConst ? "const " : "";
492 restype += "internal_enum_type_t"+enum_type.substr((std::string::size_type)ipos+1, std::string::npos);
493 resolved_enum_types[enum_type] = restype;
494 return restype; // should default to some int variant
495}
496
497Cppyy::TCppScope_t Cppyy::GetScope(const std::string& sname)
498{
499// First, try cache
500 TCppType_t result = find_memoized(sname);
501 if (result) return result;
502
503// Second, skip builtins before going through the more expensive steps of resolving
504// typedefs and looking up TClass
505 if (g_builtins.find(sname) != g_builtins.end())
506 return (TCppScope_t)0;
507
508// TODO: scope_name should always be final already?
509// Resolve name fully before lookup to make sure all aliases point to the same scope
510 std::string scope_name = ResolveName(sname);
511 bool bHasAlias = sname != scope_name;
512 if (bHasAlias) {
513 result = find_memoized(scope_name);
514 if (result) return result;
515 }
516
517// both failed, but may be STL name that's missing 'std::' now, but didn't before
518 bool b_scope_name_missclassified = is_missclassified_stl(scope_name);
519 if (b_scope_name_missclassified) {
520 result = find_memoized("std::"+scope_name);
521 if (result) g_name2classrefidx["std::"+scope_name] = (ClassRefs_t::size_type)result;
522 }
523 bool b_sname_missclassified = bHasAlias ? is_missclassified_stl(sname) : false;
524 if (b_sname_missclassified) {
525 if (!result) result = find_memoized("std::"+sname);
526 if (result) g_name2classrefidx["std::"+sname] = (ClassRefs_t::size_type)result;
527 }
528
529 if (result) return result;
530
531// use TClass directly, to enable auto-loading; class may be stubbed (eg. for
532// function returns) or forward declared, leading to a non-null TClass that is
533// otherwise invalid/unusable
534 TClassRef cr(TClass::GetClass(scope_name.c_str(), true /* load */, true /* silent */));
535 if (!cr.GetClass())
536 return (TCppScope_t)0;
537
538// memoize found/created TClass
539 ClassRefs_t::size_type sz = g_classrefs.size();
540 g_name2classrefidx[scope_name] = sz;
541 if (bHasAlias) g_name2classrefidx[sname] = sz;
542 g_classrefs.push_back(TClassRef(scope_name.c_str()));
543
544// TODO: make ROOT/meta NOT remove std :/
545 if (b_scope_name_missclassified)
546 g_name2classrefidx["std::"+scope_name] = sz;
547 if (b_sname_missclassified)
548 g_name2classrefidx["std::"+sname] = sz;
549
550 return (TCppScope_t)sz;
551}
552
553bool Cppyy::IsTemplate(const std::string& template_name)
554{
555 return (bool)gInterpreter->CheckClassTemplate(template_name.c_str());
556}
557
558namespace {
559 class AutoCastRTTI {
560 public:
561 virtual ~AutoCastRTTI() {}
562 };
563}
564
566{
567 TClassRef& cr = type_from_handle(klass);
568 if (!cr.GetClass() || !obj) return klass;
569
570#ifdef _WIN64
571// Cling does not provide a consistent ImageBase address for calculating relative addresses
572// as used in Windows 64b RTTI. So, check for our own RTTI extension instead. If that fails,
573// see whether the unmangled raw_name is available (e.g. if this is an MSVC compiled rather
574// than JITed class) and pass on if it is.
575 volatile const char* raw = nullptr; // to prevent too aggressive reordering
576 try {
577 // this will filter those objects that do not have RTTI to begin with (throws)
578 AutoCastRTTI* pcst = (AutoCastRTTI*)obj;
579 raw = typeid(*pcst).raw_name();
580
581 // check the signature id (0 == absolute, 1 == relative, 2 == ours)
582 void* vfptr = *(void**)((intptr_t)obj);
583 void* meta = (void*)((intptr_t)*((void**)((intptr_t)vfptr-sizeof(void*))));
584 if (*(intptr_t*)meta == 2) {
585 // access the extra data item which is an absolute pointer to the RTTI
586 void* ptdescr = (void*)((intptr_t)meta + 4*sizeof(unsigned long)+sizeof(void*));
587 if (ptdescr && *(void**)ptdescr) {
588 auto rtti = *(std::type_info**)ptdescr;
589 raw = rtti->raw_name();
590 if (raw && raw[0] != '\0') // likely unnecessary
591 return (TCppType_t)GetScope(rtti->name());
592 }
593
594 return klass; // do not fall through if no RTTI info available
595 }
596
597 // if the raw name is the empty string (no guarantees that this is so as truly, the
598 // address is corrupt, but it is common to be empty), then there is no accessible RTTI
599 // and getting the unmangled name will crash ...
600 if (!raw || raw[0] == '\0')
601 return klass;
602 } catch (std::bad_typeid) {
603 return klass; // can't risk passing to ROOT/meta as it may do RTTI
604 }
605#endif
606
607 TClass* clActual = cr->GetActualClass((void*)obj);
608 if (clActual && clActual != cr.GetClass()) {
609 auto itt = g_name2classrefidx.find(clActual->GetName());
610 if (itt != g_name2classrefidx.end())
611 return (TCppType_t)itt->second;
612 return (TCppType_t)GetScope(clActual->GetName());
613 }
614
615 return klass;
616}
617
619{
620 TClassRef& cr = type_from_handle(klass);
621 if (cr.GetClass() && cr->GetClassInfo())
622 return (size_t)gInterpreter->ClassInfo_Size(cr->GetClassInfo());
623 return (size_t)0;
624}
625
626size_t Cppyy::SizeOf(const std::string& type_name)
627{
628 TDataType* dt = gROOT->GetType(type_name.c_str());
629 if (dt) return dt->Size();
630 return SizeOf(GetScope(type_name));
631}
632
633bool Cppyy::IsBuiltin(const std::string& type_name)
634{
635 TDataType* dt = gROOT->GetType(TClassEdit::CleanType(type_name.c_str(), 1).c_str());
636 if (dt) return dt->GetType() != kOther_t;
637 return false;
638}
639
640bool Cppyy::IsComplete(const std::string& type_name)
641{
642// verify whether the dictionary of this class is fully available
643 bool b = false;
644
645 int oldEIL = gErrorIgnoreLevel;
646 gErrorIgnoreLevel = 3000;
647 TClass* klass = TClass::GetClass(TClassEdit::ShortType(type_name.c_str(), 1).c_str());
648 if (klass && klass->GetClassInfo()) // works for normal case w/ dict
649 b = gInterpreter->ClassInfo_IsLoaded(klass->GetClassInfo());
650 else { // special case for forward declared classes
651 ClassInfo_t* ci = gInterpreter->ClassInfo_Factory(type_name.c_str());
652 if (ci) {
653 b = gInterpreter->ClassInfo_IsLoaded(ci);
654 gInterpreter->ClassInfo_Delete(ci); // we own the fresh class info
655 }
656 }
657 gErrorIgnoreLevel = oldEIL;
658 return b;
659}
660
661// memory management ---------------------------------------------------------
663{
665 return (TCppObject_t)malloc(gInterpreter->ClassInfo_Size(cr->GetClassInfo()));
666}
667
668void Cppyy::Deallocate(TCppType_t /* type */, TCppObject_t instance)
669{
670 ::operator delete(instance);
671}
672
674{
676 return (TCppObject_t)cr->New();
677}
678
679static std::map<Cppyy::TCppType_t, bool> sHasOperatorDelete;
681{
684 cr->Destructor((void*)instance);
685 else {
686 ROOT::DelFunc_t fdel = cr->GetDelete();
687 if (fdel) fdel((void*)instance);
688 else {
689 auto ib = sHasOperatorDelete.find(type);
690 if (ib == sHasOperatorDelete.end()) {
692 ib = sHasOperatorDelete.find(type);
693 }
694 ib->second ? cr->Destructor((void*)instance) : free((void*)instance);
695 }
696 }
697}
698
699
700// method/function dispatching -----------------------------------------------
702{
703// TODO: method should be a callfunc, so that no mapping would be needed.
704 CallWrapper* wrap = (CallWrapper*)method;
705
706 CallFunc_t* callf = gInterpreter->CallFunc_Factory();
707 MethodInfo_t* meth = gInterpreter->MethodInfo_Factory(wrap->fDecl);
708 gInterpreter->CallFunc_SetFunc(callf, meth);
709 gInterpreter->MethodInfo_Delete(meth);
710
711 if (!(callf && gInterpreter->CallFunc_IsValid(callf))) {
712 // TODO: propagate this error to caller w/o use of Python C-API
713 /*
714 PyErr_Format(PyExc_RuntimeError, "could not resolve %s::%s(%s)",
715 const_cast<TClassRef&>(klass).GetClassName(),
716 wrap.fName, callString.c_str()); */
717 std::cerr << "TODO: report unresolved function error to Python\n";
718 if (callf) gInterpreter->CallFunc_Delete(callf);
720 }
721
722// generate the wrapper and JIT it; ignore wrapper generation errors (will simply
723// result in a nullptr that is reported upstream if necessary; often, however,
724// there is a different overload available that will do)
725 auto oldErrLvl = gErrorIgnoreLevel;
727 wrap->fFaceptr = gInterpreter->CallFunc_IFacePtr(callf);
728 gErrorIgnoreLevel = oldErrLvl;
729
730 gInterpreter->CallFunc_Delete(callf); // does not touch IFacePtr
731 return wrap->fFaceptr;
732}
733
734static inline
735bool copy_args(Parameter* args, size_t nargs, void** vargs)
736{
737 bool runRelease = false;
738 for (size_t i = 0; i < nargs; ++i) {
739 switch (args[i].fTypeCode) {
740 case 'X': /* (void*)type& with free */
741 runRelease = true;
742 case 'V': /* (void*)type& */
743 vargs[i] = args[i].fValue.fVoidp;
744 break;
745 case 'r': /* const type& */
746 vargs[i] = args[i].fRef;
747 break;
748 default: /* all other types in union */
749 vargs[i] = (void*)&args[i].fValue.fVoidp;
750 break;
751 }
752 }
753 return runRelease;
754}
755
756static inline
757void release_args(Parameter* args, size_t nargs) {
758 for (size_t i = 0; i < nargs; ++i) {
759 if (args[i].fTypeCode == 'X')
760 free(args[i].fValue.fVoidp);
761 }
762}
763
764static inline bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void* args_, void* self, void* result)
765{
766 Parameter* args = (Parameter*)args_;
767
768 CallWrapper* wrap = (CallWrapper*)method;
769 const TInterpreter::CallFuncIFacePtr_t& faceptr = wrap->fFaceptr.fGeneric ? wrap->fFaceptr : GetCallFunc(method);
770 if (!faceptr.fGeneric)
771 return false; // happens with compilation error
772
774 bool runRelease = false;
775 if (nargs <= SMALL_ARGS_N) {
776 void* smallbuf[SMALL_ARGS_N];
777 if (nargs) runRelease = copy_args(args, nargs, smallbuf);
778 faceptr.fGeneric(self, (int)nargs, smallbuf, result);
779 } else {
780 std::vector<void*> buf(nargs);
781 runRelease = copy_args(args, nargs, buf.data());
782 faceptr.fGeneric(self, (int)nargs, buf.data(), result);
783 }
784 if (runRelease) release_args(args, nargs);
785 return true;
786 }
787
789 bool runRelease = false;
790 if (nargs <= SMALL_ARGS_N) {
791 void* smallbuf[SMALL_ARGS_N];
792 if (nargs) runRelease = copy_args(args, nargs, (void**)smallbuf);
793 faceptr.fCtor((void**)smallbuf, result, (unsigned long)nargs);
794 } else {
795 std::vector<void*> buf(nargs);
796 runRelease = copy_args(args, nargs, buf.data());
797 faceptr.fCtor(buf.data(), result, (unsigned long)nargs);
798 }
799 if (runRelease) release_args(args, nargs);
800 return true;
801 }
802
804 std::cerr << " DESTRUCTOR NOT IMPLEMENTED YET! " << std::endl;
805 return false;
806 }
807
808 return false;
809}
810
811template<typename T>
812static inline
813T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void* args)
814{
815 T t{};
816 if (WrapperCall(method, nargs, args, (void*)self, &t))
817 return t;
818 return (T)-1;
819}
820
821#define CPPYY_IMP_CALL(typecode, rtype) \
822rtype Cppyy::Call##typecode(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)\
823{ \
824 return CallT<rtype>(method, self, nargs, args); \
825}
826
827void Cppyy::CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
828{
829 if (!WrapperCall(method, nargs, args, (void*)self, nullptr))
830 return /* TODO ... report error */;
831}
832
833CPPYY_IMP_CALL(B, unsigned char)
834CPPYY_IMP_CALL(C, char )
835CPPYY_IMP_CALL(H, short )
836CPPYY_IMP_CALL(I, int )
837CPPYY_IMP_CALL(L, long )
839CPPYY_IMP_CALL(F, float )
840CPPYY_IMP_CALL(D, double )
842
843void* Cppyy::CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
844{
845 void* r = nullptr;
846 if (WrapperCall(method, nargs, args, (void*)self, &r))
847 return r;
848 return nullptr;
849}
850
852 TCppMethod_t method, TCppObject_t self, size_t nargs, void* args, size_t* length)
853{
854 char* cstr = nullptr;
855 TClassRef cr("std::string");
856 std::string* cppresult = (std::string*)malloc(sizeof(std::string));
857 if (WrapperCall(method, nargs, args, self, (void*)cppresult)) {
858 cstr = cppstring_to_cstring(*cppresult);
859 *length = cppresult->size();
860 cppresult->std::string::~basic_string();
861 } else
862 *length = 0;
863 free((void*)cppresult);
864 return cstr;
865}
866
868 TCppMethod_t method, TCppType_t /* klass */, size_t nargs, void* args)
869{
870 void* obj = nullptr;
871 if (WrapperCall(method, nargs, args, nullptr, &obj))
872 return (TCppObject_t)obj;
873 return (TCppObject_t)0;
874}
875
877{
879 cr->Destructor((void*)self, true);
880}
881
883 TCppObject_t self, size_t nargs, void* args, TCppType_t result_type)
884{
885 TClassRef& cr = type_from_handle(result_type);
886 void* obj = ::operator new(gInterpreter->ClassInfo_Size(cr->GetClassInfo()));
887 if (WrapperCall(method, nargs, args, self, obj))
888 return (TCppObject_t)obj;
889 ::operator delete(obj);
890 return (TCppObject_t)0;
891}
892
894{
895 if (check_enabled && !gEnableFastPath) return (TCppFuncAddr_t)nullptr;
896 TFunction* f = m2f(method);
897 return (TCppFuncAddr_t)gInterpreter->FindSym(f->GetMangledName());
898}
899
900
901// handling of function argument buffer --------------------------------------
903{
904 return new Parameter[nargs];
905}
906
908{
909 delete [] (Parameter*)args;
910}
911
913{
914 return sizeof(Parameter);
915}
916
918{
919 return offsetof(Parameter, fTypeCode);
920}
921
922
923// scope reflection information ----------------------------------------------
925{
926// Test if this scope represents a namespace.
927 if (scope == GLOBAL_HANDLE)
928 return true;
929 TClassRef& cr = type_from_handle(scope);
930 if (cr.GetClass())
931 return cr->Property() & kIsNamespace;
932 return false;
933}
934
936{
937// Test if this type may not be instantiated.
938 TClassRef& cr = type_from_handle(klass);
939 if (cr.GetClass())
940 return cr->Property() & kIsAbstract;
941 return false;
942}
943
944bool Cppyy::IsEnum(const std::string& type_name)
945{
946 if (type_name.empty()) return false;
947 std::string tn_short = TClassEdit::ShortType(type_name.c_str(), 1);
948 if (tn_short.empty()) return false;
949 return gInterpreter->ClassInfo_IsEnum(tn_short.c_str());
950}
951
952// helpers for stripping scope names
953static
954std::string outer_with_template(const std::string& name)
955{
956// Cut down to the outer-most scope from <name>, taking proper care of templates.
957 int tpl_open = 0;
958 for (std::string::size_type pos = 0; pos < name.size(); ++pos) {
959 std::string::value_type c = name[pos];
960
961 // count '<' and '>' to be able to skip template contents
962 if (c == '<')
963 ++tpl_open;
964 else if (c == '>')
965 --tpl_open;
966
967 // collect name up to "::"
968 else if (tpl_open == 0 && \
969 c == ':' && pos+1 < name.size() && name[pos+1] == ':') {
970 // found the extend of the scope ... done
971 return name.substr(0, pos-1);
972 }
973 }
974
975// whole name is apparently a single scope
976 return name;
977}
978
979static
980std::string outer_no_template(const std::string& name)
981{
982// Cut down to the outer-most scope from <name>, drop templates
983 std::string::size_type first_scope = name.find(':');
984 if (first_scope == std::string::npos)
985 return name.substr(0, name.find('<'));
986 std::string::size_type first_templ = name.find('<');
987 if (first_templ == std::string::npos)
988 return name.substr(0, first_scope);
989 return name.substr(0, std::min(first_templ, first_scope));
990}
991
992#define FILL_COLL(type, filter) { \
993 TIter itr{coll}; \
994 type* obj = nullptr; \
995 while ((obj = (type*)itr.Next())) { \
996 const char* nm = obj->GetName(); \
997 if (nm && nm[0] != '_' && !(obj->Property() & (filter))) { \
998 if (gInitialNames.find(nm) == gInitialNames.end()) \
999 cppnames.insert(nm); \
1000 }}}
1001
1002static inline
1003void cond_add(Cppyy::TCppScope_t scope, const std::string& ns_scope,
1004 std::set<std::string>& cppnames, const char* name, bool nofilter = false)
1005{
1006 if (!name || name[0] == '_' || strstr(name, ".h") != 0 || strncmp(name, "operator", 8) == 0)
1007 return;
1008
1009 if (scope == GLOBAL_HANDLE) {
1010 std::string to_add = outer_no_template(name);
1011 if ((nofilter || gInitialNames.find(to_add) == gInitialNames.end()) && !is_missclassified_stl(name))
1012 cppnames.insert(outer_no_template(name));
1013 } else if (scope == STD_HANDLE) {
1014 if (strncmp(name, "std::", 5) == 0) {
1015 name += 5;
1016#ifdef __APPLE__
1017 if (strncmp(name, "__1::", 5) == 0) name += 5;
1018#endif
1019 } else if (!is_missclassified_stl(name))
1020 return;
1021 cppnames.insert(outer_no_template(name));
1022 } else {
1023 if (strncmp(name, ns_scope.c_str(), ns_scope.size()) == 0)
1024 cppnames.insert(outer_with_template(name + ns_scope.size()));
1025 }
1026}
1027
1028void Cppyy::GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames)
1029{
1030// Collect all known names of C++ entities under scope. This is useful for IDEs
1031// employing tab-completion, for example. Note that functions names need not be
1032// unique as they can be overloaded.
1033 TClassRef& cr = type_from_handle(scope);
1034 if (scope != GLOBAL_HANDLE && !(cr.GetClass() && cr->Property()))
1035 return;
1036
1037 std::string ns_scope = GetFinalName(scope);
1038 if (scope != GLOBAL_HANDLE) ns_scope += "::";
1039
1040// add existing values from read rootmap files if within this scope
1041 TCollection* coll = gInterpreter->GetMapfile()->GetTable();
1042 {
1043 TIter itr{coll};
1044 TEnvRec* ev = nullptr;
1045 while ((ev = (TEnvRec*)itr.Next())) {
1046 // TEnv contains rootmap entries and user-side rootmap files may be already
1047 // loaded on startup. Thus, filter on file name rather than load time.
1048 if (gRootSOs.find(ev->GetValue()) == gRootSOs.end())
1049 cond_add(scope, ns_scope, cppnames, ev->GetName(), true);
1050 }
1051 }
1052
1053// do we care about the class table or are the rootmap and list of types enough?
1054/*
1055 gClassTable->Init();
1056 const int N = gClassTable->Classes();
1057 for (int i = 0; i < N; ++i)
1058 cond_add(scope, ns_scope, cppnames, gClassTable->Next());
1059*/
1060
1061// any other types (e.g. that may have come from parsing headers)
1062 coll = gROOT->GetListOfTypes();
1063 {
1064 TIter itr{coll};
1065 TDataType* dt = nullptr;
1066 while ((dt = (TDataType*)itr.Next())) {
1067 if (!(dt->Property() & kIsFundamental)) {
1068 cond_add(scope, ns_scope, cppnames, dt->GetName());
1069 }
1070 }
1071 }
1072
1073// add functions
1074 coll = (scope == GLOBAL_HANDLE) ?
1075 gROOT->GetListOfGlobalFunctions() : cr->GetListOfMethods();
1076 {
1077 TIter itr{coll};
1078 TFunction* obj = nullptr;
1079 while ((obj = (TFunction*)itr.Next())) {
1080 const char* nm = obj->GetName();
1081 // skip templated functions, adding only the un-instantiated ones
1082 if (nm && nm[0] != '_' && strstr(nm, "<") == 0 && strncmp(nm, "operator", 8) != 0) {
1083 if (gInitialNames.find(nm) == gInitialNames.end())
1084 cppnames.insert(nm);
1085 }
1086 }
1087 }
1088
1089// add uninstantiated templates
1090 coll = (scope == GLOBAL_HANDLE) ?
1091 gROOT->GetListOfFunctionTemplates() : cr->GetListOfFunctionTemplates();
1093
1094// add (global) data members
1095 if (scope == GLOBAL_HANDLE) {
1096 coll = gROOT->GetListOfGlobals();
1098 } else {
1099 coll = cr->GetListOfDataMembers();
1101 coll = cr->GetListOfUsingDataMembers();
1103 }
1104
1105// add enums values only for user classes/namespaces
1106 if (scope != GLOBAL_HANDLE && scope != STD_HANDLE) {
1107 coll = cr->GetListOfEnums();
1109 }
1110
1111#ifdef __APPLE__
1112// special case for Apple, add version namespace '__1' entries to std
1113 if (scope == STD_HANDLE)
1114 GetAllCppNames(GetScope("std::__1"), cppnames);
1115#endif
1116}
1117
1118
1119// class reflection information ----------------------------------------------
1120std::vector<Cppyy::TCppScope_t> Cppyy::GetUsingNamespaces(TCppScope_t scope)
1121{
1122 std::vector<Cppyy::TCppScope_t> res;
1123 if (!IsNamespace(scope))
1124 return res;
1125
1126#ifdef __APPLE__
1127 if (scope == STD_HANDLE) {
1128 res.push_back(GetScope("__1"));
1129 return res;
1130 }
1131#endif
1132
1133 TClassRef& cr = type_from_handle(scope);
1134 if (!cr.GetClass() || !cr->GetClassInfo())
1135 return res;
1136
1137 const std::vector<std::string>& v = gInterpreter->GetUsingNamespaces(cr->GetClassInfo());
1138 res.reserve(v.size());
1139 for (const auto& uid : v) {
1140 Cppyy::TCppScope_t uscope = GetScope(uid);
1141 if (uscope) res.push_back(uscope);
1142 }
1143
1144 return res;
1145}
1146
1147
1148// class reflection information ----------------------------------------------
1150{
1151 if (klass == GLOBAL_HANDLE)
1152 return "";
1153 TClassRef& cr = type_from_handle(klass);
1154 std::string clName = cr->GetName();
1155// TODO: why is this template splitting needed?
1156 std::string::size_type pos = clName.substr(0, clName.find('<')).rfind("::");
1157 if (pos != std::string::npos)
1158 return clName.substr(pos+2, std::string::npos);
1159 return clName;
1160}
1161
1163{
1164 if (klass == GLOBAL_HANDLE)
1165 return "";
1166 TClassRef& cr = type_from_handle(klass);
1167 if (cr.GetClass()) {
1168 std::string name = cr->GetName();
1170 return std::string("std::")+cr->GetName();
1171 return cr->GetName();
1172 }
1173 return "";
1174}
1175
1177{
1178 TClassRef& cr = type_from_handle(klass);
1179 if (!cr.GetClass())
1180 return false;
1181
1182 TFunction* f = cr->GetMethod(("~"+GetFinalName(klass)).c_str(), "");
1183 if (f && (f->Property() & kIsVirtual))
1184 return true;
1185
1186 return false;
1187}
1188
1190{
1191 int is_complex = 1;
1192 size_t nbases = 0;
1193
1194 TClassRef& cr = type_from_handle(klass);
1195 if (cr.GetClass() && cr->GetListOfBases() != 0)
1196 nbases = GetNumBases(klass);
1197
1198 if (1 < nbases)
1199 is_complex = 1;
1200 else if (nbases == 0)
1201 is_complex = 0;
1202 else { // one base class only
1203 TBaseClass* base = (TBaseClass*)cr->GetListOfBases()->At(0);
1204 if (base->Property() & kIsVirtualBase)
1205 is_complex = 1; // TODO: verify; can be complex, need not be.
1206 else
1207 is_complex = HasComplexHierarchy(GetScope(base->GetName()));
1208 }
1209
1210 return is_complex;
1211}
1212
1214{
1215// Get the total number of base classes that this class has.
1216 TClassRef& cr = type_from_handle(klass);
1217 if (cr.GetClass() && cr->GetListOfBases() != 0)
1218 return (TCppIndex_t)cr->GetListOfBases()->GetSize();
1219 return (TCppIndex_t)0;
1220}
1221
1222////////////////////////////////////////////////////////////////////////////////
1223/// \fn Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
1224/// \brief Retrieve number of base classes in the longest branch of the
1225/// inheritance tree of the input class.
1226/// \param[in] klass The class to start the retrieval process from.
1227///
1228/// This is a helper function for Cppyy::GetNumBasesLongestBranch.
1229/// Given an inheritance tree, the function assigns weight 1 to each class that
1230/// has at least one base. Starting from the input class, the function is
1231/// called recursively on all the bases. For each base the return value is one
1232/// (the weight of the base itself) plus the maximum value retrieved for their
1233/// bases in turn. For example, given the following inheritance tree:
1234///
1235/// ~~~{.cpp}
1236/// class A {}; class B: public A {};
1237/// class X {}; class Y: public X {}; class Z: public Y {};
1238/// class C: public B, Z {};
1239/// ~~~
1240///
1241/// calling this function on an instance of `C` will return 3, the steps
1242/// required to go from C to X.
1244{
1245
1246 auto directbases = klass->GetListOfBases();
1247 if (!directbases) {
1248 // This is a leaf with no bases
1249 return 0;
1250 }
1251 auto ndirectbases = directbases->GetSize();
1252 if (ndirectbases == 0) {
1253 // This is a leaf with no bases
1254 return 0;
1255 } else {
1256 // If there is at least one direct base
1257 std::vector<Cppyy::TCppIndex_t> nbases_branches;
1258 nbases_branches.reserve(ndirectbases);
1259
1260 // Traverse all direct bases of the current class and call the function
1261 // recursively
1262 for (auto baseclass : TRangeDynCast<TBaseClass>(directbases)) {
1263 if (!baseclass)
1264 continue;
1265 if (auto baseclass_tclass = baseclass->GetClassPointer()) {
1266 nbases_branches.emplace_back(GetLongestInheritancePath(baseclass_tclass));
1267 }
1268 }
1269
1270 // Get longest path among the direct bases of the current class
1271 auto longestbranch = std::max_element(std::begin(nbases_branches), std::end(nbases_branches));
1272
1273 // Add 1 to include the current class in the count
1274 return 1 + *longestbranch;
1275 }
1276}
1277
1278////////////////////////////////////////////////////////////////////////////////
1279/// \fn Cppyy::TCppIndex_t Cppyy::GetNumBasesLongest(TCppType_t klass)
1280/// \brief Retrieve number of base classes in the longest branch of the
1281/// inheritance tree.
1282/// \param[in] klass The class to start the retrieval process from.
1283///
1284/// The function converts the input class to a `TClass *` and calls
1285/// GetLongestInheritancePath.
1287{
1288
1289 const auto &cr = type_from_handle(klass);
1290
1291 if (auto klass_tclass = cr.GetClass()) {
1292 return GetLongestInheritancePath(klass_tclass);
1293 }
1294
1295 // In any other case, return zero
1296 return 0;
1297}
1298
1300{
1301 TClassRef& cr = type_from_handle(klass);
1302 return ((TBaseClass*)cr->GetListOfBases()->At((int)ibase))->GetName();
1303}
1304
1306{
1307 if (derived == base)
1308 return true;
1309 TClassRef& derived_type = type_from_handle(derived);
1310 TClassRef& base_type = type_from_handle(base);
1311 return derived_type->GetBaseClass(base_type) != 0;
1312}
1313
1315{
1316 TClassRef& cr = type_from_handle(klass);
1317 const std::string& tn = cr->GetName();
1318 if (gSmartPtrTypes.find(tn.substr(0, tn.find("<"))) != gSmartPtrTypes.end())
1319 return true;
1320 return false;
1321}
1322
1324 const std::string& tname, TCppType_t* raw, TCppMethod_t* deref)
1325{
1326 const std::string& rn = ResolveName(tname);
1327 if (gSmartPtrTypes.find(rn.substr(0, rn.find("<"))) != gSmartPtrTypes.end()) {
1328 if (!raw && !deref) return true;
1329
1330 TClassRef& cr = type_from_handle(GetScope(tname));
1331 if (cr.GetClass()) {
1332 TFunction* func = cr->GetMethod("operator->", "");
1333 if (!func) {
1334 gInterpreter->UpdateListOfMethods(cr.GetClass());
1335 func = cr->GetMethod("operator->", "");
1336 }
1337 if (func) {
1338 if (deref) *deref = (TCppMethod_t)new_CallWrapper(func);
1339 if (raw) *raw = GetScope(TClassEdit::ShortType(
1340 func->GetReturnTypeNormalizedName().c_str(), 1));
1341 return (!deref || *deref) && (!raw || *raw);
1342 }
1343 }
1344 }
1345
1346 return false;
1347}
1348
1349void Cppyy::AddSmartPtrType(const std::string& type_name)
1350{
1351 gSmartPtrTypes.insert(ResolveName(type_name));
1352}
1353
1354
1355// type offsets --------------------------------------------------------------
1357 TCppObject_t address, int direction, bool rerror)
1358{
1359// calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0
1360 if (derived == base || !(base && derived))
1361 return (ptrdiff_t)0;
1362
1363 TClassRef& cd = type_from_handle(derived);
1364 TClassRef& cb = type_from_handle(base);
1365
1366 if (!cd.GetClass() || !cb.GetClass())
1367 return (ptrdiff_t)0;
1368
1369 ptrdiff_t offset = -1;
1370 if (!(cd->GetClassInfo() && cb->GetClassInfo())) { // gInterpreter requirement
1371 // would like to warn, but can't quite determine error from intentional
1372 // hiding by developers, so only cover the case where we really should have
1373 // had a class info, but apparently don't:
1374 if (cd->IsLoaded()) {
1375 // warn to allow diagnostics
1376 std::ostringstream msg;
1377 msg << "failed offset calculation between " << cb->GetName() << " and " << cd->GetName();
1378 // TODO: propagate this warning to caller w/o use of Python C-API
1379 // PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(msg.str().c_str()));
1380 std::cerr << "Warning: " << msg.str() << '\n';
1381 }
1382
1383 // return -1 to signal caller NOT to apply offset
1384 return rerror ? (ptrdiff_t)offset : 0;
1385 }
1386
1387 offset = gInterpreter->ClassInfo_GetBaseOffset(
1388 cd->GetClassInfo(), cb->GetClassInfo(), (void*)address, direction > 0);
1389 if (offset == -1) // Cling error, treat silently
1390 return rerror ? (ptrdiff_t)offset : 0;
1391
1392 return (ptrdiff_t)(direction < 0 ? -offset : offset);
1393}
1394
1395
1396// method/function reflection information ------------------------------------
1398{
1399 if (IsNamespace(scope))
1400 return (TCppIndex_t)0; // enforce lazy
1401
1402 TClassRef& cr = type_from_handle(scope);
1403 if (cr.GetClass() && cr->GetListOfMethods(true)) {
1404 Cppyy::TCppIndex_t nMethods = (TCppIndex_t)cr->GetListOfMethods(false)->GetSize();
1405 if (nMethods == (TCppIndex_t)0) {
1406 std::string clName = GetScopedFinalName(scope);
1407 if (clName.find('<') != std::string::npos) {
1408 // chicken-and-egg problem: TClass does not know about methods until
1409 // instantiation, so force it
1410 if (clName.find("std::", 0, 5) == std::string::npos && \
1411 is_missclassified_stl(clName)) {
1412 // TODO: this is too simplistic for template arguments missing std::
1413 clName = "std::" + clName;
1414 }
1415 std::ostringstream stmt;
1416 stmt << "template class " << clName << ";";
1417 gInterpreter->Declare(stmt.str().c_str());
1418
1419 // now reload the methods
1420 return (TCppIndex_t)cr->GetListOfMethods(true)->GetSize();
1421 }
1422 }
1423 return nMethods;
1424 }
1425
1426 return (TCppIndex_t)0; // unknown class?
1427}
1428
1429std::vector<Cppyy::TCppIndex_t> Cppyy::GetMethodIndicesFromName(
1430 TCppScope_t scope, const std::string& name)
1431{
1432 std::vector<TCppIndex_t> indices;
1433 TClassRef& cr = type_from_handle(scope);
1434 if (cr.GetClass()) {
1435 gInterpreter->UpdateListOfMethods(cr.GetClass());
1436 int imeth = 0;
1437 TFunction* func = nullptr;
1438 TIter next(cr->GetListOfMethods());
1439 while ((func = (TFunction*)next())) {
1440 if (match_name(name, func->GetName())) {
1441 if (func->Property() & kIsPublic)
1442 indices.push_back((TCppIndex_t)imeth);
1443 }
1444 ++imeth;
1445 }
1446 } else if (scope == GLOBAL_HANDLE) {
1447 TCollection* funcs = gROOT->GetListOfGlobalFunctions(true);
1448
1449 // tickle deserialization
1450 if (!funcs->FindObject(name.c_str()))
1451 return indices;
1452
1453 TFunction* func = nullptr;
1454 TIter ifunc(funcs);
1455 while ((func = (TFunction*)ifunc.Next())) {
1456 if (match_name(name, func->GetName()))
1457 indices.push_back((TCppIndex_t)new_CallWrapper(func));
1458 }
1459 }
1460
1461 return indices;
1462}
1463
1465{
1466 TClassRef& cr = type_from_handle(scope);
1467 if (cr.GetClass()) {
1468 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
1469 if (f) return (Cppyy::TCppMethod_t)new_CallWrapper(f);
1470 return (Cppyy::TCppMethod_t)nullptr;
1471 }
1472
1473 assert(klass == (Cppyy::TCppType_t)GLOBAL_HANDLE);
1474 return (Cppyy::TCppMethod_t)idx;
1475}
1476
1478{
1479 if (method) {
1480 const std::string& name = ((CallWrapper*)method)->fName;
1481
1482 if (name.compare(0, 8, "operator") != 0)
1483 // strip template instantiation part, if any
1484 return name.substr(0, name.find('<'));
1485 return name;
1486 }
1487 return "<unknown>";
1488}
1489
1491{
1492 if (method) {
1493 std::string name = ((CallWrapper*)method)->fName;
1494 name.erase(std::remove(name.begin(), name.end(), ' '), name.end());
1495 return name;
1496 }
1497 return "<unknown>";
1498}
1499
1501{
1502 if (method)
1503 return m2f(method)->GetMangledName();
1504 return "<unknown>";
1505}
1506
1508{
1509 if (method) {
1510 TFunction* f = m2f(method);
1511 if (f->ExtraProperty() & kIsConstructor)
1512 return "constructor";
1513 std::string restype = f->GetReturnTypeName();
1514 // TODO: this is ugly, but we can't use GetReturnTypeName() for ostreams
1515 // and maybe others, whereas GetReturnTypeNormalizedName() has proven to
1516 // be save in all cases (Note: 'int8_t' covers 'int8_t' and 'uint8_t')
1517 if (restype.find("int8_t") != std::string::npos)
1518 return restype;
1519 restype = f->GetReturnTypeNormalizedName();
1520 if (restype == "(lambda)") {
1521 std::ostringstream s;
1522 // TODO: what if there are parameters to the lambda?
1523 s << "__cling_internal::FT<decltype("
1524 << GetMethodFullName(method) << "(";
1525 for (Cppyy::TCppIndex_t i = 0; i < Cppyy::GetMethodNumArgs(method); ++i) {
1526 if (i != 0) s << ", ";
1527 s << Cppyy::GetMethodArgType(method, i) << "{}";
1528 }
1529 s << "))>::F";
1530 TClass* cl = TClass::GetClass(s.str().c_str());
1531 if (cl) return cl->GetName();
1532 // TODO: signal some type of error (or should that be upstream?
1533 }
1534 return restype;
1535 }
1536 return "<unknown>";
1537}
1538
1540{
1541 if (method)
1542 return m2f(method)->GetNargs();
1543 return 0;
1544}
1545
1547{
1548 if (method) {
1549 TFunction* f = m2f(method);
1550 return (TCppIndex_t)(f->GetNargs() - f->GetNargsOpt());
1551 }
1552 return (TCppIndex_t)0;
1553}
1554
1556{
1557 if (method) {
1558 TFunction* f = m2f(method);
1559 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1560 return arg->GetName();
1561 }
1562 return "<unknown>";
1563}
1564
1566{
1567 if (method) {
1568 TFunction* f = m2f(method);
1569 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1570 return arg->GetTypeNormalizedName();
1571 }
1572 return "<unknown>";
1573}
1574
1576{
1577 if (method) {
1578 TFunction* f = m2f(method);
1579 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1580 const char* def = arg->GetDefault();
1581 if (def)
1582 return def;
1583 }
1584
1585 return "";
1586}
1587
1588std::string Cppyy::GetMethodSignature(TCppMethod_t method, bool show_formalargs, TCppIndex_t maxargs)
1589{
1590 TFunction* f = m2f(method);
1591 if (f) {
1592 std::ostringstream sig;
1593 sig << "(";
1594 int nArgs = f->GetNargs();
1595 if (maxargs != (TCppIndex_t)-1) nArgs = std::min(nArgs, (int)maxargs);
1596 for (int iarg = 0; iarg < nArgs; ++iarg) {
1597 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At(iarg);
1598 sig << arg->GetFullTypeName();
1599 if (show_formalargs) {
1600 const char* argname = arg->GetName();
1601 if (argname && argname[0] != '\0') sig << " " << argname;
1602 const char* defvalue = arg->GetDefault();
1603 if (defvalue && defvalue[0] != '\0') sig << " = " << defvalue;
1604 }
1605 if (iarg != nArgs-1) sig << (show_formalargs ? ", " : ",");
1606 }
1607 sig << ")";
1608 return sig.str();
1609 }
1610 return "<unknown>";
1611}
1612
1613std::string Cppyy::GetMethodPrototype(TCppScope_t scope, TCppMethod_t method, bool show_formalargs)
1614{
1615 std::string scName = GetScopedFinalName(scope);
1616 TFunction* f = m2f(method);
1617 if (f) {
1618 std::ostringstream sig;
1619 sig << f->GetReturnTypeName() << " "
1620 << scName << "::" << f->GetName();
1621 sig << GetMethodSignature(method, show_formalargs);
1622 return sig.str();
1623 }
1624 return "<unknown>";
1625}
1626
1628{
1629 if (method) {
1630 TFunction* f = m2f(method);
1631 return f->Property() & kIsConstMethod;
1632 }
1633 return false;
1634}
1635
1637{
1638 if (scope == (TCppScope_t)GLOBAL_HANDLE) {
1639 TCollection* coll = gROOT->GetListOfFunctionTemplates();
1640 if (coll) return (TCppIndex_t)coll->GetSize();
1641 } else {
1642 TClassRef& cr = type_from_handle(scope);
1643 if (cr.GetClass()) {
1644 TCollection* coll = cr->GetListOfFunctionTemplates(true);
1645 if (coll) return (TCppIndex_t)coll->GetSize();
1646 }
1647 }
1648
1649// failure ...
1650 return (TCppIndex_t)0;
1651}
1652
1654{
1655 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1656 return ((THashList*)gROOT->GetListOfFunctionTemplates())->At((int)imeth)->GetName();
1657 else {
1658 TClassRef& cr = type_from_handle(scope);
1659 if (cr.GetClass())
1660 return cr->GetListOfFunctionTemplates(false)->At((int)imeth)->GetName();
1661 }
1662
1663// failure ...
1664 assert(!"should not be called unless GetNumTemplatedMethods() succeeded");
1665 return "";
1666}
1667
1669{
1670 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1671 return false;
1672
1673 TClassRef& cr = type_from_handle(scope);
1674 if (cr.GetClass()) {
1676 return f->ExtraProperty() & kIsConstructor;
1677 }
1678
1679 return false;
1680}
1681
1682bool Cppyy::ExistsMethodTemplate(TCppScope_t scope, const std::string& name)
1683{
1684 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1685 return (bool)gROOT->GetFunctionTemplate(name.c_str());
1686 else {
1687 TClassRef& cr = type_from_handle(scope);
1688 if (cr.GetClass())
1689 return (bool)cr->GetFunctionTemplate(name.c_str());
1690 }
1691
1692// failure ...
1693 return false;
1694}
1695
1697{
1698 TClassRef& cr = type_from_handle(scope);
1699 if (cr.GetClass()) {
1700 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
1701 if (f && strstr(f->GetName(), "<")) return true;
1702 return false;
1703 }
1704
1705 assert(scope == (Cppyy::TCppType_t)GLOBAL_HANDLE);
1706 if (((CallWrapper*)idx)->fName.find('<') != std::string::npos) return true;
1707 return false;
1708}
1709
1710// helpers for Cppyy::GetMethodTemplate()
1711static std::map<TDictionary::DeclId_t, CallWrapper*> gMethodTemplates;
1712
1714 TCppScope_t scope, const std::string& name, const std::string& proto)
1715{
1716// There is currently no clean way of extracting a templated method out of ROOT/meta
1717// for a variety of reasons, none of them fundamental. The game played below is to
1718// first get any pre-existing functions already managed by ROOT/meta, but if that fails,
1719// to do an explicit lookup that ignores the prototype (i.e. the full name should be
1720// enough), and finally to ignore the template arguments part of the name as this fails
1721// in cling if there are default parameters.
1722// It would be possible to get the prototype from the created functions and use that to
1723// do a new lookup, after which ROOT/meta will manage the function. However, neither
1724// TFunction::GetPrototype() nor TFunction::GetSignature() is of the proper form, so
1725// we'll/ manage the new TFunctions instead and will assume that they are cached on the
1726// calling side to prevent multiple creations.
1727 TFunction* func = nullptr; ClassInfo_t* cl = nullptr;
1728 if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
1729 func = gROOT->GetGlobalFunctionWithPrototype(name.c_str(), proto.c_str());
1730 if (func && name.back() == '>' && name != func->GetName())
1731 func = nullptr; // happens if implicit conversion matches the overload
1732 } else {
1733 TClassRef& cr = type_from_handle(scope);
1734 if (cr.GetClass()) {
1735 func = cr->GetMethodWithPrototype(name.c_str(), proto.c_str());
1736 if (!func) {
1737 cl = cr->GetClassInfo();
1738 // try base classes to cover a common 'using' case (TODO: this is stupid and misses
1739 // out on base classes; fix that with improved access to Cling)
1740 TCppIndex_t nbases = GetNumBases(scope);
1741 for (TCppIndex_t i = 0; i < nbases; ++i) {
1742 TClassRef& base = type_from_handle(GetScope(GetBaseName(scope, i)));
1743 if (base.GetClass()) {
1744 func = base->GetMethodWithPrototype(name.c_str(), proto.c_str());
1745 if (func) break;
1746 }
1747 }
1748 }
1749 }
1750 }
1751
1752 if (!func && name.back() == '>' && (cl || scope == (cppyy_scope_t)GLOBAL_HANDLE)) {
1753 // try again, ignoring proto in case full name is complete template
1754 auto declid = gInterpreter->GetFunction(cl, name.c_str());
1755 if (declid) {
1756 auto existing = gMethodTemplates.find(declid);
1757 if (existing == gMethodTemplates.end()) {
1758 auto cw = new_CallWrapper(declid, name);
1759 existing = gMethodTemplates.insert(std::make_pair(declid, cw)).first;
1760 }
1761 return (TCppMethod_t)existing->second;
1762 }
1763 }
1764
1765 if (func) {
1766 // make sure we didn't match a non-templated overload
1767 if (func->ExtraProperty() & kIsTemplateSpec)
1768 return (TCppMethod_t)new_CallWrapper(func);
1769
1770 // disregard this non-templated method as it will be considered when appropriate
1771 return (TCppMethod_t)nullptr;
1772 }
1773
1774// try again with template arguments removed from name, if applicable
1775 if (name.back() == '>') {
1776 auto pos = name.find('<');
1777 if (pos != std::string::npos) {
1778 TCppMethod_t cppmeth = GetMethodTemplate(scope, name.substr(0, pos), proto);
1779 if (cppmeth) {
1780 // allow if requested template names match up to the result
1781 const std::string& alt = GetMethodFullName(cppmeth);
1782 if (name.size() < alt.size() && alt.find('<') == pos) {
1783 const std::string& partial = name.substr(pos, name.size()-1-pos);
1784 if (strncmp(partial.c_str(), alt.substr(pos, alt.size()-1-pos).c_str(), partial.size()) == 0)
1785 return cppmeth;
1786 }
1787 }
1788 }
1789 }
1790
1791// failure ...
1792 return (TCppMethod_t)nullptr;
1793}
1794
1795static inline
1796std::string type_remap(const std::string& n1, const std::string& n2)
1797{
1798// Operator lookups of (C++ string, Python str) should succeeded, for the combos of
1799// string/str, wstring/str, string/unicode and wstring/unicode; since C++ does not have a
1800// operator+(std::string, std::wstring), we'll have to look up the same type and rely on
1801// the converters in CPyCppyy/_cppyy.
1802 if (n1 == "str") {
1803 if (n2 == "std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >")
1804 return n2; // match like for like
1805 return "std::string"; // probably best bet
1806 } else if (n1 == "float")
1807 return "double"; // debatable, but probably intended
1808 return n1;
1809}
1810
1812 TCppType_t scope, const std::string& lc, const std::string& rc, const std::string& opname)
1813{
1814// Find a global operator function with a matching signature; prefer by-ref, but
1815// fall back on by-value if that fails.
1816 std::string lcname1 = TClassEdit::CleanType(lc.c_str());
1817 const std::string& rcname = rc.empty() ? rc : type_remap(TClassEdit::CleanType(rc.c_str()), lcname1);
1818 const std::string& lcname = type_remap(lcname1, rcname);
1819
1820 std::string proto = lcname + "&" + (rc.empty() ? rc : (", " + rcname + "&"));
1821 if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
1822 TFunction* func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
1823 if (func) return (TCppIndex_t)new_CallWrapper(func);
1824 proto = lcname + (rc.empty() ? rc : (", " + rcname));
1825 func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
1826 if (func) return (TCppIndex_t)new_CallWrapper(func);
1827 } else {
1828 TClassRef& cr = type_from_handle(scope);
1829 if (cr.GetClass()) {
1830 TFunction* func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
1831 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
1832 proto = lcname + (rc.empty() ? rc : (", " + rcname));
1833 func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
1834 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
1835 }
1836 }
1837
1838// failure ...
1839 return (TCppIndex_t)-1;
1840}
1841
1842// method properties ---------------------------------------------------------
1844{
1845 if (method) {
1846 TFunction* f = m2f(method);
1847 return f->Property() & kIsPublic;
1848 }
1849 return false;
1850}
1851
1853{
1854 if (method) {
1855 TFunction* f = m2f(method);
1856 return f->Property() & kIsProtected;
1857 }
1858 return false;
1859}
1860
1862{
1863 if (method) {
1864 TFunction* f = m2f(method);
1865 return f->ExtraProperty() & kIsConstructor;
1866 }
1867 return false;
1868}
1869
1871{
1872 if (method) {
1873 TFunction* f = m2f(method);
1874 return f->ExtraProperty() & kIsDestructor;
1875 }
1876 return false;
1877}
1878
1880{
1881 if (method) {
1882 TFunction* f = m2f(method);
1883 return f->Property() & kIsStatic;
1884 }
1885 return false;
1886}
1887
1888// data member reflection information ----------------------------------------
1890{
1891 if (IsNamespace(scope))
1892 return (TCppIndex_t)0; // enforce lazy
1893
1894 TClassRef& cr = type_from_handle(scope);
1895 if (cr.GetClass()) {
1897 if (cr->GetListOfDataMembers())
1898 sum = cr->GetListOfDataMembers()->GetSize();
1899 if (cr->GetListOfUsingDataMembers())
1901 return sum;
1902 }
1903
1904 return (TCppIndex_t)0; // unknown class?
1905}
1906
1908{
1909 if (!cr.GetClass() || !cr->GetListOfDataMembers())
1910 return nullptr;
1911
1912 int numDMs = cr->GetListOfDataMembers()->GetSize();
1913 if ((int)idata < numDMs)
1914 return (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
1915 return (TDataMember*)cr->GetListOfUsingDataMembers()->At((int)idata - numDMs);
1916}
1917
1919{
1920 TClassRef& cr = type_from_handle(scope);
1921 if (cr.GetClass()) {
1922 TDataMember *m = GetDataMemberByIndex(cr, (int)idata);
1923 return m->GetName();
1924 }
1925 assert(scope == GLOBAL_HANDLE);
1926 TGlobal* gbl = g_globalvars[idata];
1927 return gbl->GetName();
1928}
1929
1931{
1932 if (scope == GLOBAL_HANDLE) {
1933 TGlobal* gbl = g_globalvars[idata];
1934 std::string fullType = gbl->GetFullTypeName();
1935
1936 if ((int)gbl->GetArrayDim() > 1)
1937 fullType.append("*");
1938 else if ((int)gbl->GetArrayDim() == 1) {
1939 std::ostringstream s;
1940 s << '[' << gbl->GetMaxIndex(0) << ']' << std::ends;
1941 fullType.append(s.str());
1942 }
1943 return fullType;
1944 }
1945
1946 TClassRef& cr = type_from_handle(scope);
1947 if (cr.GetClass()) {
1948 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
1949 // TODO: fix this upstream. Usually, we want m->GetFullTypeName(), because it does
1950 // not resolve typedefs, but it looses scopes for inner classes/structs, so in that
1951 // case m->GetTrueTypeName() should be used (this also cleans up the cases where
1952 // the "full type" retains spurious "struct" or "union" in the name).
1953 std::string fullType = m->GetFullTypeName();
1954 if (fullType != m->GetTrueTypeName()) {
1955 const std::string& trueName = m->GetTrueTypeName();
1956 if (fullType.find("::") == std::string::npos && trueName.find("::") != std::string::npos)
1957 fullType = trueName;
1958 }
1959
1960 if ((int)m->GetArrayDim() > 1 || (!m->IsBasic() && m->IsaPointer()))
1961 fullType.append("*");
1962 else if ((int)m->GetArrayDim() == 1) {
1963 std::ostringstream s;
1964 s << '[' << m->GetMaxIndex(0) << ']' << std::ends;
1965 fullType.append(s.str());
1966 }
1967 return fullType;
1968 }
1969
1970 return "<unknown>";
1971}
1972
1974{
1975 if (scope == GLOBAL_HANDLE) {
1976 TGlobal* gbl = g_globalvars[idata];
1977 if (!gbl->GetAddress() || gbl->GetAddress() == (void*)-1) {
1978 // CLING WORKAROUND: make sure variable is loaded
1979 intptr_t addr = (intptr_t)gInterpreter->ProcessLine((std::string("&")+gbl->GetName()+";").c_str());
1980 if (gbl->GetAddress() && gbl->GetAddress() != (void*)-1)
1981 return (intptr_t)gbl->GetAddress(); // now loaded!
1982 return addr; // last resort ...
1983 }
1984 return (intptr_t)gbl->GetAddress();
1985 }
1986
1987 TClassRef& cr = type_from_handle(scope);
1988 if (cr.GetClass()) {
1989 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
1990 // CLING WORKAROUND: the following causes templates to be instantiated first within the proper
1991 // scope, making the lookup succeed and preventing spurious duplicate instantiations later. Also,
1992 // if the variable is not yet loaded, pull it in through gInterpreter.
1993 if (m->Property() & kIsStatic) {
1994 if (strchr(cr->GetName(), '<'))
1995 gInterpreter->ProcessLine(((std::string)cr->GetName()+"::"+m->GetName()+";").c_str());
1996 if ((intptr_t)m->GetOffsetCint() == (intptr_t)-1)
1997 return (intptr_t)gInterpreter->ProcessLine((std::string("&")+cr->GetName()+"::"+m->GetName()+";").c_str());
1998 }
1999 return (intptr_t)m->GetOffsetCint(); // yes, CINT (GetOffset() is both wrong
2000 // and caches that wrong result!
2001 }
2002
2003 return (intptr_t)-1;
2004}
2005
2007{
2008 if (scope == GLOBAL_HANDLE) {
2009 TGlobal* gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2010 if (!gb) gb = (TGlobal*)gROOT->GetListOfGlobals(true /* load */)->FindObject(name.c_str());
2011 if (!gb) {
2012 // some enums are not loaded as they are not considered part of
2013 // the global scope, but of the enum scope; get them w/o checking
2014 TDictionary::DeclId_t did = gInterpreter->GetDataMember(nullptr, name.c_str());
2015 if (did) {
2016 DataMemberInfo_t* t = gInterpreter->DataMemberInfo_Factory(did, nullptr);
2017 ((TListOfDataMembers*)gROOT->GetListOfGlobals())->Get(t, true);
2018 gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2019 }
2020 }
2021
2022 if (gb && strcmp(gb->GetFullTypeName(), "(lambda)") == 0) {
2023 // lambdas use a compiler internal closure type, so we wrap
2024 // them, then return the wrapper's type
2025 // TODO: this current leaks the std::function; also, if possible,
2026 // should instantiate through TClass rather then ProcessLine
2027 std::ostringstream s;
2028 s << "auto __cppyy_internal_wrap_" << name << " = "
2029 "new __cling_internal::FT<decltype(" << name << ")>::F"
2030 "{" << name << "};";
2031 gInterpreter->ProcessLine(s.str().c_str());
2032 TGlobal* wrap = (TGlobal*)gROOT->GetListOfGlobals(true)->FindObject(
2033 ("__cppyy_internal_wrap_"+name).c_str());
2034 if (wrap && wrap->GetAddress()) gb = wrap;
2035 }
2036
2037 if (gb) {
2038 // TODO: do we ever need a reverse lookup?
2039 g_globalvars.push_back(gb);
2040 return TCppIndex_t(g_globalvars.size() - 1);
2041 }
2042
2043 } else {
2044 TClassRef& cr = type_from_handle(scope);
2045 if (cr.GetClass()) {
2046 TDataMember* dm =
2048 // TODO: turning this into an index is silly ...
2049 if (dm) return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf(dm);
2051 if (dm)
2052 return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf(dm)
2053 + cr->GetListOfDataMembers()->GetSize();
2054 }
2055 }
2056
2057 return (TCppIndex_t)-1;
2058}
2059
2060
2061// data member properties ----------------------------------------------------
2063{
2064 if (scope == GLOBAL_HANDLE)
2065 return true;
2066 TClassRef& cr = type_from_handle(scope);
2067 if (cr->Property() & kIsNamespace)
2068 return true;
2069 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2070 return m->Property() & kIsPublic;
2071}
2072
2074{
2075 if (scope == GLOBAL_HANDLE)
2076 return true;
2077 TClassRef& cr = type_from_handle(scope);
2078 if (cr->Property() & kIsNamespace)
2079 return true;
2080 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2081 return m->Property() & kIsProtected;
2082}
2083
2085{
2086 if (scope == GLOBAL_HANDLE)
2087 return true;
2088 TClassRef& cr = type_from_handle(scope);
2089 if (cr->Property() & kIsNamespace)
2090 return true;
2091 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2092 return m->Property() & kIsStatic;
2093}
2094
2096{
2097 if (scope == GLOBAL_HANDLE) {
2098 TGlobal* gbl = g_globalvars[idata];
2099 return gbl->Property() & kIsConstant;
2100 }
2101 TClassRef& cr = type_from_handle(scope);
2102 if (cr.GetClass()) {
2103 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2104 return m->Property() & kIsConstant;
2105 }
2106 return false;
2107}
2108
2110{
2111// TODO: currently, ROOT/meta does not properly distinguish between variables of enum
2112// type, and values of enums. The latter are supposed to be const. This code relies on
2113// odd features (bugs?) to figure out the difference, but this should really be fixed
2114// upstream and/or deserves a new API.
2115
2116 if (scope == GLOBAL_HANDLE) {
2117 TGlobal* gbl = g_globalvars[idata];
2118
2119 // make use of an oddity: enum global variables do not have their kIsStatic bit
2120 // set, whereas enum global values do
2121 return (gbl->Property() & kIsEnum) && (gbl->Property() & kIsStatic);
2122 }
2123
2124 TClassRef& cr = type_from_handle(scope);
2125 if (cr.GetClass()) {
2126 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2127 std::string ti = m->GetTypeName();
2128
2129 // can't check anonymous enums by type name, so just accept them as enums
2130 if (ti.rfind("(anonymous)") != std::string::npos)
2131 return m->Property() & kIsEnum;
2132
2133 // since there seems to be no distinction between data of enum type and enum values,
2134 // check the list of constants for the type to see if there's a match
2135 if (ti.rfind(cr->GetName(), 0) != std::string::npos) {
2136 std::string::size_type s = strlen(cr->GetName())+2;
2137 if (s < ti.size()) {
2138 TEnum* ee = ((TListOfEnums*)cr->GetListOfEnums())->GetObject(ti.substr(s, std::string::npos).c_str());
2139 if (ee) return ee->GetConstant(m->GetName());
2140 }
2141 }
2142 }
2143
2144// this default return only means that the data will be writable, not that it will
2145// be unreadable or otherwise misrepresented
2146 return false;
2147}
2148
2149int Cppyy::GetDimensionSize(TCppScope_t scope, TCppIndex_t idata, int dimension)
2150{
2151 if (scope == GLOBAL_HANDLE) {
2152 TGlobal* gbl = g_globalvars[idata];
2153 return gbl->GetMaxIndex(dimension);
2154 }
2155 TClassRef& cr = type_from_handle(scope);
2156 if (cr.GetClass()) {
2157 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2158 return m->GetMaxIndex(dimension);
2159 }
2160 return -1;
2161}
2162
2163
2164// enum properties -----------------------------------------------------------
2165Cppyy::TCppEnum_t Cppyy::GetEnum(TCppScope_t scope, const std::string& enum_name)
2166{
2167 if (scope == GLOBAL_HANDLE)
2168 return (TCppEnum_t)gROOT->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2169
2170 TClassRef& cr = type_from_handle(scope);
2171 if (cr.GetClass())
2172 return (TCppEnum_t)cr->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2173
2174 return (TCppEnum_t)0;
2175}
2176
2178{
2179 return (TCppIndex_t)((TEnum*)etype)->GetConstants()->GetSize();
2180}
2181
2183{
2184 return ((TEnumConstant*)((TEnum*)etype)->GetConstants()->At(idata))->GetName();
2185}
2186
2188{
2189 TEnumConstant* ecst = (TEnumConstant*)((TEnum*)etype)->GetConstants()->At(idata);
2190 return (long long)ecst->GetValue();
2191}
2192
2193
2194//- C-linkage wrappers -------------------------------------------------------
2195
2196extern "C" {
2197/* direct interpreter access ---------------------------------------------- */
2198int cppyy_compile(const char* code) {
2199 return Cppyy::Compile(code);
2200}
2201
2202
2203/* name to opaque C++ scope representation -------------------------------- */
2204char* cppyy_resolve_name(const char* cppitem_name) {
2205 return cppstring_to_cstring(Cppyy::ResolveName(cppitem_name));
2206}
2207
2208char* cppyy_resolve_enum(const char* enum_type) {
2209 return cppstring_to_cstring(Cppyy::ResolveEnum(enum_type));
2210}
2211
2212cppyy_scope_t cppyy_get_scope(const char* scope_name) {
2213 return cppyy_scope_t(Cppyy::GetScope(scope_name));
2214}
2215
2217 return cppyy_type_t(Cppyy::GetActualClass(klass, (void*)obj));
2218}
2219
2221 return Cppyy::SizeOf(klass);
2222}
2223
2224size_t cppyy_size_of_type(const char* type_name) {
2225 return Cppyy::SizeOf(type_name);
2226}
2227
2228
2229/* memory management ------------------------------------------------------ */
2232}
2233
2235 Cppyy::Deallocate(type, (void*)self);
2236}
2237
2240}
2241
2243 Cppyy::Destruct(type, (void*)self);
2244}
2245
2246
2247/* method/function dispatching -------------------------------------------- */
2248/* Exception types:
2249 1: default (unknown exception)
2250 2: standard exception
2251*/
2252#define CPPYY_HANDLE_EXCEPTION \
2253 catch (std::exception& e) { \
2254 cppyy_exctype_t* etype = (cppyy_exctype_t*)((Parameter*)args+nargs); \
2255 *etype = (cppyy_exctype_t)2; \
2256 *((char**)(etype+1)) = cppstring_to_cstring(e.what()); \
2257 } \
2258 catch (...) { \
2259 cppyy_exctype_t* etype = (cppyy_exctype_t*)((Parameter*)args+nargs); \
2260 *etype = (cppyy_exctype_t)1; \
2261 *((char**)(etype+1)) = \
2262 cppstring_to_cstring("unhandled, unknown C++ exception"); \
2263 }
2264
2265void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2266 try {
2267 Cppyy::CallV(method, (void*)self, nargs, args);
2269}
2270
2271unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2272 try {
2273 return (unsigned char)Cppyy::CallB(method, (void*)self, nargs, args);
2275 return (unsigned char)-1;
2276}
2277
2278char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2279 try {
2280 return (char)Cppyy::CallC(method, (void*)self, nargs, args);
2282 return (char)-1;
2283}
2284
2285short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2286 try {
2287 return (short)Cppyy::CallH(method, (void*)self, nargs, args);
2289 return (short)-1;
2290}
2291
2292int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2293 try {
2294 return (int)Cppyy::CallI(method, (void*)self, nargs, args);
2296 return (int)-1;
2297}
2298
2299long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2300 try {
2301 return (long)Cppyy::CallL(method, (void*)self, nargs, args);
2303 return (long)-1;
2304}
2305
2306long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2307 try {
2308 return (long long)Cppyy::CallLL(method, (void*)self, nargs, args);
2310 return (long long)-1;
2311}
2312
2313float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2314 try {
2315 return (float)Cppyy::CallF(method, (void*)self, nargs, args);
2317 return (float)-1;
2318}
2319
2320double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2321 try {
2322 return (double)Cppyy::CallD(method, (void*)self, nargs, args);
2324 return (double)-1;
2325}
2326
2327long double cppyy_call_ld(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2328 try {
2329 return (long double)Cppyy::CallLD(method, (void*)self, nargs, args);
2331 return (long double)-1;
2332}
2333
2334double cppyy_call_nld(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2335 return (double)cppyy_call_ld(method, self, nargs, args);
2336}
2337
2338void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2339 try {
2340 return (void*)Cppyy::CallR(method, (void*)self, nargs, args);
2342 return (void*)nullptr;
2343}
2344
2346 cppyy_method_t method, cppyy_object_t self, int nargs, void* args, size_t* lsz) {
2347 try {
2348 return Cppyy::CallS(method, (void*)self, nargs, args, lsz);
2350 return (char*)nullptr;
2351}
2352
2354 cppyy_method_t method, cppyy_type_t klass, int nargs, void* args) {
2355 try {
2356 return cppyy_object_t(Cppyy::CallConstructor(method, klass, nargs, args));
2358 return (cppyy_object_t)0;
2359}
2360
2362 Cppyy::CallDestructor(klass, self);
2363}
2364
2366 int nargs, void* args, cppyy_type_t result_type) {
2367 try {
2368 return cppyy_object_t(Cppyy::CallO(method, (void*)self, nargs, args, result_type));
2370 return (cppyy_object_t)0;
2371}
2372
2374 return cppyy_funcaddr_t(Cppyy::GetFunctionAddress(method, true));
2375}
2376
2377
2378/* handling of function argument buffer ----------------------------------- */
2380// for calls through C interface, require extra space for reporting exceptions
2381 return malloc(nargs*sizeof(Parameter)+sizeof(cppyy_exctype_t)+sizeof(char**));
2382}
2383
2385 free(args);
2386}
2387
2389 return (size_t)Cppyy::GetFunctionArgSizeof();
2390}
2391
2393 return (size_t)Cppyy::GetFunctionArgTypeoffset();
2394}
2395
2396
2397/* scope reflection information ------------------------------------------- */
2399 return (int)Cppyy::IsNamespace(scope);
2400}
2401
2402int cppyy_is_template(const char* template_name) {
2403 return (int)Cppyy::IsTemplate(template_name);
2404}
2405
2407 return (int)Cppyy::IsAbstract(type);
2408}
2409
2410int cppyy_is_enum(const char* type_name) {
2411 return (int)Cppyy::IsEnum(type_name);
2412}
2413
2414const char** cppyy_get_all_cpp_names(cppyy_scope_t scope, size_t* count) {
2415 std::set<std::string> cppnames;
2416 Cppyy::GetAllCppNames(scope, cppnames);
2417 const char** c_cppnames = (const char**)malloc(cppnames.size()*sizeof(const char*));
2418 int i = 0;
2419 for (const auto& name : cppnames) {
2420 c_cppnames[i] = cppstring_to_cstring(name);
2421 ++i;
2422 }
2423 *count = cppnames.size();
2424 return c_cppnames;
2425}
2426
2427
2428/* namespace reflection information --------------------------------------- */
2430 const std::vector<Cppyy::TCppScope_t>& uv = Cppyy::GetUsingNamespaces((Cppyy::TCppScope_t)scope);
2431
2432 if (uv.empty())
2433 return (cppyy_index_t*)nullptr;
2434
2435 cppyy_scope_t* llresult = (cppyy_scope_t*)malloc(sizeof(cppyy_scope_t)*(uv.size()+1));
2436 for (int i = 0; i < (int)uv.size(); ++i) llresult[i] = uv[i];
2437 llresult[uv.size()] = (cppyy_scope_t)0;
2438 return llresult;
2439}
2440
2441
2442/* class reflection information ------------------------------------------- */
2445}
2446
2449}
2450
2452 return (int)Cppyy::HasVirtualDestructor(type);
2453}
2454
2456 return (int)Cppyy::HasComplexHierarchy(type);
2457}
2458
2460 return (int)Cppyy::GetNumBases(type);
2461}
2462
2465}
2466
2467char* cppyy_base_name(cppyy_type_t type, int base_index) {
2468 return cppstring_to_cstring(Cppyy::GetBaseName (type, base_index));
2469}
2470
2472 return (int)Cppyy::IsSubtype(derived, base);
2473}
2474
2476 return (int)Cppyy::IsSmartPtr(type);
2477}
2478
2479int cppyy_smartptr_info(const char* name, cppyy_type_t* raw, cppyy_method_t* deref) {
2480 return (int)Cppyy::GetSmartPtrInfo(name, raw, deref);
2481}
2482
2483void cppyy_add_smartptr_type(const char* type_name) {
2484 Cppyy::AddSmartPtrType(type_name);
2485}
2486
2487
2488/* calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0 */
2489ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, cppyy_object_t address, int direction) {
2490 return (ptrdiff_t)Cppyy::GetBaseOffset(derived, base, (void*)address, direction, 0);
2491}
2492
2493
2494/* method/function reflection information --------------------------------- */
2496 return (int)Cppyy::GetNumMethods(scope);
2497}
2498
2500{
2501 std::vector<cppyy_index_t> result = Cppyy::GetMethodIndicesFromName(scope, name);
2502
2503 if (result.empty())
2504 return (cppyy_index_t*)nullptr;
2505
2506 cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
2507 for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
2508 llresult[result.size()] = -1;
2509 return llresult;
2510}
2511
2513 return cppyy_method_t(Cppyy::GetMethod(scope, idx));
2514}
2515
2518}
2519
2522}
2523
2526}
2527
2530}
2531
2533 return (int)Cppyy::GetMethodNumArgs((Cppyy::TCppMethod_t)method);
2534}
2535
2537 return (int)Cppyy::GetMethodReqArgs((Cppyy::TCppMethod_t)method);
2538}
2539
2540char* cppyy_method_arg_name(cppyy_method_t method, int arg_index) {
2542}
2543
2544char* cppyy_method_arg_type(cppyy_method_t method, int arg_index) {
2546}
2547
2548char* cppyy_method_arg_default(cppyy_method_t method, int arg_index) {
2550}
2551
2552char* cppyy_method_signature(cppyy_method_t method, int show_formalargs) {
2553 return cppstring_to_cstring(Cppyy::GetMethodSignature((Cppyy::TCppMethod_t)method, (bool)show_formalargs));
2554}
2555
2556char* cppyy_method_signature_max(cppyy_method_t method, int show_formalargs, int maxargs) {
2557 return cppstring_to_cstring(Cppyy::GetMethodSignature((Cppyy::TCppMethod_t)method, (bool)show_formalargs, (Cppyy::TCppIndex_t)maxargs));
2558}
2559
2560char* cppyy_method_prototype(cppyy_scope_t scope, cppyy_method_t method, int show_formalargs) {
2562 (Cppyy::TCppScope_t)scope, (Cppyy::TCppMethod_t)method, (bool)show_formalargs));
2563}
2564
2566 return (int)Cppyy::IsConstMethod(method);
2567}
2568
2570 return (int)Cppyy::GetNumTemplatedMethods(scope);
2571}
2572
2575}
2576
2579}
2580
2582 return (int)Cppyy::ExistsMethodTemplate(scope, name);
2583}
2584
2586 return (int)Cppyy::IsMethodTemplate(scope, idx);
2587}
2588
2591}
2592
2595}
2596
2597
2598/* method properties ------------------------------------------------------ */
2600 return (int)Cppyy::IsPublicMethod((Cppyy::TCppMethod_t)method);
2601}
2602
2604 return (int)Cppyy::IsProtectedMethod((Cppyy::TCppMethod_t)method);
2605}
2606
2608 return (int)Cppyy::IsConstructor((Cppyy::TCppMethod_t)method);
2609}
2610
2612 return (int)Cppyy::IsDestructor((Cppyy::TCppMethod_t)method);
2613}
2614
2616 return (int)Cppyy::IsStaticMethod((Cppyy::TCppMethod_t)method);
2617}
2618
2619
2620/* data member reflection information ------------------------------------- */
2622 return (int)Cppyy::GetNumDatamembers(scope);
2623}
2624
2625char* cppyy_datamember_name(cppyy_scope_t scope, int datamember_index) {
2626 return cppstring_to_cstring(Cppyy::GetDatamemberName(scope, datamember_index));
2627}
2628
2629char* cppyy_datamember_type(cppyy_scope_t scope, int datamember_index) {
2630 return cppstring_to_cstring(Cppyy::GetDatamemberType(scope, datamember_index));
2631}
2632
2633intptr_t cppyy_datamember_offset(cppyy_scope_t scope, int datamember_index) {
2634 return intptr_t(Cppyy::GetDatamemberOffset(scope, datamember_index));
2635}
2636
2638 return (int)Cppyy::GetDatamemberIndex(scope, name);
2639}
2640
2641
2642
2643/* data member properties ------------------------------------------------- */
2645 return (int)Cppyy::IsPublicData(type, datamember_index);
2646}
2647
2649 return (int)Cppyy::IsProtectedData(type, datamember_index);
2650}
2651
2653 return (int)Cppyy::IsStaticData(type, datamember_index);
2654}
2655
2657 return (int)Cppyy::IsConstData(scope, idata);
2658}
2659
2661 return (int)Cppyy::IsEnumData(scope, idata);
2662}
2663
2664int cppyy_get_dimension_size(cppyy_scope_t scope, cppyy_index_t idata, int dimension) {
2665 return Cppyy::GetDimensionSize(scope, idata, dimension);
2666}
2667
2668
2669/* misc helpers ----------------------------------------------------------- */
2671void* cppyy_load_dictionary(const char* lib_name) {
2672 int result = gSystem->Load(lib_name);
2673 return (void*)(result == 0 /* success */ || result == 1 /* already loaded */);
2674}
2675
2676#if defined(_MSC_VER)
2677long long cppyy_strtoll(const char* str) {
2678 return _strtoi64(str, NULL, 0);
2679}
2680
2681extern "C" {
2682unsigned long long cppyy_strtoull(const char* str) {
2683 return _strtoui64(str, NULL, 0);
2684}
2685}
2686#else
2687long long cppyy_strtoll(const char* str) {
2688 return strtoll(str, NULL, 0);
2689}
2690
2691extern "C" {
2692unsigned long long cppyy_strtoull(const char* str) {
2693 return strtoull(str, NULL, 0);
2694}
2695}
2696#endif
2697
2698void cppyy_free(void* ptr) {
2699 free(ptr);
2700}
2701
2702cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz) {
2703 return (cppyy_object_t)new std::string(str, sz);
2704}
2705
2706const char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz) {
2707 *lsz = ((std::string*)ptr)->size();
2708 return ((std::string*)ptr)->data();
2709}
2710
2712 return (cppyy_object_t)new std::string(*(std::string*)ptr);
2713}
2714
2716 return (double)*(long double*)p;
2717}
2718
2719void cppyy_double2longdouble(double d, void* p) {
2720 *(long double*)p = d;
2721}
2722
2724 return (int)(*(std::vector<bool>*)ptr)[idx];
2725}
2726
2727void cppyy_vectorbool_setitem(cppyy_object_t ptr, int idx, int value) {
2728 (*(std::vector<bool>*)ptr)[idx] = (bool)value;
2729}
2730
2731} // end C-linkage wrappers
long
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
ROOT::R::TRInterface & r
Definition Object.C:4
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
long double LongDouble_t
Definition RtypesCore.h:61
long long Long64_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:100
@ kMAXSIGNALS
Definition Rtypes.h:59
@ kOther_t
Definition TDataType.h:32
@ kIsDestructor
@ kIsTemplateSpec
@ kIsConstructor
@ kClassHasExplicitDtor
@ kClassHasImplicitDtor
@ kIsPublic
Definition TDictionary.h:75
@ kIsConstant
Definition TDictionary.h:88
@ kIsConstMethod
Definition TDictionary.h:96
@ kIsEnum
Definition TDictionary.h:68
@ kIsPrivate
Definition TDictionary.h:77
@ kIsFundamental
Definition TDictionary.h:70
@ kIsAbstract
Definition TDictionary.h:71
@ kIsStatic
Definition TDictionary.h:80
@ kIsProtected
Definition TDictionary.h:76
@ kIsVirtual
Definition TDictionary.h:72
@ kIsNamespace
Definition TDictionary.h:95
@ kIsVirtualBase
Definition TDictionary.h:89
constexpr Int_t kFatal
Definition TError.h:49
R__EXTERN Int_t gErrorIgnoreLevel
Definition TError.h:127
R__EXTERN TExceptionHandler * gExceptionHandler
Definition TException.h:84
R__EXTERN ExceptionContext_t * gException
Definition TException.h:74
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
#define gInterpreter
#define gROOT
Definition TROOT.h:404
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
static struct Signalmap_t gSignalMap[kMAXSIGNALS]
size_t cppyy_scope_t
Definition capi.h:12
cppyy_scope_t cppyy_type_t
Definition capi.h:13
intptr_t cppyy_method_t
Definition capi.h:15
size_t cppyy_index_t
Definition capi.h:17
void * cppyy_object_t
Definition capi.h:14
unsigned long cppyy_exctype_t
Definition capi.h:20
void * cppyy_funcaddr_t
Definition capi.h:18
const char * proto
Definition civetweb.c:16613
#define free
Definition civetweb.c:1539
#define malloc
Definition civetweb.c:1536
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:28
TClass * GetClass() const
Definition TClassRef.h:70
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
TList * GetListOfUsingDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of using declarations of a class.
Definition TClass.cxx:3772
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4964
TMethod * GetMethod(const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Find the best method (if there is one) matching the parameters.
Definition TClass.cxx:4397
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4442
const TList * GetListOfAllPublicMethods(Bool_t load=kTRUE)
Returns a list of all public methods of this class and its base classes.
Definition TClass.cxx:3831
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5386
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return TListOfFunctionTemplates for a class.
Definition TClass.cxx:3784
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition TClass.cxx:3672
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3798
TClass * GetBaseClass(const char *classname)
Return pointer to the base class "classname".
Definition TClass.cxx:2653
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3756
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3622
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:5898
ClassInfo_t * GetClassInfo() const
Definition TClass.h:430
Long_t Property() const
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6072
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2395
ROOT::DelFunc_t GetDelete() const
Return the wrapper around delete ThiObject.
Definition TClass.cxx:7449
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
Definition TClass.cxx:2606
TFunctionTemplate * GetFunctionTemplate(const char *name)
Definition TClass.cxx:3593
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2966
Collection abstract base class.
Definition TCollection.h:65
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Int_t GetType() const
Definition TDataType.h:68
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: "class TDirectory*".
Int_t Size() const
Get size of basic typedef'ed type.
const void * DeclId_t
The TEnumConstant class implements the constants of the enum type.
Long64_t GetValue() const
The TEnum class implements the enum type.
Definition TEnum.h:33
const TEnumConstant * GetConstant(const char *name) const
Definition TEnum.h:61
Definition TEnv.h:86
const char * GetValue() const
Definition TEnv.h:110
const char * GetName() const
Returns name of object.
Definition TEnv.h:109
virtual void HandleException(int sig)=0
Dictionary for function template This class describes one single function template.
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Int_t GetNargs() const
Number of function arguments.
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
Global variables class (global variables are obtained from CINT).
Definition TGlobal.h:28
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition TGlobal.cxx:85
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition TGlobal.cxx:148
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition TGlobal.cxx:101
virtual void * GetAddress() const
Return address of global.
Definition TGlobal.cxx:77
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition TGlobal.cxx:120
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TObject * Next()
A collection of TDataMember objects designed for fast access given a DeclId_t and for keep track of T...
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
const char * GetDefault() const
Get default value of method argument.
std::string GetTypeNormalizedName() const
Get the normalized name of the return type.
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:429
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:393
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2834
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1855
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:719
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:735
char * cppyy_method_mangled_name(cppyy_method_t method)
int cppyy_is_staticdata(cppyy_type_t type, cppyy_index_t datamember_index)
int cppyy_vectorbool_getitem(cppyy_object_t ptr, int idx)
int cppyy_has_virtual_destructor(cppyy_type_t type)
int cppyy_is_publicmethod(cppyy_method_t method)
void * cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t klass, int nargs, void *args)
static void cond_add(Cppyy::TCppScope_t scope, const std::string &ns_scope, std::set< std::string > &cppnames, const char *name, bool nofilter=false)
size_t cppyy_function_arg_typeoffset()
int cppyy_exists_method_template(cppyy_scope_t scope, const char *name)
int cppyy_get_num_templated_methods(cppyy_scope_t scope)
char * cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void *args, size_t *lsz)
char * cppyy_resolve_enum(const char *enum_type)
cppyy_object_t cppyy_charp2stdstring(const char *str, size_t sz)
static Name2ClassRefIndex_t g_name2classrefidx
int cppyy_is_constructor(cppyy_method_t method)
int cppyy_is_enum_data(cppyy_scope_t scope, cppyy_index_t idata)
#define FILL_COLL(type, filter)
char * cppyy_scoped_final_name(cppyy_type_t type)
int cppyy_num_bases(cppyy_type_t type)
const int SMALL_ARGS_N
static std::string outer_with_template(const std::string &name)
cppyy_method_t cppyy_get_method_template(cppyy_scope_t scope, const char *name, const char *proto)
static std::string outer_no_template(const std::string &name)
int cppyy_is_smartptr(cppyy_type_t type)
static std::string type_remap(const std::string &n1, const std::string &n2)
static std::map< Cppyy::TCppType_t, bool > sHasOperatorDelete
long long cppyy_strtoll(const char *str)
static std::set< std::string > gRootSOs
int cppyy_is_subtype(cppyy_type_t derived, cppyy_type_t base)
static TClassRef & type_from_handle(Cppyy::TCppScope_t scope)
double cppyy_call_nld(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
void cppyy_free(void *ptr)
int cppyy_smartptr_info(const char *name, cppyy_type_t *raw, cppyy_method_t *deref)
unsigned long long cppyy_strtoull(const char *str)
char * cppyy_method_arg_type(cppyy_method_t method, int arg_index)
cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr)
char * cppyy_base_name(cppyy_type_t type, int base_index)
cppyy_scope_t * cppyy_get_using_namespaces(cppyy_scope_t scope)
static bool copy_args(Parameter *args, size_t nargs, void **vargs)
int cppyy_num_bases_longest_branch(cppyy_type_t type)
static TInterpreter::CallFuncIFacePtr_t GetCallFunc(Cppyy::TCppMethod_t method)
int cppyy_is_publicdata(cppyy_type_t type, cppyy_index_t datamember_index)
CPyCppyy::Parameter Parameter
intptr_t cppyy_datamember_offset(cppyy_scope_t scope, int datamember_index)
char * cppyy_datamember_type(cppyy_scope_t scope, int datamember_index)
static bool is_missclassified_stl(const std::string &name)
std::map< std::string, ClassRefs_t::size_type > Name2ClassRefIndex_t
void cppyy_destructor(cppyy_type_t klass, cppyy_object_t self)
static const ClassRefs_t::size_type STD_HANDLE
char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, cppyy_object_t address, int direction)
long double cppyy_call_ld(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_const_data(cppyy_scope_t scope, cppyy_index_t idata)
const char ** cppyy_get_all_cpp_names(cppyy_scope_t scope, size_t *count)
void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
static std::set< std::string > gSmartPtrTypes
double cppyy_longdouble2double(void *p)
int cppyy_method_req_args(cppyy_method_t method)
int cppyy_is_staticmethod(cppyy_method_t method)
static GlobalVars_t g_globalvars
cppyy_index_t * cppyy_method_indices_from_name(cppyy_scope_t scope, const char *name)
static char * cppstring_to_cstring(const std::string &cppstr)
char * cppyy_method_signature(cppyy_method_t method, int show_formalargs)
int cppyy_is_abstract(cppyy_type_t type)
static void release_args(Parameter *args, size_t nargs)
int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
static std::set< std::string > g_builtins
unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_template(const char *template_name)
char * cppyy_method_result_type(cppyy_method_t method)
cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj)
int cppyy_is_templated_constructor(cppyy_scope_t scope, cppyy_index_t imeth)
char * cppyy_method_name(cppyy_method_t method)
int cppyy_is_protectedmethod(cppyy_method_t method)
char * cppyy_final_name(cppyy_type_t type)
char * cppyy_get_templated_method_name(cppyy_scope_t scope, cppyy_index_t imeth)
char * cppyy_method_full_name(cppyy_method_t method)
long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
void cppyy_double2longdouble(double d, void *p)
void cppyy_deallocate_function_args(void *args)
int cppyy_method_is_template(cppyy_scope_t scope, cppyy_index_t idx)
static std::vector< CallWrapper * > gWrapperHolder
static bool gEnableFastPath
void cppyy_destruct(cppyy_type_t type, cppyy_object_t self)
int cppyy_is_enum(const char *type_name)
size_t cppyy_size_of_type(const char *type_name)
int cppyy_is_destructor(cppyy_method_t method)
cppyy_object_t cppyy_allocate(cppyy_type_t type)
char * cppyy_datamember_name(cppyy_scope_t scope, int datamember_index)
cppyy_object_t cppyy_construct(cppyy_type_t type)
static ClassRefs_t g_classrefs(1)
static bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void *args_, void *self, void *result)
static std::map< std::string, std::string > resolved_enum_types
int cppyy_is_namespace(cppyy_scope_t scope)
cppyy_object_t cppyy_call_o(cppyy_method_t method, cppyy_object_t self, int nargs, void *args, cppyy_type_t result_type)
long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
cppyy_scope_t cppyy_get_scope(const char *scope_name)
void cppyy_vectorbool_setitem(cppyy_object_t ptr, int idx, int value)
static CallWrapper * new_CallWrapper(TFunction *f)
void cppyy_add_smartptr_type(const char *type_name)
void * cppyy_allocate_function_args(int nargs)
float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_protecteddata(cppyy_type_t type, cppyy_index_t datamember_index)
static std::set< std::string > gSTLNames
static const ClassRefs_t::size_type GLOBAL_HANDLE
int cppyy_get_dimension_size(cppyy_scope_t scope, cppyy_index_t idata, int dimension)
char * cppyy_method_signature_max(cppyy_method_t method, int show_formalargs, int maxargs)
double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_num_methods(cppyy_scope_t scope)
char * cppyy_method_prototype(cppyy_scope_t scope, cppyy_method_t method, int show_formalargs)
std::vector< TGlobal * > GlobalVars_t
char * cppyy_resolve_name(const char *cppitem_name)
cppyy_method_t cppyy_get_method(cppyy_scope_t scope, cppyy_index_t idx)
std::vector< TClassRef > ClassRefs_t
size_t cppyy_function_arg_sizeof()
int cppyy_is_const_method(cppyy_method_t method)
static std::map< TDictionary::DeclId_t, CallWrapper * > gMethodTemplates
int cppyy_num_datamembers(cppyy_scope_t scope)
#define CPPYY_HANDLE_EXCEPTION
size_t cppyy_size_of_klass(cppyy_type_t klass)
static bool match_name(const std::string &tname, const std::string fname)
int cppyy_datamember_index(cppyy_scope_t scope, const char *name)
cppyy_index_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char *op)
static TFunction * m2f(Cppyy::TCppMethod_t method)
void cppyy_deallocate(cppyy_type_t type, cppyy_object_t self)
const char * cppyy_stdstring2charp(cppyy_object_t ptr, size_t *lsz)
int cppyy_compile(const char *code)
static TDataMember * GetDataMemberByIndex(TClassRef cr, int idata)
#define CPPYY_IMP_CALL(typecode, rtype)
int cppyy_method_num_args(cppyy_method_t method)
static std::set< std::string > gInitialNames
char * cppyy_method_arg_default(cppyy_method_t method, int arg_index)
RPY_EXTERN void * cppyy_load_dictionary(const char *lib_name)
static T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void *args)
cppyy_funcaddr_t cppyy_function_address(cppyy_method_t method)
int cppyy_has_complex_hierarchy(cppyy_type_t type)
Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
Retrieve number of base classes in the longest branch of the inheritance tree of the input class.
char * cppyy_method_arg_name(cppyy_method_t method, int arg_index)
const Int_t n
Definition legend1.C:16
#define F(x, y, z)
#define I(x, y, z)
#define H(x, y, z)
RPY_EXPORTED short CallH(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
size_t TCppIndex_t
Definition cpp_cppyy.h:24
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool Compile(const std::string &code)
RPY_EXPORTED TCppObject_t Allocate(TCppType_t type)
RPY_EXPORTED TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED TCppIndex_t GetNumEnumData(TCppEnum_t)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
intptr_t TCppMethod_t
Definition cpp_cppyy.h:22
RPY_EXPORTED std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED void AddSmartPtrType(const std::string &)
RPY_EXPORTED bool IsBuiltin(const std::string &type_name)
RPY_EXPORTED TCppIndex_t GetNumBasesLongestBranch(TCppType_t type)
RPY_EXPORTED bool GetSmartPtrInfo(const std::string &, TCppType_t *raw, TCppMethod_t *deref)
RPY_EXPORTED size_t GetFunctionArgTypeoffset()
RPY_EXPORTED void * AllocateFunctionArgs(size_t nargs)
RPY_EXPORTED bool IsProtectedMethod(TCppMethod_t method)
RPY_EXPORTED std::string GetMethodSignature(TCppMethod_t, bool show_formalargs, TCppIndex_t maxargs=(TCppIndex_t) -1)
RPY_EXPORTED std::string GetMethodPrototype(TCppScope_t scope, TCppMethod_t, bool show_formalargs)
RPY_EXPORTED unsigned char CallB(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetTemplatedMethodName(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
RPY_EXPORTED TCppIndex_t GetGlobalOperator(TCppType_t scope, const std::string &lc, const std::string &rc, const std::string &op)
void * TCppObject_t
Definition cpp_cppyy.h:21
RPY_EXPORTED Long64_t CallLL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED bool IsPublicData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool HasComplexHierarchy(TCppType_t type)
RPY_EXPORTED TCppObject_t Construct(TCppType_t type)
RPY_EXPORTED std::string GetEnumDataName(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED int GetDimensionSize(TCppScope_t scope, TCppIndex_t idata, int dimension)
RPY_EXPORTED float CallF(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED intptr_t GetDatamemberOffset(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsTemplate(const std::string &template_name)
TCppScope_t TCppType_t
Definition cpp_cppyy.h:19
RPY_EXPORTED bool IsComplete(const std::string &type_name)
RPY_EXPORTED bool IsProtectedData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED long CallL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED void * CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetMethodMangledName(TCppMethod_t)
RPY_EXPORTED std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsEnumData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsMethodTemplate(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope)
RPY_EXPORTED size_t GetFunctionArgSizeof()
void * TCppEnum_t
Definition cpp_cppyy.h:20
RPY_EXPORTED bool IsConstructor(TCppMethod_t method)
RPY_EXPORTED TCppIndex_t GetDatamemberIndex(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool IsDestructor(TCppMethod_t method)
RPY_EXPORTED void CallDestructor(TCppType_t type, TCppObject_t self)
RPY_EXPORTED bool IsStaticData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED bool IsPublicMethod(TCppMethod_t method)
RPY_EXPORTED void CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED char * CallS(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, size_t *length)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED bool IsStaticMethod(TCppMethod_t method)
RPY_EXPORTED std::string GetMethodName(TCppMethod_t)
RPY_EXPORTED long long GetEnumDataValue(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED bool IsConstData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED TCppIndex_t GetNumBases(TCppType_t type)
RPY_EXPORTED bool IsTemplatedConstructor(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, TCppType_t result_type)
RPY_EXPORTED char CallC(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED double CallD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED bool IsConstMethod(TCppMethod_t)
size_t TCppScope_t
Definition cpp_cppyy.h:18
RPY_EXPORTED LongDouble_t CallLD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetMethodFullName(TCppMethod_t)
RPY_EXPORTED std::string ResolveEnum(const std::string &enum_type)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
RPY_EXPORTED TCppObject_t CallConstructor(TCppMethod_t method, TCppType_t type, size_t nargs, void *args)
RPY_EXPORTED size_t SizeOf(TCppType_t klass)
RPY_EXPORTED std::string GetBaseName(TCppType_t type, TCppIndex_t ibase)
RPY_EXPORTED TCppIndex_t GetMethodNumArgs(TCppMethod_t)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED bool IsNamespace(TCppScope_t scope)
RPY_EXPORTED void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
RPY_EXPORTED TCppIndex_t GetNumDatamembers(TCppScope_t scope)
RPY_EXPORTED bool IsSmartPtr(TCppType_t type)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED std::string GetDatamemberType(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED void Destruct(TCppType_t type, TCppObject_t instance)
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED bool HasVirtualDestructor(TCppType_t type)
RPY_EXPORTED bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
RPY_EXPORTED TCppScope_t gGlobalScope
Definition cpp_cppyy.h:51
void * TCppFuncAddr_t
Definition cpp_cppyy.h:25
RPY_EXPORTED std::string GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED void DeallocateFunctionArgs(void *args)
RPY_EXPORTED int CallI(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED TCppIndex_t GetNumMethods(TCppScope_t scope)
RPY_EXPORTED void Deallocate(TCppType_t type, TCppObject_t instance)
RPY_EXPORTED TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)
RPY_EXPORTED bool IsAbstract(TCppType_t type)
void(* DelFunc_t)(void *)
Definition Rtypes.h:110
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=0)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
#define RPY_EXTERN
union CPyCppyy::Parameter::Value fValue
const char * fSigName
auto * m
Definition textangle.C:8
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345