diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 7188d85..4155bcc 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -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, diff --git a/pykd/pytypeinfo.h b/pykd/pytypeinfo.h index 3730a20..a6b5782 100644 --- a/pykd/pytypeinfo.h +++ b/pykd/pytypeinfo.h @@ -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); } diff --git a/test/scripts/customtypestest.py b/test/scripts/customtypestest.py index 0ca5abf..6b5e253 100644 --- a/test/scripts/customtypestest.py +++ b/test/scripts/customtypestest.py @@ -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 )