mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
[3.12] gh-126937: ctypes: add test for maximum size of a struct field (GH-126938) (GH-127825) (GH-127909)
This backports the *test* from GH-126938, with changed limit and exception class.
Co-authored-by: Melissa0x1f992 <70096546+Melissa0x1f992@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
(cherry-picked from d51c1444e3)
This commit is contained in:
parent
58916eb211
commit
d0368556b5
1 changed files with 22 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
import sys
|
||||
from ctypes import *
|
||||
|
||||
class StructFieldsTestCase(unittest.TestCase):
|
||||
|
|
@ -69,6 +70,27 @@ def __init_subclass__(cls, **kwargs):
|
|||
'ctypes state is not initialized'):
|
||||
class Subclass(BrokenStructure): ...
|
||||
|
||||
def test_max_field_size_gh126937(self):
|
||||
# Classes for big structs should be created successfully.
|
||||
# (But they most likely can't be instantiated.)
|
||||
# The size must fit in Py_ssize_t.
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [('char', c_char),]
|
||||
max_field_size = sys.maxsize
|
||||
|
||||
class Y(Structure):
|
||||
_fields_ = [('largeField', X * max_field_size)]
|
||||
class Z(Structure):
|
||||
_fields_ = [('largeField', c_char * max_field_size)]
|
||||
|
||||
with self.assertRaises(OverflowError):
|
||||
class TooBig(Structure):
|
||||
_fields_ = [('largeField', X * (max_field_size + 1))]
|
||||
with self.assertRaises(OverflowError):
|
||||
class TooBig(Structure):
|
||||
_fields_ = [('largeField', c_char * (max_field_size + 1))]
|
||||
|
||||
# __set__ and __get__ should raise a TypeError in case their self
|
||||
# argument is not a ctype instance.
|
||||
def test___set__(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue