Commit ad341bee authored by ussrhero's avatar ussrhero
Browse files

fixed comparing typeInfo with None

parent a447202c
......@@ -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
......
......@@ -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);
};
......
......@@ -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" ) )
......
......@@ -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()
......
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