From 30795b3ef9886851b5ed248d47abe56cf50b8f6e Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 10 Feb 2012 08:03:36 +0000 Subject: [PATCH] [0.1.x] fixed : pykd routines can not convert parameters to long git-svn-id: https://pykd.svn.codeplex.com/svn@74113 9b283d60-5439-405e-af05-b73fd8c4d996 --- changelist.txt | 5 +++- pykd/dbgext.cpp | 6 +++-- pykd/intbase.h | 49 +++++++++++++++++++++++++++++++++++++--- test/scripts/typedvar.py | 9 +++++++- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/changelist.txt b/changelist.txt index 82acd7a..5f306be 100644 --- a/changelist.txt +++ b/changelist.txt @@ -1,9 +1,12 @@ + +[!] fixed : issue #10336 ( pykd routines can not convert parameters to long ) + version 0.1.0.7 30/01/2012 [+] added : cpuReg class [+] added : getLocals method for the class stackFrame [+] added : checksum method for the class module -[+] added : timestam method for the class module +[+] added : timestamp method for the class module version 0.1.0.6 20/01/2012 diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index eb97698..fe8c167 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -150,8 +150,10 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__long__", &intBase::long_ ) .def( "__int__", &intBase::int_ ) .def( "__index__", &intBase::long_ ) - .def( "__hash__", &intBase::long_ ) - .def( "__coerce__", &intBase::coerce ); + .def( "__hash__", &intBase::long_ ); + + python::implicitly_convertible(); + python::implicitly_convertible(); python::class_("dbgClient", "Class representing a debugging session", python::no_init ) .def( "addr64", &DebugClient::addr64, diff --git a/pykd/intbase.h b/pykd/intbase.h index 302880e..38e4824 100644 --- a/pykd/intbase.h +++ b/pykd/intbase.h @@ -53,6 +53,34 @@ public: } }; +class VariantToULong64 : public boost::static_visitor +{ +public: + template + ULONG64 operator()(T i ) const { + return static_cast( i ); + } +}; + + +class VariantToLong : public boost::static_visitor +{ +public: + template + LONG operator()(T i ) const { + return static_cast( i ); + } +}; + +class VariantToLong64 : public boost::static_visitor +{ +public: + template + LONG64 operator()(T i ) const { + return static_cast( i ); + } +}; + class intBase { @@ -185,11 +213,23 @@ public: return boost::apply_visitor( VariantToPyobj(), getValue() ) != 0; } - python::object coerce() { - __debugbreak(); - return python::object(); + operator ULONG64() { + return boost::apply_visitor( VariantToULong64(), getValue() ); } + operator ULONG() { + return boost::apply_visitor( VariantToULong(), getValue() ); + } + + operator LONG64() { + return boost::apply_visitor( VariantToLong64(), getValue() ); + } + + operator LONG() { + return boost::apply_visitor( VariantToLong(), getValue() ); + } + + private: virtual BaseTypeVariant getValue() { @@ -224,4 +264,7 @@ private: BaseTypeVariant m_variant; }; + + + }; \ No newline at end of file diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 442bbf8..e1b122d 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -169,7 +169,7 @@ class TypedVarTest( unittest.TestCase ): self.assertEqual( 4, tv.m_fieldNestedStruct ) self.assertEqual( 5, tv.m_fieldOfUnNamed ) - def testPointerToFunction( self ): + def testPointerToFunction(self): tv1 = target.module.typedVar( "g_unTypedPtrToFunction" ) # if debug: g_unTypedPtrToFunction point to jmp EnumWindowsProc2 (e9 xxxxxxxx) @@ -181,3 +181,10 @@ class TypedVarTest( unittest.TestCase ): self.assertRaises( pykd.TypeException, tv1.deref ) self.assertRaises( pykd.TypeException, tv2.deref ) + + + def testTypeVarArg(self): + tv1 = target.module.typedVar( "structTest", target.module.g_structTest ) + tv2 = target.module.typedVar( "structTest", tv1 ) + self.assertEqual( tv1, tv2 ) + self.assertTrue( tv1 )