[Lldb-commits] [lldb] r184158 - <rdar://problem/13926101>
Enrico Granata
egranata at apple.com
Mon Jun 17 17:58:07 PDT 2013
Author: enrico
Date: Mon Jun 17 19:58:06 2013
New Revision: 184158
URL: http://llvm.org/viewvc/llvm-project?rev=184158&view=rev
Log:
<rdar://problem/13926101>
Allow “command script import” to work with folder names that have a ‘ (tick) in them
Kudos to StackOverflow (question 1494399) for the replace_all code!
Modified:
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=184158&r1=184157&r2=184158&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Mon Jun 17 19:58:06 2013
@@ -2577,6 +2577,19 @@ ReadPythonBacktrace (PyObject* py_backtr
return retval;
}
+uint64_t replace_all(std::string& str, const std::string& oldStr, const std::string& newStr)
+{
+ size_t pos = 0;
+ uint64_t matches = 0;
+ while((pos = str.find(oldStr, pos)) != std::string::npos)
+ {
+ matches++;
+ str.replace(pos, oldStr.length(), newStr);
+ pos += newStr.length();
+ }
+ return matches;
+}
+
bool
ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
bool can_reload,
@@ -2624,13 +2637,14 @@ ScriptInterpreterPython::LoadScriptingMo
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
{
- const char* directory = target_file.GetDirectory().GetCString();
+ std::string directory(target_file.GetDirectory().GetCString());
+ replace_all(directory,"'","\\'");
// now make sure that Python has "directory" in the search path
StreamString command_stream;
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
- directory,
- directory);
+ directory.c_str(),
+ directory.c_str());
bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
if (!syspath_retval)
{
More information about the lldb-commits
mailing list