[Python-checkins] [3.7] bpo-22273: Changed conditions for ctypes array-in-struct handling. (GH-16381) (GH-16400)
Vinay Sajip
webhook-mailer at python.org
Wed Sep 25 16:37:45 EDT 2019
https://github.com/python/cpython/commit/d015714f89af5c57b7071a74eeca618577b3dfe4
commit: d015714f89af5c57b7071a74eeca618577b3dfe4
branch: 3.7
author: Vinay Sajip <vinay_sajip at yahoo.co.uk>
committer: GitHub <noreply at github.com>
date: 2019-09-25T21:37:24+01:00
summary:
[3.7] bpo-22273: Changed conditions for ctypes array-in-struct handling. (GH-16381) (GH-16400)
(cherry picked from commit c64af8fad3c4f5751af624647fbb0ce023f525dc)
files:
M Modules/_ctypes/stgdict.c
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index e584abc96f1a..5388a3154b50 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -344,9 +344,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
int pack = 0;
Py_ssize_t ffi_ofs;
int big_endian;
-#if defined(X86_64)
int arrays_seen = 0;
-#endif
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
be a way to use the old, broken sematics: _fields_ are not extended
@@ -471,10 +469,8 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
Py_XDECREF(pair);
return -1;
}
-#if defined(X86_64)
if (PyCArrayTypeObject_Check(desc))
arrays_seen = 1;
-#endif
dict = PyType_stgdict(desc);
if (dict == NULL) {
Py_DECREF(pair);
@@ -615,8 +611,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
stgdict->align = total_align;
stgdict->length = len; /* ADD ffi_ofs? */
-#if defined(X86_64)
-
#define MAX_ELEMENTS 16
if (arrays_seen && (size <= 16)) {
@@ -636,6 +630,10 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
* accurate set, to allow libffi to marshal them into registers
* correctly. It means one more loop over the fields, but if we got
* here, the structure is small, so there aren't too many of those.
+ *
+ * Although the passing in registers is specific to 64-bit Linux, the
+ * array-in-struct vs. pointer problem is general. But we restrict the
+ * type transformation to small structs nonetheless.
*/
ffi_type *actual_types[MAX_ELEMENTS + 1];
int actual_type_index = 0;
@@ -713,7 +711,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
memcpy(&stgdict->ffi_type_pointer.elements[ffi_ofs], actual_types,
actual_type_index * sizeof(ffi_type *));
}
-#endif
/* We did check that this flag was NOT set above, it must not
have been set until now. */
More information about the Python-checkins
mailing list