[0.3.x] fixed : exception registration for python 3

git-svn-id: https://pykd.svn.codeplex.com/svn@90966 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2016-03-22 07:37:13 +00:00 committed by Mikhail I. Izmestev
parent 0df2fba54f
commit d6190121d3

View File

@ -27,30 +27,30 @@ class exception {
public: public:
exception( const std::string& className, const std::string& classDesc ) exception(const std::string& className, const std::string& classDesc)
{ {
python::handle<> basedtype; std::string fullName = "pykd." + className;
if ( boost::is_same<TBaseExcept, python::detail::not_specified>::value ) if (boost::is_same<TBaseExcept, python::detail::not_specified>::value)
{ {
basedtype = python::handle<>(PyExc_Exception); exceptPyType<TExcept>::pyExceptType =
python::handle<>(PyErr_NewExceptionWithDoc(
const_cast<char*>(fullName.c_str()),
const_cast<char*>(classDesc.c_str()),
NULL,
NULL));
} }
else else
{ {
basedtype = exceptPyType<TBaseExcept>::pyExceptType; exceptPyType<TExcept>::pyExceptType =
python::handle<>(PyErr_NewExceptionWithDoc(
const_cast<char*>(fullName.c_str()),
const_cast<char*>(classDesc.c_str()),
exceptPyType<TBaseExcept>::pyExceptType.get(),
NULL));
} }
python::dict ob_dict; python::scope().attr(className.c_str()) = exceptPyType<TExcept>::pyExceptType;
ob_dict["__doc__"] = classDesc;
python::tuple ob_bases = python::make_tuple( basedtype );
python::object ob = python::object( python::handle<>(Py_TYPE(basedtype.get()) ) )( className, ob_bases, ob_dict );
python::scope().attr( className.c_str() ) = ob;
exceptPyType<TExcept>::pyExceptType = python::handle<>( ob.ptr() );
} }
}; };