================
@@ -32,6 +32,84 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
   ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter);
   ~ScriptedPythonInterface() override = default;
 
+  template <typename... Args>
+  llvm::Expected<StructuredData::GenericSP>
+  CreatePluginObject(llvm::StringRef class_name,
+                     StructuredData::Generic *script_obj, Args... args) {
+    using namespace python;
+    using Locker = ScriptInterpreterPythonImpl::Locker;
+
+    std::string error_string;
+    if (class_name.empty() &&
+        llvm::StringRef(m_interpreter.GetDictionaryName()).empty() &&
+        !script_obj)
+      return llvm::createStringError(
+          llvm::inconvertibleErrorCode(),
+          "ScriptedPythonInterface::CreatePluginObject - missing script class "
+          "name, dictionary or object.");
+
+    Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+                   Locker::FreeLock);
+
+    PythonObject result = {};
+
+    if (!script_obj) {
+      auto dict =
+          PythonModule::MainModule().ResolveName<python::PythonDictionary>(
+              m_interpreter.GetDictionaryName());
+      auto pfunc =
+          PythonObject::ResolveNameWithDictionary<python::PythonCallable>(
+              class_name, dict);
+
+      if (!pfunc.IsAllocated()) {
+        error_string.append("Could not find script class: ");
+        error_string.append(class_name);
+        return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                       error_string);
----------------
JDevlieghere wrote:

Could you just pass those as twines to `createStringError`? 

https://github.com/llvm/llvm-project/pull/68052
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to