[pypy-svn] r72823 - pypy/branch/fix-64/pypy/rpython/tool/test

arigo at codespeak.net arigo at codespeak.net
Thu Mar 25 16:43:45 CET 2010


Author: arigo
Date: Thu Mar 25 16:43:44 2010
New Revision: 72823

Modified:
   pypy/branch/fix-64/pypy/rpython/tool/test/test_rffi_platform.py
Log:
Write a test about what I would like to have.


Modified: pypy/branch/fix-64/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/branch/fix-64/pypy/rpython/tool/test/test_rffi_platform.py	(original)
+++ pypy/branch/fix-64/pypy/rpython/tool/test/test_rffi_platform.py	Thu Mar 25 16:43:44 2010
@@ -256,3 +256,88 @@
         library_dirs = [str(tmpdir)]
         )
     rffi_platform.verify_eci(eci)
+
+def test_generate_padding():
+    # 'padding_drop' is a bit strange, but is what we need to write C code
+    # that defines prebuilt structures of that type.  Normally, the C
+    # backend would generate '0' entries for every field c__pad#.  That's
+    # usually much more than the number of real fields in the real structure
+    # definition.  So 'padding_drop' allows a quick fix: it lists fields
+    # that should be ignored by the C backend.  It should only be used in
+    # that situation because it lists some of the c__pad# fields a bit
+    # randomly -- to the effect that writing '0' for the other fields gives
+    # the right amount of '0's.
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;        /* followed by one byte of padding */
+                short s1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("s1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0',)
+    assert S._hints['padding_drop'] == ('c__pad0',)
+    #
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;
+                char c2;  /* _pad0 */
+                short s1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("s1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0',)
+    assert S._hints['padding_drop'] == ()
+    #
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;
+                char c2;  /* _pad0 */
+                /* _pad1, _pad2 */
+                int i1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("i1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+    assert S._hints['padding_drop'] == ('c__pad1', 'c__pad2')
+    #
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;
+                char c2;  /* _pad0 */
+                char c3;  /* _pad1 */
+                /* _pad2 */
+                int i1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("i1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+    assert S._hints['padding_drop'] == ('c__pad2',)
+    #
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;
+                /* _pad0 */
+                short s1;  /* _pad1, _pad2 */
+                int i1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("i1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+    assert S._hints['padding_drop'] == ('c__pad1', 'c__pad2')
+    #
+    S = rffi_platform.getstruct("foobar_t", """
+           typedef struct {
+                char c1;
+                char c2;  /* _pad0 */
+                /* _pad1, _pad2 */
+                int i1;
+                char c3;  /* _pad3 */
+                /* _pad4 */
+                short s1;
+           } foobar_t;
+           """, [("c1", lltype.Signed),
+                 ("i1", lltype.Signed),
+                 ("s1", lltype.Signed)])
+    assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2',
+                                   'c__pad3', 'c__pad4')
+    assert S._hints['padding_drop'] == ('c__pad1', 'c__pad2', 'c__pad4')



More information about the Pypy-commit mailing list