From ad341bee9f64bc7d06c66afd3c797181d6304130 Mon Sep 17 00:00:00 2001 From: ussrhero Date: Sun, 29 Dec 2019 12:48:52 +0300 Subject: [PATCH] fixed comparing typeInfo with None --- pykd/pymod.cpp | 2 +- pykd/pytypeinfo.h | 4 ++++ test/scripts/typedvar.py | 8 ++++++++ test/scripts/typeinfo.py | 14 +++++--------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 7faf8a4..b8a09bc 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -1015,7 +1015,7 @@ void pykd_init() .def( "__dir__", TypeInfoAdapter::getElementDir ) .def("__contains__", TypeInfoAdapter::hasFieldOrMethod) #if PY_VERSION_HEX >= 0x03000000 - .def("__bool__", TypeInfoAdapter::isZero ) + .def("__bool__", TypeInfoAdapter::isNotZero ) #else .def("__iszero__", TypeInfoAdapter::isZero ) #endif diff --git a/pykd/pytypeinfo.h b/pykd/pytypeinfo.h index 24cb707..c93292a 100644 --- a/pykd/pytypeinfo.h +++ b/pykd/pytypeinfo.h @@ -378,6 +378,10 @@ struct TypeInfoAdapter : public kdlib::TypeInfo { return false; } + static bool isNotZero(kdlib::TypeInfo &typeInfo) { + return true; + } + static bool hasFieldOrMethod(kdlib::TypeInfoPtr& typedVar, const std::wstring& name); }; diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 0624e4f..0777c7c 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -21,6 +21,14 @@ class TypedVarTest( unittest.TestCase ): tv = pykd.typedVar( "g_structTest" ) tv = pykd.typedVar( target.moduleName + "!g_structTest" ) + + def testCompareWithNone(self): + tv = target.module.typedVar( "ucharVar" ) + self.assertFalse(tv == None) + self.assertTrue(tv != None) + self.assertFalse(not tv) + self.assertTrue(tv) + def testBaseTypes(self): self.assertEqual( 10, target.module.typedVar( "ucharVar" ) ) self.assertEqual( 1020, target.module.typedVar( "ushortVar" ) ) diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 9f661f2..8e4b51b 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -242,16 +242,12 @@ class TypeInfoTest( unittest.TestCase ): ti = pykd.typeInfo("UInt8B").arrayOf(10) self.assertTrue( "UInt8B[10]", ti.name() ) - def testCompareWihNone(self): + def testCompareWithNone(self): ti = pykd.typeInfo("UInt8B") - if ti == None: - pass - if ti != None: - pass - if not ti: - pass - if ti: - pass + self.assertFalse(ti == None) + self.assertTrue(ti != None) + self.assertFalse(not ti) + self.assertTrue(ti) def testFunction(self): functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref()