Skip to content

Commit 3792b4b

Browse files
vsajipshihai1991
authored andcommitted
bpo-16575: Disabled checks for union types being passed by value. (pythonGH-17960)
Although the underlying libffi issue remains open, adding these checks have caused problems in third-party projects which are in widespread use. See the issue for examples. The corresponding tests have also been skipped.
1 parent f31216c commit 3792b4b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Lib/ctypes/test/test_structures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ class U(Union):
576576
self.assertEqual(f2, [0x4567, 0x0123, 0xcdef, 0x89ab,
577577
0x3210, 0x7654, 0xba98, 0xfedc])
578578

579+
@unittest.skipIf(True, 'Test disabled for now - see bpo-16575/bpo-16576')
579580
def test_union_by_value(self):
580581
# See bpo-16575
581582

@@ -656,7 +657,7 @@ class Test5(Structure):
656657
self.assertEqual(test5.nested.an_int, 0)
657658
self.assertEqual(test5.another_int, 0)
658659

659-
#@unittest.skipIf('s390' in MACHINE, 'Test causes segfault on S390')
660+
@unittest.skipIf(True, 'Test disabled for now - see bpo-16575/bpo-16576')
660661
def test_bitfield_by_value(self):
661662
# See bpo-16576
662663

Modules/_ctypes/_ctypes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,23 @@ converters_from_argtypes(PyObject *ob)
24012401
for (i = 0; i < nArgs; ++i) {
24022402
PyObject *cnv;
24032403
PyObject *tp = PyTuple_GET_ITEM(ob, i);
2404+
/*
2405+
* The following checks, relating to bpo-16575 and bpo-16576, have been
2406+
* disabled. The reason is that, although there is a definite problem with
2407+
* how libffi handles unions (https://github.com/libffi/libffi/issues/33),
2408+
* there are numerous libraries which pass structures containing unions
2409+
* by values - especially on Windows but examples also exist on Linux
2410+
* (https://bugs.python.org/msg359834).
2411+
*
2412+
* It may not be possible to get proper support for unions and bitfields
2413+
* until support is forthcoming in libffi, but for now, adding the checks
2414+
* has caused problems in otherwise-working software, which suggests it
2415+
* is better to disable the checks.
2416+
*
2417+
* Although specific examples reported relate specifically to unions and
2418+
* not bitfields, the bitfields check is also being disabled as a
2419+
* precaution.
2420+
24042421
StgDictObject *stgdict = PyType_stgdict(tp);
24052422
24062423
if (stgdict != NULL) {
@@ -2428,6 +2445,7 @@ converters_from_argtypes(PyObject *ob)
24282445
return NULL;
24292446
}
24302447
}
2448+
*/
24312449

24322450
if (_PyObject_LookupAttrId(tp, &PyId_from_param, &cnv) <= 0) {
24332451
Py_DECREF(converters);

0 commit comments

Comments
 (0)