diff options
author | Thomas Heller <theller@ctypes.org> | 2009-07-21 06:27:14 +0000 |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2009-07-21 06:27:14 +0000 |
commit | 6adda9641d41c858cfe2318f9e4e5b898ee1dce4 (patch) | |
tree | a6a4f5f1d67d5a732f9bbc51af761ee01f6671dc | |
parent | 4d4b7398a283da7f8cf0e2f7bc7abd9a054b169f (diff) | |
download | cpython-git-6adda9641d41c858cfe2318f9e4e5b898ee1dce4.tar.gz |
Issue #6493: Fix a ctypes problem setting bitfields more than 31 bits
wide.
-rw-r--r-- | Lib/ctypes/test/test_bitfields.py | 15 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 4 |
3 files changed, 19 insertions, 2 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py index e9c46c2c20..211d1db022 100644 --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -240,5 +240,20 @@ class BitFieldTest(unittest.TestCase): _anonymous_ = ["_"] _fields_ = [("_", X)] + def test_uint32(self): + class X(Structure): + _fields_ = [("a", c_uint32, 32)] + x = X() + x.a = 10 + self.failUnlessEqual(x.a, 10) + + def test_uint64(self): + class X(Structure): + _fields_ = [("a", c_uint64, 64)] + x = X() + x.a = 10 + self.failUnlessEqual(x.a, 10) + + if __name__ == "__main__": unittest.main() @@ -349,6 +349,8 @@ Core and Builtins Library ------- +- Issue #6493: Fix a ctypes problem setting bitfields more than 31 bits wide. + - unittest has been split up into a package. All old names should still work. - Issue #6431: Make Fraction type return NotImplemented when it doesn't diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index bf247bc41b..766348189a 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -426,9 +426,9 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) #define LOW_BIT(x) ((x) & 0xFFFF) #define NUM_BITS(x) ((x) >> 16) -/* This seems nore a compiler issue than a Windows/non-Windows one */ +/* This seems more a compiler issue than a Windows/non-Windows one */ #ifdef MS_WIN32 -# define BIT_MASK(size) ((1 << NUM_BITS(size))-1) +# define BIT_MASK(size) ((1i64 << NUM_BITS(size))-1) #else # define BIT_MASK(size) ((1LL << NUM_BITS(size))-1) #endif |