From 2d038e75f680fb8e889ac1db859689ec2860d33b Mon Sep 17 00:00:00 2001 From: Aaron Jomy Date: Mon, 4 Nov 2024 13:42:45 +0100 Subject: [PATCH] [TCling] Invoke InterOp interpreter API in metacling This uses provides InterOp with the TInterpreter instance created by ROOT in TCling. The InterOp API can now be used without providing interpreter ownership. --- core/metacling/src/CMakeLists.txt | 1 - core/metacling/src/TCling.cxx | 8 ++++++++ core/metacling/src/TClingCallFunc.cxx | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/metacling/src/CMakeLists.txt b/core/metacling/src/CMakeLists.txt index 9c5b2616f577a..1104d8346c509 100644 --- a/core/metacling/src/CMakeLists.txt +++ b/core/metacling/src/CMakeLists.txt @@ -76,7 +76,6 @@ if(MSVC) endif() add_dependencies(MetaCling CLING clangCppInterOp) -# target_include_directories(MetaCling SYSTEM PUBLIC ${source_dir}/include/) ##### libCling ############################################################# diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index e831914ad0426..b7a90d4f26174 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -115,6 +115,8 @@ clang/LLVM technology. #include "cling/Utils/SourceNormalization.h" #include "cling/Interpreter/Exception.h" +#include "clang/Interpreter/CppInterOp.h" + #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" @@ -1609,6 +1611,12 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo // Initialize the dyld for AutoloadLibraryGenerator. DLM.initializeDyld(ShouldPermanentlyIgnore); } + + // Tell CppInterOp that the cling::Interpreter instance is managed externally by ROOT + // We pass the handle so it sets the ownership flags and sets the interpreter as soon as TCling is initialized + if (!Cpp::GetInterpreter()) { + Cpp::UseExternalInterpreter((Cpp::TInterp_t*)fInterpreter.get()); + } } diff --git a/core/metacling/src/TClingCallFunc.cxx b/core/metacling/src/TClingCallFunc.cxx index 7387068e938ee..5772966c1c9f5 100644 --- a/core/metacling/src/TClingCallFunc.cxx +++ b/core/metacling/src/TClingCallFunc.cxx @@ -67,6 +67,8 @@ C++ interpreter and the Clang C++ compiler, not CINT. #include "clang/Sema/SemaInternal.h" +#include "clang/Interpreter/CppInterOp.h" + #include #include #include