Skip to content

Commit 3fbbfea

Browse files
committed
fix for gInterpreter and codegen for gInterpreter->Declare
1 parent 8fbd662 commit 3fbbfea

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@ Cppyy::TCppScope_t Cppyy::GetUnderlyingScope(TCppScope_t scope)
836836
Cppyy::TCppScope_t Cppyy::GetScope(const std::string& name,
837837
TCppScope_t parent_scope)
838838
{
839+
// CppInterOp directly looks at the AST which is not enough.
840+
// We require lazy module loading that ROOT relies on, so we do it here first.
841+
// Use TClass::GetClass to trigger auto-loading of dictionaries and
842+
// modules.
843+
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
844+
TClass::GetClass(name.c_str(), true /* load */, true /* silent */);
845+
839846
if (Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope))
840847
return scope;
841848
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
@@ -933,8 +940,16 @@ Cppyy::TCppScope_t Cppyy::GetActualClass(TCppScope_t klass, TCppObject_t obj) {
933940
std::string mangled_name = typ->name();
934941
std::string demangled_name = Cpp::Demangle(mangled_name);
935942

936-
if (TCppScope_t scope = Cppyy::GetScope(demangled_name))
937-
return scope;
943+
if (TCppScope_t scope = Cppyy::GetScope(demangled_name)) {
944+
// Only return the derived type if it has a complete definition in the
945+
// interpreter. Internal classes like TCling have no public header and
946+
// no dictionary, so their CXXRecordDecl has no DefinitionData.
947+
// returning them crashes when querying bases/offsets. Fall back
948+
// to the declared base type instead (equivalent to a
949+
// clActual->GetClassInfo() guard).
950+
if (Cpp::IsComplete(scope))
951+
return scope;
952+
}
938953

939954
return klass;
940955
}
@@ -1474,9 +1489,13 @@ bool Cppyy::GetSmartPtrInfo(
14741489
// type offsets --------------------------------------------------------------
14751490
ptrdiff_t Cppyy::GetBaseOffset(TCppScope_t derived, TCppScope_t base,
14761491
TCppObject_t address, int direction, bool rerror)
1477-
{
1492+
{
1493+
// Either base or derived class is incomplete, treat silently
1494+
if (!Cpp::IsComplete(derived) || !Cpp::IsComplete(base))
1495+
return rerror ? (ptrdiff_t)-1 : 0;
1496+
14781497
intptr_t offset = Cpp::GetBaseClassOffset(derived, base);
1479-
1498+
14801499
if (offset == -1) // Cling error, treat silently
14811500
return rerror ? (ptrdiff_t)offset : 0;
14821501

bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ def _set_pch():
9090
_e = gbl.std.exception
9191

9292

93-
#- enable auto-loading -------------------------------------------------------
94-
try: gbl.cling.runtime.gCling.EnableAutoLoading()
95-
except: pass
96-
97-
9893
#- external typemap ----------------------------------------------------------
9994
from . import _typemap
10095
_typemap.initialize(_backend) # also creates (u)int8_t mapper

bindings/pyroot/pythonizations/python/ROOT/_facade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _finalSetup(self):
190190
self.__dict__["gROOT"] = self._cppyy.gbl.ROOT.GetROOT()
191191

192192
# Make sure the interpreter is initialized once gROOT has been initialized
193-
self._cppyy.gbl.TInterpreter.Instance()
193+
self.__dict__["gInterpreter"] = self._cppyy.gbl.TInterpreter.Instance()
194194

195195
# Setup interactive usage from Python
196196
self.__dict__["app"] = PyROOTApplication(self.PyConfig, self._is_ipython)

interpreter/CppInterOp/lib/CppInterOp/CppInterOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ void make_narg_call(const FunctionDecl* FD, const std::string& return_type,
22832283
else
22842284
callbuf << "((" << class_name << "*)obj)->";
22852285

2286-
if (op_flag)
2286+
if (op_flag && !MD->isVirtual())
22872287
callbuf << class_name << "::";
22882288
} else if (isa<NamedDecl>(get_non_transparent_decl_context(FD))) {
22892289
// This is a namespace member.

0 commit comments

Comments
 (0)