File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 11import unittest
2+ import sys
23from ctypes import *
34
45class StructFieldsTestCase (unittest .TestCase ):
@@ -69,6 +70,27 @@ def __init_subclass__(cls, **kwargs):
6970 'ctypes state is not initialized' ):
7071 class Subclass (BrokenStructure ): ...
7172
73+ def test_max_field_size_gh126937 (self ):
74+ # Classes for big structs should be created successfully.
75+ # (But they most likely can't be instantiated.)
76+ # The size must fit in Py_ssize_t.
77+
78+ class X (Structure ):
79+ _fields_ = [('char' , c_char ),]
80+ max_field_size = sys .maxsize
81+
82+ class Y (Structure ):
83+ _fields_ = [('largeField' , X * max_field_size )]
84+ class Z (Structure ):
85+ _fields_ = [('largeField' , c_char * max_field_size )]
86+
87+ with self .assertRaises (OverflowError ):
88+ class TooBig (Structure ):
89+ _fields_ = [('largeField' , X * (max_field_size + 1 ))]
90+ with self .assertRaises (OverflowError ):
91+ class TooBig (Structure ):
92+ _fields_ = [('largeField' , c_char * (max_field_size + 1 ))]
93+
7294 # __set__ and __get__ should raise a TypeError in case their self
7395 # argument is not a ctype instance.
7496 def test___set__ (self ):
You can’t perform that action at this time.
0 commit comments