teemperor created this revision.
teemperor added a reviewer: dblaikie.

After https://reviews.llvm.org/D49309 it became clear that we always need a 
null-terminated string (for
the Python API), so we might as well change the API to accept an std::string&
instead of taking a StringRef and then always allocating a new std::string.


https://reviews.llvm.org/D49411

Files:
  include/lldb/Interpreter/ScriptInterpreter.h
  source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
  source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h

Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===================================================================
--- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -151,13 +151,13 @@
   bool Interrupt() override;
 
   bool ExecuteOneLine(
-      llvm::StringRef command, CommandReturnObject *result,
+      const std::string &command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
   void ExecuteInterpreterLoop() override;
 
   bool ExecuteOneLineWithReturn(
-      llvm::StringRef in_string,
+      const std::string &in_string,
       ScriptInterpreter::ScriptReturnType return_type, void *ret_value,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -751,9 +751,8 @@
 }
 
 bool ScriptInterpreterPython::ExecuteOneLine(
-    llvm::StringRef command, CommandReturnObject *result,
+    const std::string &command, CommandReturnObject *result,
     const ExecuteScriptOptions &options) {
-  std::string command_str = command.str();
 
   if (!m_valid_session)
     return false;
@@ -857,7 +856,7 @@
           if (PyCallable_Check(m_run_one_line_function.get())) {
             PythonObject pargs(
                 PyRefType::Owned,
-                Py_BuildValue("(Os)", session_dict.get(), command_str.c_str()));
+                Py_BuildValue("(Os)", session_dict.get(), command.c_str()));
             if (pargs.IsValid()) {
               PythonObject return_value(
                   PyRefType::Owned,
@@ -898,7 +897,7 @@
     // The one-liner failed.  Append the error message.
     if (result) {
       result->AppendErrorWithFormat(
-          "python failed attempting to evaluate '%s'\n", command_str.c_str());
+          "python failed attempting to evaluate '%s'\n", command.c_str());
     }
     return false;
   }
@@ -1024,8 +1023,9 @@
   return false;
 }
 bool ScriptInterpreterPython::ExecuteOneLineWithReturn(
-    llvm::StringRef in_string, ScriptInterpreter::ScriptReturnType return_type,
-    void *ret_value, const ExecuteScriptOptions &options) {
+    const std::string &in_string,
+    ScriptInterpreter::ScriptReturnType return_type, void *ret_value,
+    const ExecuteScriptOptions &options) {
 
   Locker locker(this, ScriptInterpreterPython::Locker::AcquireLock |
                           ScriptInterpreterPython::Locker::InitSession |
@@ -1059,19 +1059,18 @@
   if (py_error.IsValid())
     PyErr_Clear();
 
-  std::string as_string = in_string.str();
   { // scope for PythonInputReaderManager
     // PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
     py_return.Reset(PyRefType::Owned,
-                    PyRun_String(as_string.c_str(), Py_eval_input,
+                    PyRun_String(in_string.c_str(), Py_eval_input,
                                  globals.get(), locals.get()));
     if (!py_return.IsValid()) {
       py_error.Reset(PyRefType::Borrowed, PyErr_Occurred());
       if (py_error.IsValid())
         PyErr_Clear();
 
       py_return.Reset(PyRefType::Owned,
-                      PyRun_String(as_string.c_str(), Py_single_input,
+                      PyRun_String(in_string.c_str(), Py_single_input,
                                    globals.get(), locals.get()));
     }
   }
@@ -2892,7 +2891,7 @@
                               // ExecuteOneLineWithReturn returns successfully
 
   if (ExecuteOneLineWithReturn(
-          command.c_str(), ScriptInterpreter::eScriptReturnTypeCharStrOrNone,
+          command, ScriptInterpreter::eScriptReturnTypeCharStrOrNone,
           &result_ptr,
           ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false))) {
     if (result_ptr)
Index: source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
===================================================================
--- source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
+++ source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
@@ -25,7 +25,7 @@
   ~ScriptInterpreterNone() override;
 
   bool ExecuteOneLine(
-      llvm::StringRef command, CommandReturnObject *result,
+      const std::string &command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
   void ExecuteInterpreterLoop() override;
Index: source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
===================================================================
--- source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
+++ source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
@@ -27,7 +27,7 @@
 
 ScriptInterpreterNone::~ScriptInterpreterNone() {}
 
-bool ScriptInterpreterNone::ExecuteOneLine(llvm::StringRef command,
+bool ScriptInterpreterNone::ExecuteOneLine(const std::string &command,
                                            CommandReturnObject *,
                                            const ExecuteScriptOptions &) {
   m_interpreter.GetDebugger().GetErrorFile()->PutCString(
Index: include/lldb/Interpreter/ScriptInterpreter.h
===================================================================
--- include/lldb/Interpreter/ScriptInterpreter.h
+++ include/lldb/Interpreter/ScriptInterpreter.h
@@ -96,13 +96,14 @@
   virtual bool Interrupt() { return false; }
 
   virtual bool ExecuteOneLine(
-      llvm::StringRef command, CommandReturnObject *result,
+      const std::string &command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
 
   virtual void ExecuteInterpreterLoop() = 0;
 
   virtual bool ExecuteOneLineWithReturn(
-      llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
+      const std::string &in_string, ScriptReturnType return_type,
+      void *ret_value,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
     return true;
   }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to