New submission from STINNER Victor <vstin...@python.org>:

In Modules/_hashopenssl.c:PyInit__hashlib(), PyModule_AddObject() can be 
replaced with PyModule_AddType() to add the 3 types: this function does the 
Py_INCREF for us, which reduces errors if the function fails.

The results of other PyModule_AddObject() calls should also be checked to 
handle errors.

The following _hashlibstate_global macro is no longer used:

#define _hashlibstate_global ((_hashlibstate 
*)PyModule_GetState(PyState_FindModule(&_hashlibmodule)))

EVPnew() got a module parameter, so it doesn't need _hashlibstate_global 
anymore.

Dong-hee, Hai: Maybe it's time to convert this module to PEP 489 multiphase 
initialization?

Hai: do you want to work on a PR?

--

Question: do EVPobject and HMACobject rely on a global state somewhere in 
OpenSSL? Or is it safe to use them in subinterpreters, with multiple instances 
of _hashlib?

EVPobject and HMACobject have "lock" member.

Even if converting the module to PEP 489 is not enough to make it compatible 
with subinterpreters (I don't know, maybe it's enought, see my question), it 
should help for that :-)

Note: the current code is already quite clean, I like it :-)

cc Petr & Christian.

----------
components: Library (Lib)
messages: 369211
nosy: christian.heimes, corona10, petr.viktorin, shihai1991, vstinner
priority: normal
severity: normal
status: open
title: Convert _hashlib to PEP 489 multiphase initialization
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40671>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to