From ae1e83e9d5182df7a1eb0ad28304dd7af8ef43e0 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Tue, 17 Dec 2013 14:13:48 +0000 Subject: [PATCH] [0.2.x] + align for custom union git-svn-id: https://pykd.svn.codeplex.com/svn@86872 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/customtypes.cpp | 8 ++++---- pykd/customtypes.h | 4 ++-- pykd/python/pymod.cpp | 5 +++-- test/scripts/customtypestest.py | 8 ++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pykd/customtypes.cpp b/pykd/customtypes.cpp index 3491d8c..32d9351 100644 --- a/pykd/customtypes.cpp +++ b/pykd/customtypes.cpp @@ -9,16 +9,16 @@ namespace pykd { //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeBuilder::createStruct( const std::string &name, ULONG align ) +TypeInfoPtr TypeBuilder::createStruct( const std::string &name, ULONG align ) { - return TypeInfoPtr( new CustomStruct( name, m_ptrSize, align ? align : m_ptrSize ) ); + return TypeInfoPtr( new CustomStruct( name, m_ptrSize, align ) ); } //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeBuilder::createUnion( const std::string &name ) +TypeInfoPtr TypeBuilder::createUnion( const std::string &name, ULONG align ) { - return TypeInfoPtr( new CustomUnion( name, m_ptrSize, m_ptrSize ) ); + return TypeInfoPtr( new CustomUnion( name, m_ptrSize, align ) ); } //////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/customtypes.h b/pykd/customtypes.h index 3015e18..75344fc 100644 --- a/pykd/customtypes.h +++ b/pykd/customtypes.h @@ -41,7 +41,7 @@ public: TypeInfoPtr createStruct( const std::string &name, ULONG align = 0 ); - TypeInfoPtr createUnion( const std::string &name); + TypeInfoPtr createUnion( const std::string &name, ULONG align = 0); private: @@ -63,7 +63,7 @@ protected: UdtTypeInfoBase( name ) { m_ptrSize = pointerSize; - m_align = align; + m_align = align ? align : m_ptrSize; m_size = 0; } diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index 1a63a3b..e9e613a 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -69,6 +69,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( TypeBuilder_createStruct, TypeBuilder::createStruct, 1, 2 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( TypeBuilder_createUnion, TypeBuilder::createUnion, 1, 2 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_enumSymbols, Module::enumSymbols, 0, 1 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_findSymbol, Module::getSymbolNameByVa, 1, 2 ); @@ -518,8 +519,8 @@ BOOST_PYTHON_MODULE( pykd ) .add_property( "VoidPtr", &TypeBuilder::getVoidPtr ) .def( "createStruct", &TypeBuilder::createStruct, TypeBuilder_createStruct( python::args( "name", "align" ), "Create custom struct" ) ) - .def( "createUnion", &TypeBuilder::createUnion, - "Create custom union" ); + .def( "createUnion", &TypeBuilder::createUnion, TypeBuilder_createUnion( python::args( "name", "align" ), + "Create custom union" ) ); python::class_ >( "cpuReg", "CPU regsiter class", boost::python::no_init ) diff --git a/test/scripts/customtypestest.py b/test/scripts/customtypestest.py index 6280c92..55ab8d7 100644 --- a/test/scripts/customtypestest.py +++ b/test/scripts/customtypestest.py @@ -142,6 +142,14 @@ class CustomTypesTest(unittest.TestCase): struct.append( "m_field7", tb.UInt1B.arrayOf(5) ) self.assertEqual( 20, struct.size() ) + def testUnionAlignedSize(self): + tb = pykd.typeBuilder() + union = tb.createUnion("MyCustomUnion", align=4) + union.append( "m_field1", tb.UInt2B ) + self.assertEqual( 2, union.size() ) + union.append( "m_field2", tb.UInt1B.arrayOf(3) ) + self.assertEqual( 4, union.size() ) + def testWi12591(self): tb = pykd.typeBuilder() struct = tb.createStruct(name ="MyAlignStruct", align=4)