[pykd_ext_2.0] fixed : pykd is not initialized exception

git-svn-id: https://pykd.svn.codeplex.com/svn@90999 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2016-07-01 11:22:59 +00:00 committed by Mikhail I. Izmestev
parent d1b185601a
commit 332c5efc14
3 changed files with 35 additions and 21 deletions

View File

@ -515,30 +515,39 @@ void PyModule::deactivate()
void PyModule::checkPykd()
{
if (m_pykdInit)
return;
PyObject* pykdMod = PyImport_ImportModule("pykd");
PyObject *mainName = 0, *mainMod = 0, *globals = 0, *result = 0;
if (!pykdMod)
{
PyObject* mainName = isPy3 ? PyUnicode_FromString("__main__") : PyString_FromString("__main__");
PyObject* mainMod = PyImport_Import(mainName);
PyObject* globals = PyObject_GetAttrString(mainMod, "__dict__");
PyObject* result = PyRun_String("__import__('pykd').initialize()\n", Py_file_input, globals, globals);
if (mainName) Py_DecRef(mainName);
if (mainMod) Py_DecRef(mainMod);
if (globals) Py_DecRef(globals);
if (result) Py_DecRef(result);
}
do {
if (m_pykdInit)
break;
if (pykdMod) Py_DecRef(pykdMod);
mainName = isPy3 ? PyUnicode_FromString("__main__") : PyString_FromString("__main__");
if (!mainName)
break;
m_pykdInit = true;
mainMod = PyImport_Import(mainName);
if (!mainMod)
break;
globals = PyObject_GetAttrString(mainMod, "__dict__");
if (!globals)
break;
result = PyRun_String("__import__('pykd').initialize()\n", Py_file_input, globals, globals);
if (!result)
break;
m_pykdInit = true;
} while( false);
if (mainName) Py_DecRef(mainName);
if (mainMod) Py_DecRef(mainMod);
if (globals) Py_DecRef(globals);
if (result) Py_DecRef(result);
}
PythonInterpreter* activateInterpreter(bool global, int majorVersion, int minorVersion)
{
return PythonSingleton::get()->getInterpreter(majorVersion, minorVersion, global);

View File

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

View File

@ -11,6 +11,7 @@
#include "pyinterpret.h"
#include "pyapi.h"
#include "pyclass.h"
#include "version.h"
//////////////////////////////////////////////////////////////////////////////
@ -132,15 +133,19 @@ info(
PCSTR args
)
{
std::list<InterpreterDesc> interpreterList = getInstalledInterpreter();
std::stringstream sstr;
sstr <<std::endl << "pykd bootstrapper version: " << PYKDEXT_VERSION_MAJOR << '.' << PYKDEXT_VERSION_MINOR << '.'
<< PYKDEXT_VERSION_SUBVERSION << '.' << PYKDEXT_VERSION_BUILDNO << std::endl;
std::list<InterpreterDesc> interpreterList = getInstalledInterpreter();
int defaultMajor;
int defaultMinor;
getDefaultPythonVersion(defaultMajor, defaultMinor);
sstr << std::endl << "Installed python" << std::endl << std::endl;
sstr << std::endl << "Installed python:" << std::endl << std::endl;
sstr << std::setw(16) << std::left << "Version:" << std::setw(12) << std::left << "Status: " << std::left << "Image:" << std::endl;
sstr << "------------------------------------------------------------------------------" << std::endl;
if (interpreterList.size() > 0)