code: def test_bitfield_by_value(self):
      # See bpo-16576
  
      # These should mirror the structures in Modules/_ctypes/_ctypes_test.c
  
      class Test6(Structure):
          _fields_ = [
              ("A", c_int, 1),
              ("B", c_int, 2),
              ("C", c_int, 3),
              ("D", c_int, 2),
          ]
  
      test6 = Test6()
      # As these are signed int fields, all are logically -1 due to sign
      # extension.
      test6.A = 1
      test6.B = 3
      test6.C = 7
      test6.D = 3
      dll = CDLL(_ctypes_test.__file__)
      with self.assertRaises(TypeError) as ctx:
          func = dll._testfunc_bitfield_by_value1
          func.restype = c_long
          func.argtypes = (Test6,)
          result = func(test6)
      self.assertEqual(
          ctx.exception.args[0],
          "item 1 in _argtypes_ passes "
          "a struct/union with a bitfield by value, which is "
          "unsupported.",
      )
      # passing by reference should be OK
      func = dll._testfunc_bitfield_by_reference1
      func.restype = c_long
      func.argtypes = (POINTER(Test6),)
      result = func(byref(test6))
      self.assertEqual(result, -4)
      self.assertEqual(test6.A, 0)
      self.assertEqual(test6.B, 0)
      self.assertEqual(test6.C, 0)
      self.assertEqual(test6.D, 0)
  
      class Test7(Structure):
          _fields_ = [
              ("A", c_uint, 1),
              ("B", c_uint, 2),
              ("C", c_uint, 3),
              ("D", c_uint, 2),
          ]
  
      test7 = Test7()
      test7.A = 1
      test7.B = 3
      test7.C = 7
      test7.D = 3
      func = dll._testfunc_bitfield_by_reference2
      func.restype = c_long
      func.argtypes = (POINTER(Test7),)
      result = func(byref(test7))
      self.assertEqual(result, 14)
      self.assertEqual(test7.A, 0)
      self.assertEqual(test7.B, 0)
      self.assertEqual(test7.C, 0)
      self.assertEqual(test7.D, 0)
  
      # for a union with bitfields, the union check happens first
      class Test8(Union):
          _fields_ = [
              ("A", c_int, 1),
              ("B", c_int, 2),
              ("C", c_int, 3),
              ("D", c_int, 2),
          ]
  
      test8 = Test8()
      with self.assertRaises(TypeError) as ctx:
          func = dll._testfunc_bitfield_by_value2
          func.restype = c_long
          func.argtypes = (Test8,)
          result = func(test8)
      self.assertEqual(
          ctx.exception.args[0],
          "item 1 in _argtypes_ passes "
          "a union by value, which is unsupported.",
      )
  
imports: import _ctypes_test
  from platform import architecture
  import struct
  import sys
  import unittest
  from ctypes import CDLL, Array, Structure, Union, POINTER, sizeof, byref, alignment, c_void_p, c_char, c_wchar, c_byte, c_ubyte, c_uint8, c_uint16, c_uint32, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double
  from ctypes.util import find_library
  from struct import calcsize
  from collections import namedtuple
  from test import support
  from ._support import _CData, PyCStructType, Py_TPFLAGS_DISALLOW_INSTANTIATION, Py_TPFLAGS_IMMUTABLETYPE
label_desc: Use image node_id 34 for calling the StructureTestCase obj's underlying member method code with example usage: obj.test_bitfield_by_value() without return types