From 332c5efc1436536836c8d1f502fcd765fd93ac19 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 1 Jul 2016 11:22:59 +0000 Subject: [PATCH] [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 --- pykd_ext/pyinterpret.cpp | 45 ++++++++++++++++++++++++---------------- pykd_ext/version.h | 2 +- pykd_ext/windbgext.cpp | 9 ++++++-- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/pykd_ext/pyinterpret.cpp b/pykd_ext/pyinterpret.cpp index 6380343..2285668 100644 --- a/pykd_ext/pyinterpret.cpp +++ b/pykd_ext/pyinterpret.cpp @@ -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); diff --git a/pykd_ext/version.h b/pykd_ext/version.h index e455f7a..b09df73 100644 --- a/pykd_ext/version.h +++ b/pykd_ext/version.h @@ -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) diff --git a/pykd_ext/windbgext.cpp b/pykd_ext/windbgext.cpp index b8f4f9d..31dcba7 100644 --- a/pykd_ext/windbgext.cpp +++ b/pykd_ext/windbgext.cpp @@ -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 interpreterList = getInstalledInterpreter(); std::stringstream sstr; + sstr < 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)