8000 [3.8] bpo-22273: Changed conditions for ctypes array-in-struct handli… · python/cpython@b92b8c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b92b8c5

Browse files
authored
[3.8] bpo-22273: Changed conditions for ctypes array-in-struct handling. (GH-16381) (GH-16401)
(cherry picked from commit c64af8f)
1 parent 4267e8f commit b92b8c5

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
@@ -350,9 +350,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
350350
int pack;
351351
Py_ssize_t ffi_ofs;
352352
int big_endian;
353-
#if defined(X86_64)
354353
int arrays_seen = 0;
355-
#endif
356354

357355
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
358356
be a way to use the old, broken semantics: _fields_ are not extended
@@ -504,10 +502,8 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
504502
Py_XDECREF(pair);
505503
return -1;
506504
}
507-
#if defined(X86_64)
508505
if (PyCArrayTypeObject_Check(desc))
509506
arrays_seen = 1;
510-
#endif
511507
dict = PyType_stgdict(desc);
512508
if (dict == NULL) {
513509
Py_DECREF(pair);
@@ -648,8 +644,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
648644
stgdict->align = total_align;
649645
stgdict->length = len; /* ADD ffi_ofs? */
650646

651-
#if defined(X86_64)
652-
653647
#define MAX_ELEMENTS 16
654648

655649
if (arrays_seen && (size <= 16)) {
@@ -669,6 +663,10 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
669663
* accurate set, to allow libffi to marshal them into registers
670664
* correctly. It means one more loop over the fields, but if we got
671665
* here, the structure is small, so there aren't too many of those.
666+
*
667+
* Although the passing in registers is specific to 64-bit Linux, the
668+
* array-in-struct vs. pointer problem is general. But we restrict the
669+
* type transformation to small structs nonetheless.
672670
*/
673671
ffi_type *actual_types[MAX_ELEMENTS + 1];
674672
int actual_type_index = 0;
@@ -746,7 +744,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
746744
memcpy(&stgdict->ffi_type_pointer.elements[ffi_ofs], actual_types,
747745
actual_type_index * sizeof(ffi_type *));
748746
}
749-
#endif
750747

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

0 commit comments

Comments
 (0)
0