Skip to content

Commit 7af4016

Browse files
authored
Merge branch '3.12' into bp-e85f2f1703e0f79cfd0d0e3010190b71c0eb18da
2 parents 4cde360 + 7f707fa commit 7af4016

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Doc/library/string.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ conversions, trailing zeros are not removed from the result.
409409

410410
.. index:: single: , (comma); in string formatting
411411

412-
The ``','`` option signals the use of a comma for a thousands separator.
412+
The ``','`` option signals the use of a comma for a thousands separator for
413+
floating-point presentation types and for integer presentation type ``'d'``.
414+
For other presentation types, this option is an error.
413415
For a locale aware separator, use the ``'n'`` integer presentation type
414416
instead.
415417

Lib/test/test_ctypes/test_struct_fields.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import sys
23
from ctypes import *
34

45
class 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):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In :mod:`ssl`, system call failures that OpenSSL reports using
2+
``ERR_LIB_SYS`` are now raised as :exc:`OSError`.

Modules/_ssl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno)
651651
ERR_GET_REASON(e) == SSL_R_CERTIFICATE_VERIFY_FAILED) {
652652
type = state->PySSLCertVerificationErrorObject;
653653
}
654+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
655+
// A system error is being reported; reason is set to errno
656+
errno = ERR_GET_REASON(e);
657+
return PyErr_SetFromErrno(PyExc_OSError);
658+
}
654659
p = PY_SSL_ERROR_SYSCALL;
655660
}
656661
break;
@@ -676,6 +681,11 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno)
676681
errstr = "EOF occurred in violation of protocol";
677682
}
678683
#endif
684+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
685+
// A system error is being reported; reason is set to errno
686+
errno = ERR_GET_REASON(e);
687+
return PyErr_SetFromErrno(PyExc_OSError);
688+
}
679689
break;
680690
}
681691
default:

0 commit comments

Comments
 (0)