cpython: 6707637f68ca (original) (raw)

Mercurial > cpython

changeset 83807:6707637f68ca

Issue #14596: The struct.Struct() objects now use more compact implementation. [#14596]

Serhiy Storchaka storchaka@gmail.com
date Fri, 17 May 2013 10:49:44 +0300
parents 27cc0e0b7637
children 9ff8b6d4d479
files Lib/test/test_struct.py Misc/NEWS Modules/_struct.c
diffstat 3 files changed, 99 insertions(+), 87 deletions(-)[+] [-] Lib/test/test_struct.py 9 Misc/NEWS 2 Modules/_struct.c 175

line wrap: on

line diff

--- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -8,7 +8,6 @@ import sys from test import support ISBIGENDIAN = sys.byteorder == "big" -IS32BIT = sys.maxsize == 0x7fffffff integer_codes = 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'n', 'N' byteorders = '', '@', '=', '<', '>', '!' @@ -538,10 +537,6 @@ class StructTest(unittest.TestCase): hugecount2 = '{}b{}H'.format(sys.maxsize//2, sys.maxsize//2) self.assertRaises(struct.error, struct.calcsize, hugecount2)

- def test_trailing_counter(self): store = array.array('b', b' '*100) @@ -578,7 +573,7 @@ class StructTest(unittest.TestCase): # The size of 'PyStructObject' totalsize = support.calcobjsize('2n3P') # The size taken up by the 'formatcode' dynamic array

@support.cpython_only @@ -589,7 +584,7 @@ class StructTest(unittest.TestCase): self.check_sizeof('B' * 1234, 1234) self.check_sizeof('fd', 2) self.check_sizeof('xxxxxxxxxxxxxx', 0)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -91,6 +91,8 @@ Core and Builtins Library ------- +- Issue #14596: The struct.Struct() objects now use more compact implementation. +

--- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -26,6 +26,7 @@ typedef struct _formatcode { const struct _formatdef *fmtdef; Py_ssize_t offset; Py_ssize_t size;

} formatcode; /* Struct object interface */ @@ -1263,7 +1264,7 @@ prepare_s(PyStructObject *self) const char *s; const char *fmt; char c;

fmt = PyBytes_AS_STRING(self->s_format); @@ -1272,6 +1273,7 @@ prepare_s(PyStructObject *self) s = fmt; size = 0; len = 0;

@@ -1301,9 +1303,9 @@ prepare_s(PyStructObject self) switch (c) { case 's': / fall through */

itemsize = e->size; @@ -1318,14 +1320,14 @@ prepare_s(PyStructObject self) } / check for overflow */

@@ -1357,23 +1359,24 @@ prepare_s(PyStructObject *self) codes->offset = size; codes->size = num; codes->fmtdef = e;

return 0; @@ -1462,22 +1465,26 @@ s_unpack_internal(PyStructObject *soself return NULL; for (code = soself->s_codes; code->fmtdef != NULL; code++) {