Commit ad341bee authored by ussrhero's avatar ussrhero
Browse files

fixed comparing typeInfo with None

parent a447202c
...@@ -1015,7 +1015,7 @@ void pykd_init() ...@@ -1015,7 +1015,7 @@ void pykd_init()
.def( "__dir__", TypeInfoAdapter::getElementDir ) .def( "__dir__", TypeInfoAdapter::getElementDir )
.def("__contains__", TypeInfoAdapter::hasFieldOrMethod) .def("__contains__", TypeInfoAdapter::hasFieldOrMethod)
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
.def("__bool__", TypeInfoAdapter::isZero ) .def("__bool__", TypeInfoAdapter::isNotZero )
#else #else
.def("__iszero__", TypeInfoAdapter::isZero ) .def("__iszero__", TypeInfoAdapter::isZero )
#endif #endif
......
...@@ -378,6 +378,10 @@ struct TypeInfoAdapter : public kdlib::TypeInfo { ...@@ -378,6 +378,10 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
return false; return false;
} }
static bool isNotZero(kdlib::TypeInfo &typeInfo) {
return true;
}
static bool hasFieldOrMethod(kdlib::TypeInfoPtr& typedVar, const std::wstring& name); static bool hasFieldOrMethod(kdlib::TypeInfoPtr& typedVar, const std::wstring& name);
}; };
......
...@@ -21,6 +21,14 @@ class TypedVarTest( unittest.TestCase ): ...@@ -21,6 +21,14 @@ class TypedVarTest( unittest.TestCase ):
tv = pykd.typedVar( "g_structTest" ) tv = pykd.typedVar( "g_structTest" )
tv = pykd.typedVar( target.moduleName + "!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): def testBaseTypes(self):
self.assertEqual( 10, target.module.typedVar( "ucharVar" ) ) self.assertEqual( 10, target.module.typedVar( "ucharVar" ) )
self.assertEqual( 1020, target.module.typedVar( "ushortVar" ) ) self.assertEqual( 1020, target.module.typedVar( "ushortVar" ) )
......
...@@ -242,16 +242,12 @@ class TypeInfoTest( unittest.TestCase ): ...@@ -242,16 +242,12 @@ class TypeInfoTest( unittest.TestCase ):
ti = pykd.typeInfo("UInt8B").arrayOf(10) ti = pykd.typeInfo("UInt8B").arrayOf(10)
self.assertTrue( "UInt8B[10]", ti.name() ) self.assertTrue( "UInt8B[10]", ti.name() )
def testCompareWihNone(self): def testCompareWithNone(self):
ti = pykd.typeInfo("UInt8B") ti = pykd.typeInfo("UInt8B")
if ti == None: self.assertFalse(ti == None)
pass self.assertTrue(ti != None)
if ti != None: self.assertFalse(not ti)
pass self.assertTrue(ti)
if not ti:
pass
if ti:
pass
def testFunction(self): def testFunction(self):
functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref() functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment