From 5cb3fc858bc045e0dac23c80822c2f0fdfce9f2a Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 21 Oct 2013 13:59:58 +0000 Subject: [PATCH] [0.2.x] fixed : issue #12335 ( TypeError: object has no len() for array ) git-svn-id: https://pykd.svn.codeplex.com/svn@85918 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/typeinfo.h | 22 ++++++++++++++++++++-- test/scripts/typeinfo.py | 13 +++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index e8c594c..d0aa827 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -203,7 +203,7 @@ public: throw PyException( PyExc_TypeError, "object has no len()" ); } - virtual python::tuple getElementByIndex( ULONG index ) { + virtual python::object getElementByIndex( ULONG index ) { throw PyException( PyExc_TypeError, "object is unsubscriptable"); } @@ -400,7 +400,7 @@ protected: return getFieldCount(); } - virtual python::tuple getElementByIndex( ULONG index ) { + virtual python::object getElementByIndex( ULONG index ) { return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); } @@ -542,6 +542,14 @@ protected: return getSize(); } + virtual ULONG getElementCount() { + return getFieldCount(); + } + + virtual python::object getElementByIndex( ULONG index ) { + return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); + } + SymbolPtr m_dia; }; @@ -630,6 +638,16 @@ public: return m_count; } + virtual ULONG getElementCount() { + return getCount(); + } + + virtual python::object getElementByIndex( ULONG index ) { + if( index < m_count ) + return python::object( m_derefType ); + throw PyException( PyExc_IndexError, "index out of range" ); + } + virtual TypeInfoPtr getElementType() { return m_derefType; } diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index a03fabb..de75fde 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -213,6 +213,19 @@ class TypeInfoTest( unittest.TestCase ): self.assertEqual( 5, len(ti) ) for field in ti: str( field ) + + def testArraySubscribe(self): + ti = pykd.typeInfo("g_testArray") + self.assertEqual(2, len(ti) ) + for field in ti: + str( field ) + + def testEnumSubscribe(self): + ti = pykd.typeInfo("enumType") + self.assertEqual(3, len(ti) ) + self.assertEqual( ( "TWO", 2 ), ti[1] ) + for field in ti: + str( field ) def testStructNullSize(self): ti = target.module.type("structNullSize")