Skip to content

Commit 7d3bb10

Browse files
committed
Test maximum field size (sys.maxsize / 8, so we can count bits later)
1 parent 5e8aec0 commit 7d3bb10

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_ctypes/test_struct_fields.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import sys
23
from ctypes import Structure, Union, sizeof, c_char, c_int
34
from ._support import (CField, Py_TPFLAGS_DISALLOW_INSTANTIATION,
45
Py_TPFLAGS_IMMUTABLETYPE)
@@ -78,9 +79,12 @@ class Subclass(BrokenStructure): ...
7879
def test_gh126937(self):
7980
class X(self.cls):
8081
_fields_ = [('char', c_char),]
82+
max_field_size = sys.maxsize // 8
8183
class Y(self.cls):
82-
# (2^31 - 1) is the largest size that can fit into a signed 32 bit int
83-
_fields_ = [('largeField', X * (2 ** 31 - 1))]
84+
_fields_ = [('largeField', X * max_field_size)]
85+
with self.assertRaises(ValueError):
86+
class TooBig(self.cls):
87+
_fields_ = [('largeField', X * (max_field_size + 1))]
8488

8589
# __set__ and __get__ should raise a TypeError in case their self
8690
# argument is not a ctype instance.

0 commit comments

Comments
 (0)