Author: Brian Kearns <[email protected]>
Branch: stdlib-2.7.6
Changeset: r69643:456583a14be5
Date: 2014-03-03 17:47 -0500
http://bitbucket.org/pypy/pypy/changeset/456583a14be5/
Log: more rawffi work
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
@@ -15,7 +15,8 @@
from pypy.module._rawffi.interp_rawffi import size_alignment
from pypy.module._rawffi.interp_rawffi import read_ptr, write_ptr
from rpython.rlib import clibffi, rgc
-from rpython.rlib.rarithmetic import intmask, signedtype, widen, r_uint,
r_longlong
+from rpython.rlib.rarithmetic import intmask, signedtype, widen, r_uint, \
+ r_longlong, r_ulonglong
from rpython.rtyper.lltypesystem import lltype, rffi
@@ -268,7 +269,14 @@
return x >> 16
def BIT_MASK(x, ll_t):
- return (((widen(rffi.cast(ll_t, 1)) << (x - 1)) - 1) << 1) + 1
+ if ll_t is lltype.SignedLongLong:
+ one = r_longlong(1)
+ elif ll_t is lltype.UnsignedLongLong:
+ one = r_ulonglong(1)
+ else:
+ one = 1
+ # to avoid left shift by x == sizeof(ll_t)
+ return (((one << (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
@@ -544,7 +544,19 @@
assert (y.a, y.b, y.c) == (1, (1 << 61) | 1, 1)
y.free()
- def test_structure_bitfields_single(self):
+ def test_structure_bitfields_single_signed(self):
+ import _rawffi
+ for s in [('i', 32), ('q', 64)]:
+ Y = _rawffi.Structure([('a',) + s])
+ y = Y()
+ y.a = 10
+ assert y.a == 10
+ val = (1 << (s[1] - 1)) | 1
+ y.a = val
+ assert y.a == val - (1 << s[1])
+ y.free()
+
+ def test_structure_bitfields_single_unsigned(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