[pykd] fixed: issue 8499 ( !py command crashs with wrong script's path )

git-svn-id: https://pykd.svn.codeplex.com/svn@63927 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-04-13 07:28:56 +00:00
parent 494b59b9ef
commit 30d291750a
2 changed files with 21 additions and 25 deletions

View File

@ -566,22 +566,14 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
std::string filePath; std::string filePath;
DbgPythonPath dbgPythonPath; DbgPythonPath dbgPythonPath;
if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) ) if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) )
{ {
DWORD oldCurDirLen = GetCurrentDirectoryA( 0, NULL ); try {
std::vector<char> oldCurDirCstr(oldCurDirLen);
GetCurrentDirectoryA( oldCurDirLen, &oldCurDirCstr[0] );
// SetCurrentDirectoryA( filePath.c_str() );
try {
boost::python::object result; boost::python::object result;
result = boost::python::exec_file( fullFileName.c_str(), global, global ); result = boost::python::exec_file( fullFileName.c_str(), global, global );
} }
catch( boost::python::error_already_set const & ) catch( boost::python::error_already_set const & )
{ {
@ -603,13 +595,11 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
Py_XDECREF(errtype); Py_XDECREF(errtype);
Py_XDECREF(traceback); Py_XDECREF(traceback);
} }
SetCurrentDirectoryA( &oldCurDirCstr[0] );
} }
else else
{ {
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" ); dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" );
} }
} }
catch(...) catch(...)

View File

@ -86,6 +86,7 @@ DbgPythonPath::findPath(
if ( bufSize > 0 ) if ( bufSize > 0 )
{ {
bufSize += 1;
std::vector<char> fullFileNameCStr(bufSize); std::vector<char> fullFileNameCStr(bufSize);
char *partFileNameCStr = NULL; char *partFileNameCStr = NULL;
@ -95,12 +96,14 @@ DbgPythonPath::findPath(
pyExt ? NULL : ".py", pyExt ? NULL : ".py",
bufSize, bufSize,
&fullFileNameCStr[0], &fullFileNameCStr[0],
&partFileNameCStr ); &partFileNameCStr );
fullFileName = std::string( &fullFileNameCStr[0] ); fullFileName = std::string( &fullFileNameCStr[0] );
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); if ( !fullFileName.empty() )
{
return true; filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
return true;
}
} }
// 2. Èùåì âî âñåõ äèğåêòîğèÿõ, óêàçàííûõ â m_pathList // 2. Èùåì âî âñåõ äèğåêòîğèÿõ, óêàçàííûõ â m_pathList
@ -120,21 +123,24 @@ DbgPythonPath::findPath(
if ( bufSize > 0 ) if ( bufSize > 0 )
{ {
bufSize += 1;
std::vector<char> fullFileNameCStr(bufSize); std::vector<char> fullFileNameCStr(bufSize);
char *partFileNameCStr = NULL; char *partFileNameCStr = NULL;
SearchPathA( bufSize = SearchPathA(
(*it).c_str(), (*it).c_str(),
fileName.c_str(), fileName.c_str(),
pyExt ? NULL : ".py", pyExt ? NULL : ".py",
bufSize, bufSize,
&fullFileNameCStr[0], &fullFileNameCStr[0],
&partFileNameCStr ); &partFileNameCStr );
fullFileName = std::string( &fullFileNameCStr[0] ); fullFileName = std::string( &fullFileNameCStr[0] );
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); if ( !fullFileName.empty() )
{
return true; filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
return true;
}
} }
} }