Skip to content

Commit f9f3609

Browse files
committedApr 7, 2016
Fix TestImport for Windows by ensuring backslashes in the directory paths are properly escaped in Python.
The Python import works by ensuring the directory of the module or package is in sys.path, and then it does a Python `import foo`. The original code was not escaping the backslashes in the directory path, so this wasn't working. Differential Revision: http://reviews.llvm.org/D18873 llvm-svn: 265738
1 parent 3a41be2 commit f9f3609

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
 

‎lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
25482548

25492549
StreamString command_stream;
25502550

2551-
// Before executing Pyton code, lock the GIL.
2551+
// Before executing Python code, lock the GIL.
25522552
Locker py_lock (this,
25532553
Locker::AcquireLock | (init_session ? Locker::InitSession : 0) | Locker::NoSTDIN,
25542554
Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0));
@@ -2569,9 +2569,10 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
25692569
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
25702570
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
25712571
{
2572-
std::string directory(target_file.GetDirectory().GetCString());
2573-
replace_all(directory,"'","\\'");
2574-
2572+
std::string directory = target_file.GetDirectory().GetCString();
2573+
replace_all(directory, "\\", "\\\\");
2574+
replace_all(directory, "'", "\\'");
2575+
25752576
// now make sure that Python has "directory" in the search path
25762577
StreamString command_stream;
25772578
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
@@ -2583,7 +2584,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
25832584
error.SetErrorString("Python sys.path handling failed");
25842585
return false;
25852586
}
2586-
2587+
25872588
// strip .py or .pyc extension
25882589
ConstString extension = target_file.GetFileNameExtension();
25892590
if (extension)
@@ -2634,8 +2635,8 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
26342635
command_stream.Printf("reload_module(%s)",basename.c_str());
26352636
}
26362637
else
2637-
command_stream.Printf("import %s",basename.c_str());
2638-
2638+
command_stream.Printf("import %s", basename.c_str());
2639+
26392640
error = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
26402641
if (error.Fail())
26412642
return false;

0 commit comments

Comments
 (0)