Skip to content

Commit 9a361aa

Browse files
committed
Merge remote-tracking branch 'upstream/main' into delattr-suggestions-re
2 parents d1e38c2 + 9be3649 commit 9a361aa

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

Lib/test/test_inspect/test_inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5916,6 +5916,7 @@ def test_sysconfig_module_has_signatures(self):
59165916
def test_threading_module_has_signatures(self):
59175917
import threading
59185918
self._test_module_has_signatures(threading)
5919+
self.assertIsNotNone(inspect.signature(threading.__excepthook__))
59195920

59205921
def test_thread_module_has_signatures(self):
59215922
import _thread
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix signature of :func:`threading.excepthook`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`!_hashlib`: avoid using deprecated functions
2+
:manpage:`ERR_func_error_string` and :manpage:`EVP_MD_CTX_md` when using
3+
OpenSSL 3.0 and later. Patch by Bénédikt Tran.

Modules/_hashopenssl.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@
6464
#define PY_EVP_MD_fetch(algorithm, properties) EVP_MD_fetch(NULL, algorithm, properties)
6565
#define PY_EVP_MD_up_ref(md) EVP_MD_up_ref(md)
6666
#define PY_EVP_MD_free(md) EVP_MD_free(md)
67+
68+
#define PY_EVP_MD_CTX_md(CTX) EVP_MD_CTX_get0_md(CTX)
6769
#else
6870
#define PY_EVP_MD const EVP_MD
6971
#define PY_EVP_MD_fetch(algorithm, properties) EVP_get_digestbyname(algorithm)
7072
#define PY_EVP_MD_up_ref(md) do {} while(0)
7173
#define PY_EVP_MD_free(md) do {} while(0)
74+
75+
#define PY_EVP_MD_CTX_md(CTX) EVP_MD_CTX_md(CTX)
7276
#endif
7377

7478
/* hash alias map and fast lookup
@@ -308,6 +312,14 @@ class _hashlib.HMAC "HMACobject *" "&PyType_Type"
308312

309313
/* LCOV_EXCL_START */
310314

315+
/* Thin wrapper around ERR_reason_error_string() returning non-NULL text. */
316+
static const char *
317+
py_wrapper_ERR_reason_error_string(unsigned long errcode)
318+
{
319+
const char *reason = ERR_reason_error_string(errcode);
320+
return reason ? reason : "no reason";
321+
}
322+
311323
/* Set an exception of given type using the given OpenSSL error code. */
312324
static void
313325
set_ssl_exception_from_errcode(PyObject *exc_type, unsigned long errcode)
@@ -317,8 +329,13 @@ set_ssl_exception_from_errcode(PyObject *exc_type, unsigned long errcode)
317329

318330
/* ERR_ERROR_STRING(3) ensures that the messages below are ASCII */
319331
const char *lib = ERR_lib_error_string(errcode);
332+
#ifdef Py_HAS_OPENSSL3_SUPPORT
333+
// Since OpenSSL 3.0, ERR_func_error_string() always returns NULL.
334+
const char *func = NULL;
335+
#else
320336
const char *func = ERR_func_error_string(errcode);
321-
const char *reason = ERR_reason_error_string(errcode);
337+
#endif
338+
const char *reason = py_wrapper_ERR_reason_error_string(errcode);
322339

323340
if (lib && func) {
324341
PyErr_Format(exc_type, "[%s: %s] %s", lib, func, reason);
@@ -838,7 +855,7 @@ static PyObject *
838855
_hashlib_HASH_get_name(PyObject *op, void *Py_UNUSED(closure))
839856
{
840857
HASHobject *self = HASHobject_CAST(op);
841-
const EVP_MD *md = EVP_MD_CTX_md(self->ctx);
858+
const EVP_MD *md = PY_EVP_MD_CTX_md(self->ctx);
842859
if (md == NULL) {
843860
notify_ssl_error_occurred("missing EVP_MD for HASH context");
844861
return NULL;

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ thread_excepthook(PyObject *module, PyObject *args)
23302330
}
23312331

23322332
PyDoc_STRVAR(excepthook_doc,
2333-
"_excepthook($module, (exc_type, exc_value, exc_traceback, thread), /)\n\
2333+
"_excepthook($module, args, /)\n\
23342334
--\n\
23352335
\n\
23362336
Handle uncaught Thread.run() exception.");

0 commit comments

Comments
 (0)