Skip to content

Commit 22462da

Browse files
aixtoolsncoghlan
authored andcommitted
bpo-27643 - skip test_ctypes test case with XLC compiler. (GH-5164)
This test case needs "signed short" bitfields, but the IBM XLC compiler (on AIX) does not support this. Skip the code and test when AIX and XLC are used. Use __xlc__ as identifier to detect the XLC compiler.
1 parent 5661459 commit 22462da

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

Lib/ctypes/test/test_bitfields.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_ints(self):
4040
self.assertEqual(getattr(b, name), func(byref(b), name.encode('ascii')))
4141

4242
def test_shorts(self):
43+
b = BITS()
44+
name = "M"
45+
if func(byref(b), name.encode('ascii')) == 999:
46+
self.skipTest("Compiler does not support signed short bitfields")
4347
for i in range(256):
4448
for name in "MNOPQRS":
4549
b = BITS()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Test_C test case needs "signed short" bitfields, but the
2+
IBM XLC compiler (on AIX) does not support this
3+
Skip the code and test when AIX and XLC are used
4+
5+
Applicable to Python2-2.7 and later

Modules/_ctypes/_ctypes_test.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,15 @@ EXPORT(long long) last_tf_arg_s = 0;
414414
EXPORT(unsigned long long) last_tf_arg_u = 0;
415415

416416
struct BITS {
417-
int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
418-
short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7;
417+
signed int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
418+
/*
419+
* The test case needs/uses "signed short" bitfields, but the
420+
* IBM XLC compiler does not support this
421+
*/
422+
#ifndef __xlc__
423+
#define SIGNED_SHORT_BITFIELDS
424+
short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7;
425+
#endif
419426
};
420427

421428
EXPORT(void) set_bitfields(struct BITS *bits, char name, int value)
@@ -430,14 +437,15 @@ EXPORT(void) set_bitfields(struct BITS *bits, char name, int value)
430437
case 'G': bits->G = value; break;
431438
case 'H': bits->H = value; break;
432439
case 'I': bits->I = value; break;
433-
440+
#ifdef SIGNED_SHORT_BITFIELDS
434441
case 'M': bits->M = value; break;
435442
case 'N': bits->N = value; break;
436443
case 'O': bits->O = value; break;
437444
case 'P': bits->P = value; break;
438445
case 'Q': bits->Q = value; break;
439446
case 'R': bits->R = value; break;
440447
case 'S': bits->S = value; break;
448+
#endif
441449
}
442450
}
443451

@@ -454,15 +462,17 @@ EXPORT(int) unpack_bitfields(struct BITS *bits, char name)
454462
case 'H': return bits->H;
455463
case 'I': return bits->I;
456464

465+
#ifdef SIGNED_SHORT_BITFIELDS
457466
case 'M': return bits->M;
458467
case 'N': return bits->N;
459468
case 'O': return bits->O;
460469
case 'P': return bits->P;
461470
case 'Q': return bits->Q;
462471
case 'R': return bits->R;
463472
case 'S': return bits->S;
473+
#endif
464474
}
465-
return 0;
475+
return 999;
466476
}
467477

468478
static PyMethodDef module_methods[] = {

0 commit comments

Comments
 (0)