[0.3.x] added alignment-requirement for custom types, added alignment for unions

git-svn-id: https://pykd.svn.codeplex.com/svn@86873 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2013-12-17 14:50:57 +00:00 committed by Mikhail I. Izmestev
parent 5a1c2945e4
commit ab7fa30e8e
3 changed files with 24 additions and 4 deletions

View File

@ -67,6 +67,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, pykd::findSymbol, 1, 2 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 );
//
BOOST_PYTHON_FUNCTION_OVERLOADS( createStruct_, kdlib::defineStruct, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( createUnion_, kdlib::defineUnion, 1, 2 );
//
BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumSymbols, ModuleAdapter::enumSymbols, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( Module_findSymbol, ModuleAdapter::findSymbol, 2, 3 );
@ -292,8 +293,8 @@ BOOST_PYTHON_MODULE( pykd )
// "Return custom defined struct" );
python::def( "createStruct", &pykd::defineStruct, createStruct_( python::args( "name", "align" ),
"Create custom struct" ) );
python::def( "createUnion", &pykd::defineUnion,
"Create custom union" );
python::def( "createUnion", &pykd::defineUnion, createUnion_( python::args( "name", "align" ),
"Create custom union" ) );
// CPU registers
python::def( "reg", pykd::getRegisterByName,

View File

@ -27,10 +27,10 @@ inline kdlib::TypeInfoPtr defineStruct( const std::wstring &structName, size_t a
return kdlib::defineStruct(structName, align);
}
inline kdlib::TypeInfoPtr defineUnion( const std::wstring& unionName )
inline kdlib::TypeInfoPtr defineUnion( const std::wstring& unionName, size_t align = 0 )
{
AutoRestorePyState pystate;
return kdlib::defineUnion(unionName);
return kdlib::defineUnion(unionName, align);
}

View File

@ -113,4 +113,23 @@ class CustomTypesTest(unittest.TestCase):
struct.append( "m_field7", baseTypes.UInt1B.arrayOf(5) )
self.assertEqual( 20, struct.size() )
def testUnionAlignedSize(self):
union = pykd.createUnion("MyCustomUnion", align=4)
union.append( "m_field1", baseTypes.UInt2B )
self.assertEqual( 2, union.size() )
union.append( "m_field2", baseTypes.UInt1B.arrayOf(3) )
self.assertEqual( 4, union.size() )
def testWi12591(self):
struct = pykd.createStruct(name ="MyAlignStruct", align=4)
struct.append( "m_field1", baseTypes.UInt1B )
struct.append( "m_field2", baseTypes.UInt1B.arrayOf(2) )
self.assertEqual( struct.size(), 3 )
self.assertEqual( struct.fieldOffset("m_field2"), 1 )
def testWi12592(self):
struct = pykd.createStruct(name ="MyAlignStruct", align=4)
struct.append( "field1", baseTypes.UInt4B )
struct.append( "field2", baseTypes.UInt1B )
self.assertEqual( struct.size(), 8 )
self.assertEqual( struct.fieldOffset("field2"), 4 )