Author: Brian Kearns <[email protected]>
Branch: stdlib-2.7.6
Changeset: r69641:ffc94b4dd771
Date: 2014-03-03 16:19 -0500
http://bitbucket.org/pypy/pypy/changeset/ffc94b4dd771/

Log:    another go at rawffi

diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -268,7 +268,7 @@
     return x >> 16
 
 def BIT_MASK(x, ll_t):
-    return (((1 << (x - 1)) - 1) << 1) + 1
+    return (((widen(rffi.cast(ll_t, 1)) << (x - 1)) - 1) << 1) + 1
 BIT_MASK._annspecialcase_ = 'specialize:arg(1)'
 
 def push_field(self, num, value):
diff --git a/pypy/module/_rawffi/test/test__rawffi.py 
b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -490,7 +490,7 @@
         assert x.C == 1
         x.free()
 
-    def test_structure_bitfields(self):
+    def test_structure_bitfields_varied(self):
         import _rawffi
         X = _rawffi.Structure([('A', 'I', 1),
                                ('B', 'I', 2),
@@ -504,37 +504,47 @@
         assert x.C == -1
         x.free()
 
+    def test_structure_bitfields_int(self):
+        import _rawffi
         Y = _rawffi.Structure([('a', 'i', 1),
                                ('b', 'i', 30),
                                ('c', 'i', 1)])
         y = Y()
-        y.a, y.b, y.c = -1, -7, 0
-        assert (y.a, y.b, y.c) == (-1, -7, 0)
+        y.a, y.b, y.c = -1, -7, 1
+        assert (y.a, y.b, y.c) == (-1, -7, -1)
         y.free()
 
-    def test_structure_ulonglong_bitfields(self):
+    def test_structure_bitfields_uint(self):
         import _rawffi
-        X = _rawffi.Structure([('A', 'Q', 1),
-                               ('B', 'Q', 62),
-                               ('C', 'Q', 1)])
-        x = X()
-        x.A, x.B, x.C = 7, 0x1000000000000001, 7
-        assert x.A == 1
-        assert x.B == 0x1000000000000001
-        assert x.C == 1
-        x.free()
+        Y = _rawffi.Structure([('a', 'I', 1),
+                               ('b', 'I', 30),
+                               ('c', 'I', 1)])
+        y = Y()
+        y.a, y.b, y.c = 7, (1 << 29) | 1, 7
+        assert (y.a, y.b, y.c) == (1, (1 << 29) | 1, 1)
+        y.free()
 
-    def test_structure_longlong_bitfields(self):
+    def test_structure_bitfields_longlong(self):
         import _rawffi
         Y = _rawffi.Structure([('a', 'q', 1),
-                               ('b', 'q', 61),
+                               ('b', 'q', 62),
                                ('c', 'q', 1)])
         y = Y()
-        y.a, y.b, y.c = 0, -7, 0
-        assert (y.a, y.b, y.c) == (0, -7, 0)
+        y.a, y.b, y.c = -1, -7, 1
+        assert (y.a, y.b, y.c) == (-1, -7, -1)
         y.free()
 
-    def test_structure_single_longbit_bitfield(self):
+    def test_structure_bitfields_ulonglong(self):
+        import _rawffi
+        Y = _rawffi.Structure([('a', 'Q', 1),
+                               ('b', 'Q', 62),
+                               ('c', 'Q', 1)])
+        y = Y()
+        y.a, y.b, y.c = 7, (1 << 61) | 1, 7
+        assert (y.a, y.b, y.c) == (1, (1 << 61) | 1, 1)
+        y.free()
+
+    def test_structure_bitfields_single(self):
         import _rawffi
         for s in [('I', 32), ('Q', 64)]:
             Y = _rawffi.Structure([('a',) + s])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to