diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-09-11 04:01:57 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-09-11 04:01:57 (GMT) |
commit | 71e2aa0cc5c07a4e15a48c35739f34d5ab69d26c (patch) | |
tree | 2cc125984da91cfec3c0b382053dc3e8d16cd942 | |
parent | 19d76c5aa88d8f673bc91529d25806d2e333aa84 (diff) | |
download | cpython-71e2aa0cc5c07a4e15a48c35739f34d5ab69d26c.zip cpython-71e2aa0cc5c07a4e15a48c35739f34d5ab69d26c.tar.gz cpython-71e2aa0cc5c07a4e15a48c35739f34d5ab69d26c.tar.bz2 |
Backport rev 51819 from Thomas Heller
Anonymous structure fields that have a bit-width specified did not work,
and they gave a strange error message from PyArg_ParseTuple:
function takes exactly 2 arguments (3 given).
-rw-r--r-- | Lib/ctypes/test/test_bitfields.py | 9 | ||||
-rw-r--r-- | Modules/_ctypes/stgdict.c | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py index 92c4669..2867cbf 100644 --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -215,5 +215,14 @@ class BitFieldTest(unittest.TestCase): ("b", c_ubyte, 4)] self.failUnlessEqual(sizeof(X), sizeof(c_byte)) + def test_anon_bitfields(self): + # anonymous bit-fields gave a strange error message + class X(Structure): + _fields_ = [("a", c_byte, 4), + ("b", c_ubyte, 4)] + class Y(Structure): + _anonymous_ = ["_"] + _fields_ = [("_", X)] + if __name__ == "__main__": unittest.main() diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 182b9af..d701f9e 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -177,11 +177,11 @@ MakeFields(PyObject *type, CFieldObject *descr, for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) { PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */ - PyObject *fname, *ftype; + PyObject *fname, *ftype, *bits; CFieldObject *fdescr; CFieldObject *new_descr; /* Convert to PyArg_UnpackTuple... */ - if (!PyArg_ParseTuple(pair, "OO", &fname, &ftype)) { + if (!PyArg_ParseTuple(pair, "OO|O", &fname, &ftype, &bits)) { Py_DECREF(fieldlist); return -1; } |