summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-07-11 17:47:06 (GMT)
committerGitHub <noreply@github.com>2021-07-11 17:47:06 (GMT)
commit42da46ed522157b057d73e6b623615ef6427999e (patch)
tree40dd1075d5558b1665de9e6c8f4652cfd1053cff /Modules
parent1577259cc51d0d46ad676798ce0a130039acf956 (diff)
downloadcpython-42da46ed522157b057d73e6b623615ef6427999e.zip
cpython-42da46ed522157b057d73e6b623615ef6427999e.tar.gz
cpython-42da46ed522157b057d73e6b623615ef6427999e.tar.bz2
bpo-29753: revert 0d7ad9f (GH-19850) (GH-27085)
This reverts commit 0d7ad9fb38c041c46094087b0cf2c8ce44916b11 as it has a regression. See https://github.com/python/cpython/pull/19850GH-issuecomment-869410686 (cherry picked from commit e14d5ae5447ae28fc4828a9cee8e9007f9c30700) Co-authored-by: Filipe LaĆ­ns <lains@archlinux.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/cfield.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 8d0710f..a21a9da 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -71,18 +71,6 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
Py_DECREF(self);
return NULL;
}
-
-#ifndef MS_WIN32
- /* if we have a packed bitfield, calculate the minimum number of bytes we
- need to fit it. otherwise use the specified size. */
- if (pack && bitsize) {
- size = (bitsize - 1) / 8 + 1;
- } else
-#endif
- size = dict->size;
-
- proto = desc;
-
if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
#ifdef MS_WIN32
@@ -99,9 +87,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
} else if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
&& dict->size * 8 >= *pfield_size
- /* if this is a packed bitfield, always expand it.
- otherwise calculate if we need to expand it. */
- && (((*pbitofs + bitsize) <= dict->size * 8) || pack)) {
+ && (*pbitofs + bitsize) <= dict->size * 8) {
/* expand bit field */
fieldtype = EXPAND_BITFIELD;
#endif
@@ -109,9 +95,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
/* start new bitfield */
fieldtype = NEW_BITFIELD;
*pbitofs = 0;
- /* use our calculated size (size) instead of type size (dict->size),
- which can be different for packed bitfields */
- *pfield_size = size * 8;
+ *pfield_size = dict->size * 8;
} else {
/* not a bit field */
fieldtype = NO_BITFIELD;
@@ -119,6 +103,9 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
*pfield_size = 0;
}
+ size = dict->size;
+ proto = desc;
+
/* Field descriptors for 'c_char * n' are be scpecial cased to
return a Python string instead of an Array object instance...
*/
@@ -183,16 +170,10 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
break;
case EXPAND_BITFIELD:
- /* increase the size if it is a packed bitfield.
- EXPAND_BITFIELD should not be selected for non-packed fields if the
- current size isn't already enough. */
- if (pack)
- size = (*pbitofs + bitsize - 1) / 8 + 1;
-
- *poffset += size - *pfield_size/8;
- *psize += size - *pfield_size/8;
+ *poffset += dict->size - *pfield_size/8;
+ *psize += dict->size - *pfield_size/8;
- *pfield_size = size * 8;
+ *pfield_size = dict->size * 8;
if (big_endian)
self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize;