Skip to content

Commit d015714

Browse files
authored
[3.7] bpo-22273: Changed conditions for ctypes array-in-struct handling. (GH-16381) (GH-16400)
(cherry picked from commit c64af8f)
1 parent 585798f commit d015714

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Modules/_ctypes/stgdict.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
344344
int pack = 0;
345345
Py_ssize_t ffi_ofs;
346346
int big_endian;
347-
#if defined(X86_64)
348347
int arrays_seen = 0;
349-
#endif
350348

351349
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
352350
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
471469
Py_XDECREF(pair);
472470
return -1;
473471
}
474-
#if defined(X86_64)
475472
if (PyCArrayTypeObject_Check(desc))
476473
arrays_seen = 1;
477-
#endif
478474
dict = PyType_stgdict(desc);
479475
if (dict == NULL) {
480476
Py_DECREF(pair);
@@ -615,8 +611,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
615611
stgdict->align = total_align;
616612
stgdict->length = len; /* ADD ffi_ofs? */
617613

618-
#if defined(X86_64)
619-
620614
#define MAX_ELEMENTS 16
621615

622616
if (arrays_seen && (size <= 16)) {
@@ -636,6 +630,10 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
636630
* accurate set, to allow libffi to marshal them into registers
637631
* correctly. It means one more loop over the fields, but if we got
638632
* here, the structure is small, so there aren't too many of those.
633+
*
634+
* Although the passing in registers is specific to 64-bit Linux, the
635+
* array-in-struct vs. pointer problem is general. But we restrict the
636+
* type transformation to small structs nonetheless.
639637
*/
640638
ffi_type *actual_types[MAX_ELEMENTS + 1];
641639
int actual_type_index = 0;
@@ -713,7 +711,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
713711
memcpy(&stgdict->ffi_type_pointer.elements[ffi_ofs], actual_types,
714712
actual_type_index * sizeof(ffi_type *));
715713
}
716-
#endif
717714

718715
/* We did check that this flag was NOT set above, it must not
719716
have been set until now. */

0 commit comments

Comments
 (0)