8000 Changed conditions for ctypes array-in-struct handling. (GH-16381) · python/cpython@c64af8f · GitHub
[go: up one dir, main page]

Skip to content

Commit c64af8f

Browse files
authored
Changed conditions for ctypes array-in-struct handling. (GH-16381)
1 parent 17deb16 commit c64af8f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Lib/ctypes/test/test_structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class X(Structure):
480480
self.assertEqual(s.first, got.first)
481481
self.assertEqual(s.second, got.second)
482482

483-
@unittest.skipIf(MACHINE in ('armv7l', 'ppc64'),
483+
@unittest.skipIf(MACHINE.startswith(('arm', 'ppc')),
484484
'Test temporarily disabled on this architecture')
485485
def test_array_in_struct(self):
486486
# See bpo-22273

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 <= MAX_ELEMENTS)) {
@@ -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