[0.3.x] fixed : exec_file raise std exception

git-svn-id: https://pykd.svn.codeplex.com/svn@90543 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2015-04-30 12:14:34 +00:00 committed by Mikhail I. Izmestev
parent ab0d8e2031
commit 29e42ed852
4 changed files with 50 additions and 30 deletions

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include <comutil.h>
#include <boost/python.hpp>
namespace python = boost::python;
@ -181,10 +182,16 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py)
PykdInterruptWatch interruptWatch;
python::exec_file( scriptFileName.c_str(), global );
}
catch( python::error_already_set const & )
catch( const python::error_already_set& )
{
pykd::printException();
}
catch (const std::exception& invalidArg)
{
_bstr_t bstrInavalidArg(invalidArg.what());
kdlib::eprintln(std::wstring(bstrInavalidArg));
}
}
if ( !global )

View File

@ -3,7 +3,7 @@
#define PYKDEXT_VERSION_MAJOR 1
#define PYKDEXT_VERSION_MINOR 0
#define PYKDEXT_VERSION_SUBVERSION 1
#define PYKDEXT_VERSION_BUILDNO 6
#define PYKDEXT_VERSION_BUILDNO 7
#define __VER_STR2__(x) #x
#define __VER_STR1__(x) __VER_STR2__(x)

View File

@ -1,5 +1,7 @@
#include "stdafx.h"
#include <comutil.h>
#include <boost/python.hpp>
namespace python = boost::python;
@ -235,31 +237,12 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdBootsTrapper, py)
PyThreadState *localState = NULL;
PyThreadState *globalState = NULL;
PythonSingleton::get()->beginPythonCode();
try {
InterruptWatch interruptWatch;
PythonSingleton::get()->beginPythonCode();
std::string scriptFileName;
if (args.size() > 0)
{
scriptFileName = getScriptFileName(args[0]);
if (scriptFileName.empty())
{
kdlib::eprintln(L"script file not found");
python::throw_error_already_set();
}
global = !(global || local) ? false : global; //set local by default
}
else
{
global = !(global || local) ? true : global; //set global by default
}
if (!global)
{
globalState = PyThreadState_Swap(NULL);
@ -275,6 +258,21 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdBootsTrapper, py)
sys.attr("stdin") = python::object(::DbgIn());
}
std::string scriptFileName;
if (args.size() > 0)
{
scriptFileName = getScriptFileName(args[0]);
if (scriptFileName.empty())
throw std::invalid_argument("script not found");
global = !(global || local) ? false : global; //set local by default
}
else
{
global = !(global || local) ? true : global; //set global by default
}
// ïîëó÷àåì äîñòóï ê ãëîáàëüíîìó ìàïó ( íóæåí äëÿ âûçîâà exec_file )
python::object main = python::import("__main__");
python::object globalScope(main.attr("__dict__"));
@ -316,12 +314,17 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdBootsTrapper, py)
python::exec_file(scriptFileName.c_str(), globalScope);
}
}
catch (python::error_already_set const &)
catch (const python::error_already_set&)
{
printException();
}
catch (const std::exception& invalidArg)
{
_bstr_t bstrInavalidArg(invalidArg.what());
kdlib::eprintln(std::wstring(bstrInavalidArg));
}
if (!global)
if (!global && localState)
{
PyInterpreterState *interpreter = localState->interp;
@ -370,6 +373,11 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdBootsTrapper, install)
{
printException();
}
catch (const std::exception& invalidArg)
{
_bstr_t bstrInavalidArg(invalidArg.what());
kdlib::eprintln(std::wstring(bstrInavalidArg));
}
PythonSingleton::get()->endPythonCode();
}
@ -394,6 +402,11 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdBootsTrapper, upgrade)
{
printException();
}
catch (const std::exception& invalidArg)
{
_bstr_t bstrInavalidArg(invalidArg.what());
kdlib::eprintln(std::wstring(bstrInavalidArg));
}
PythonSingleton::get()->endPythonCode();
}
@ -504,10 +517,10 @@ std::string PykdBootsTrapper::findScript(const std::string &fullFileName)
&fullFileNameCStr[0],
&partFileNameCStr);
if (bufSize > 0)
{
DWORD fileAttr = GetFileAttributesA(&fullFileNameCStr[0]);
if ( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) == 0 )
return std::string(&fullFileNameCStr[0]);
}
}
}

View File

@ -15,8 +15,8 @@ cfg.PromptManager.in_template = 'In <\\#>: '
cfg.PromptManager.in2_template = ' .\\D.: '
cfg.PromptManager.out_template = 'Out<\\#>: '
cfg.InteractiveShellApp.extensions = [ 'pykdmagic' ]
#cfg.InteractiveShellApp.extensions = [ 'pykdmagic' ]
ipshell = InteractiveShellEmbed(config=cfg)
ipshell()
ipshell()