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 1
1
import unittest
2
+ import sys
2
3
from ctypes import *
3
4
4
5
class StructFieldsTestCase (unittest .TestCase ):
@@ -69,6 +70,27 @@ def __init_subclass__(cls, **kwargs):
69
70
'ctypes state is not initialized' ):
70
71
class Subclass (BrokenStructure ): ...
71
72
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
+
72
94
# __set__ and __get__ should raise a TypeError in case their self
73
95
# argument is not a ctype instance.
74
96
def test___set__ (self ):
You can’t perform that action at this time.
0 commit comments