diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 01f9a89..4ece5a0 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -128,7 +128,9 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__invert__", &intBase::invert ) .def( "__nonzero__", &intBase::nonzero ) .def( "__str__", &intBase::str ) - .def( "__hex__", &intBase::hex ); + .def( "__hex__", &intBase::hex ) + .def( "__long__", &intBase::long_ ) + .def( "__int__", &intBase::int_ ); 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 6638036..6a07c7c 100644 --- a/pykd/intbase.h +++ b/pykd/intbase.h @@ -37,6 +37,15 @@ public: } }; +class VariantToPylong : public boost::static_visitor +{ +public: + template + python::object operator()(T i ) const { + return python::long_( i ); + } +}; + class intBase { @@ -60,6 +69,16 @@ public: return boost::apply_visitor( VariantToHex(), getValue() ); } + python::object + long_() { + return boost::apply_visitor( VariantToPylong(), getValue() ); + } + + python::object + int_() { + return boost::apply_visitor( VariantToPylong(), getValue() ); + } + python::object eq( python::object& obj ) { return boost::apply_visitor( VariantToPyobj(), getValue() ) == obj; } diff --git a/test/scripts/intbase.py b/test/scripts/intbase.py index 0a7f807..da8a9b2 100644 --- a/test/scripts/intbase.py +++ b/test/scripts/intbase.py @@ -142,5 +142,12 @@ class IntBaseTest( unittest.TestCase ): self.assertEqual( -0xFFFFFFFF, -intBase(0xFFFFFFFF) ) self.assertEqual( 0xFFFFFFFF, +intBase(0xFFFFFFFF) ) self.assertEqual( 0, ~intBase(0xFFFFFFFF) ) + + def testLongConvert( self ): + self.assertEqual( "100", "%d" % intBase(100) ) + self.assertEqual( "FFFF", "%X" % intBase(0xFFFF) ) + self.assertEqual( "-70000000000", "%d" % intBase(-70000000000) ) + self.assertEqual( "FFFFFFFFFFFFFF", "%X" % intBase(0xFFFFFFFFFFFFFF) ) + self.assertEqual( "0", "%d" % intBase(False) ) \ No newline at end of file diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 884c424..61793ed 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -54,8 +54,9 @@ if __name__ == "__main__": target.module.reload(); suite = getTestSuite() + #suite = getTestSuite( "intbase.IntBaseTest.testLongConvert" ) #suite = getTestSuite( "typedvar.TypedVarTest.testStruct" ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite ) - a = raw_input("\npress return\n") \ No newline at end of file + #a = raw_input("\npress return\n") \ No newline at end of file