Rev 188: Fix some 32 vs 64 bit issues. in http://bazaar.launchpad.net/%2Bbranch/meliae

John Arbash Meinel john at arbash-meinel.com
Tue Mar 22 10:45:23 UTC 2011


At http://bazaar.launchpad.net/%2Bbranch/meliae

------------------------------------------------------------
revno: 188
revision-id: john at arbash-meinel.com-20110322104515-iuccimlh0rl8fi2o
parent: john at arbash-meinel.com-20110322103212-q3ohgf1trmqh9lzw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: meliae
timestamp: Tue 2011-03-22 11:45:15 +0100
message:
  Fix some 32 vs 64 bit issues.
  
  On 64-bit even though the size of individual members are 4-bytes wide, we still don't
  change the alignment and packing defaults. So the structs default to aligned on
  8-byte wide, which 'wastes' 4-bytes at the end.
-------------- next part --------------
=== modified file 'meliae/tests/test__intset.py'
--- a/meliae/tests/test__intset.py	2010-07-28 21:13:06 +0000
+++ b/meliae/tests/test__intset.py	2011-03-22 10:45:15 +0000
@@ -1,14 +1,14 @@
-# Copyright (C) 2009, 2010 Canonical Ltd
-# 
+# Copyright (C) 2009, 2010, 2011 Canonical Ltd
+#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 3 as
 # published by the Free Software Foundation.
-# 
+#
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -130,10 +130,13 @@
         # 5: _mask
         # 6: _array
         # 4-byte int _has_singleton
-        self.assertSizeOf(6, iset, extra_size=4, has_gc=False)
+        # However, most compliers will align the struct based on the width of
+        # the largest entry. So while we could put 2 4-byte ints into the
+        # struct, it will waste 4-bytes anyway.
+        self.assertSizeOf(7, iset, has_gc=False)
         iset.add(12345)
         # Min allocation is 256 entries
-        self.assertSizeOf(6+256, iset, extra_size=4, has_gc=False)
+        self.assertSizeOf(7+256, iset, has_gc=False)
 
 
 class TestIDSet(TestIntSet):
@@ -151,7 +154,7 @@
         self.assertFalse(bigint in iset)
         iset.add(bigint)
         self.assertTrue(bigint in iset)
-        
+
     def test_add_singletons(self):
         pass
         # Negative values cannot be checked in IDSet, because we cast them to

=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py	2010-07-31 06:39:43 +0000
+++ b/meliae/tests/test__loader.py	2011-03-22 10:45:15 +0000
@@ -1,21 +1,19 @@
-# Copyright (C) 2009, 2010 Canonical Ltd
-# 
+# Copyright (C) 2009, 2010, 2011 Canonical Ltd
+#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 3 as
 # published by the Free Software Foundation.
-# 
+#
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 """Pyrex extension for tracking loaded objects"""
 
-import sys
-
 from meliae import (
     _loader,
     _scanner,
@@ -23,9 +21,22 @@
     tests,
     )
 
+# Empty table size is 1024 pointers
+# 1: PyType*
+# 2: refcnt
+# 3: vtable*
+# 4: _table*
+# 3 4-byte int attributes
+# Note that on 64-bit platforms, alignment issues mean we will still
+# round to a multiple-of-8 bytes.
+_memobj_extra_size = 3*4
+if (_memobj_extra_size % _scanner._word_size) != 0:
+    _memobj_extra_size += (_scanner._word_size
+                           - (_memobj_extra_size % _scanner._word_size))
 
 class TestMemObjectCollection(tests.TestCase):
 
+
     def test__init__(self):
         moc = _loader.MemObjectCollection()
         self.assertEqual(0, moc._active)
@@ -207,7 +218,10 @@
         # 3: vtable*
         # 4: _table*
         # 3 4-byte int attributes
-        self.assertSizeOf(4+1024, moc, extra_size=3*4, has_gc=False)
+        # Note that on 64-bit platforms, alignment issues mean we will still
+        # round to a multiple-of-8 bytes.
+        self.assertSizeOf(4+1024, moc, extra_size=_memobj_extra_size,
+                          has_gc=False)
 
     def test__sizeof__one_item(self):
         moc = _loader.MemObjectCollection()
@@ -222,7 +236,8 @@
         # 7: ulong total_size
         # 8: *proxy
         moc.add(0, 'foo', 100)
-        self.assertSizeOf(4+1024+8, moc, extra_size=3*4, has_gc=False)
+        self.assertSizeOf(4+1024+8, moc, extra_size=_memobj_extra_size,
+                          has_gc=False)
 
     def test__sizeof__with_reflists(self):
         moc = _loader.MemObjectCollection()
@@ -230,7 +245,8 @@
         # ref-list allocates the number of entries + 1
         # Each _memobject also takes up
         moc.add(0, 'foo', 100, children=[1234], parent_list=[3456, 7890])
-        self.assertSizeOf(4+1024+8+2+3, moc, extra_size=3*4, has_gc=False)
+        self.assertSizeOf(4+1024+8+2+3, moc, extra_size=_memobj_extra_size,
+                          has_gc=False)
 
     def test__sizeof__with_dummy(self):
         moc = _loader.MemObjectCollection()



More information about the bazaar-commits mailing list