mirror of https://github.com/python/cpython
gh-101476: Use _PyType_GetModuleState where applicable (#102188)
This commit is contained in:
parent
81bf10e4f2
commit
568fc0dee4
|
@ -79,7 +79,7 @@ abc_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = PyType_GetModuleState(type);
|
state = _PyType_GetModuleState(type);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
Py_DECREF(self);
|
Py_DECREF(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -76,7 +76,7 @@ get_asyncio_state(PyObject *mod)
|
||||||
static inline asyncio_state *
|
static inline asyncio_state *
|
||||||
get_asyncio_state_by_cls(PyTypeObject *cls)
|
get_asyncio_state_by_cls(PyTypeObject *cls)
|
||||||
{
|
{
|
||||||
asyncio_state *state = (asyncio_state *)PyType_GetModuleState(cls);
|
asyncio_state *state = (asyncio_state *)_PyType_GetModuleState(cls);
|
||||||
assert(state != NULL);
|
assert(state != NULL);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -607,7 +607,7 @@ _lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/
|
/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/
|
||||||
{
|
{
|
||||||
statscollector_t collect;
|
statscollector_t collect;
|
||||||
collect.state = PyType_GetModuleState(cls);
|
collect.state = _PyType_GetModuleState(cls);
|
||||||
if (pending_exception(self)) {
|
if (pending_exception(self)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
} else {
|
} else {
|
||||||
item = args;
|
item = args;
|
||||||
}
|
}
|
||||||
_operator_state *state = PyType_GetModuleState(type);
|
_operator_state *state = _PyType_GetModuleState(type);
|
||||||
/* create itemgetterobject structure */
|
/* create itemgetterobject structure */
|
||||||
ig = PyObject_GC_New(itemgetterobject, (PyTypeObject *) state->itemgetter_type);
|
ig = PyObject_GC_New(itemgetterobject, (PyTypeObject *) state->itemgetter_type);
|
||||||
if (ig == NULL) {
|
if (ig == NULL) {
|
||||||
|
@ -1298,7 +1298,7 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_operator_state *state = PyType_GetModuleState(type);
|
_operator_state *state = _PyType_GetModuleState(type);
|
||||||
/* create attrgetterobject structure */
|
/* create attrgetterobject structure */
|
||||||
ag = PyObject_GC_New(attrgetterobject, (PyTypeObject *)state->attrgetter_type);
|
ag = PyObject_GC_New(attrgetterobject, (PyTypeObject *)state->attrgetter_type);
|
||||||
if (ag == NULL) {
|
if (ag == NULL) {
|
||||||
|
@ -1578,7 +1578,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_operator_state *state = PyType_GetModuleState(type);
|
_operator_state *state = _PyType_GetModuleState(type);
|
||||||
/* create methodcallerobject structure */
|
/* create methodcallerobject structure */
|
||||||
mc = PyObject_GC_New(methodcallerobject, (PyTypeObject *)state->methodcaller_type);
|
mc = PyObject_GC_New(methodcallerobject, (PyTypeObject *)state->methodcaller_type);
|
||||||
if (mc == NULL) {
|
if (mc == NULL) {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_strhex.h" // _Py_strhex()
|
#include "pycore_strhex.h" // _Py_strhex()
|
||||||
|
#include "pycore_typeobject.h" // _PyType_GetModuleState()
|
||||||
#include "../hashlib.h"
|
#include "../hashlib.h"
|
||||||
|
|
||||||
#include "sha3.c"
|
#include "sha3.c"
|
||||||
|
@ -106,7 +107,7 @@ py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity)
|
||||||
{
|
{
|
||||||
HashReturn res;
|
HashReturn res;
|
||||||
Py_buffer buf = {NULL, NULL};
|
Py_buffer buf = {NULL, NULL};
|
||||||
SHA3State *state = PyType_GetModuleState(type);
|
SHA3State *state = _PyType_GetModuleState(type);
|
||||||
SHA3object *self = newSHA3object(type);
|
SHA3object *self = newSHA3object(type);
|
||||||
if (self == NULL) {
|
if (self == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -337,7 +338,7 @@ SHA3_get_name(SHA3object *self, void *closure)
|
||||||
{
|
{
|
||||||
PyTypeObject *type = Py_TYPE(self);
|
PyTypeObject *type = Py_TYPE(self);
|
||||||
|
|
||||||
SHA3State *state = PyType_GetModuleState(type);
|
SHA3State *state = _PyType_GetModuleState(type);
|
||||||
assert(state != NULL);
|
assert(state != NULL);
|
||||||
|
|
||||||
if (type == state->sha3_224_type) {
|
if (type == state->sha3_224_type) {
|
||||||
|
@ -408,7 +409,7 @@ static PyGetSetDef SHA3_getseters[] = {
|
||||||
{0,0} \
|
{0,0} \
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using PyType_GetModuleState() on these types is safe since they
|
// Using _PyType_GetModuleState() on these types is safe since they
|
||||||
// cannot be subclassed: it does not have the Py_TPFLAGS_BASETYPE flag.
|
// cannot be subclassed: it does not have the Py_TPFLAGS_BASETYPE flag.
|
||||||
#define SHA3_TYPE_SPEC(type_spec_obj, type_name, type_slots) \
|
#define SHA3_TYPE_SPEC(type_spec_obj, type_name, type_slots) \
|
||||||
static PyType_Spec type_spec_obj = { \
|
static PyType_Spec type_spec_obj = { \
|
||||||
|
|
|
@ -204,7 +204,7 @@ zoneinfo_get_state(PyObject *mod)
|
||||||
static inline zoneinfo_state *
|
static inline zoneinfo_state *
|
||||||
zoneinfo_get_state_by_cls(PyTypeObject *cls)
|
zoneinfo_get_state_by_cls(PyTypeObject *cls)
|
||||||
{
|
{
|
||||||
zoneinfo_state *state = (zoneinfo_state *)PyType_GetModuleState(cls);
|
zoneinfo_state *state = (zoneinfo_state *)_PyType_GetModuleState(cls);
|
||||||
assert(state != NULL);
|
assert(state != NULL);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "hashlib.h"
|
#include "hashlib.h"
|
||||||
#include "pycore_strhex.h" // _Py_strhex()
|
#include "pycore_strhex.h" // _Py_strhex()
|
||||||
|
#include "pycore_typeobject.h" // _PyType_GetModuleState()
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
module _md5
|
module _md5
|
||||||
|
@ -108,7 +109,7 @@ static PyObject *
|
||||||
MD5Type_copy_impl(MD5object *self, PyTypeObject *cls)
|
MD5Type_copy_impl(MD5object *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=bf055e08244bf5ee input=d89087dcfb2a8620]*/
|
/*[clinic end generated code: output=bf055e08244bf5ee input=d89087dcfb2a8620]*/
|
||||||
{
|
{
|
||||||
MD5State *st = PyType_GetModuleState(cls);
|
MD5State *st = _PyType_GetModuleState(cls);
|
||||||
|
|
||||||
MD5object *newobj;
|
MD5object *newobj;
|
||||||
if ((newobj = newMD5object(st))==NULL)
|
if ((newobj = newMD5object(st))==NULL)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "hashlib.h"
|
#include "hashlib.h"
|
||||||
#include "pycore_strhex.h" // _Py_strhex()
|
#include "pycore_strhex.h" // _Py_strhex()
|
||||||
|
#include "pycore_typeobject.h" // _PyType_GetModuleState()
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
module _sha1
|
module _sha1
|
||||||
|
@ -108,7 +109,7 @@ static PyObject *
|
||||||
SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls)
|
SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=b32d4461ce8bc7a7 input=6c22e66fcc34c58e]*/
|
/*[clinic end generated code: output=b32d4461ce8bc7a7 input=6c22e66fcc34c58e]*/
|
||||||
{
|
{
|
||||||
SHA1State *st = PyType_GetModuleState(cls);
|
SHA1State *st = _PyType_GetModuleState(cls);
|
||||||
|
|
||||||
SHA1object *newobj;
|
SHA1object *newobj;
|
||||||
if ((newobj = newSHA1object(st)) == NULL)
|
if ((newobj = newSHA1object(st)) == NULL)
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_bitutils.h" // _Py_bswap32()
|
#include "pycore_bitutils.h" // _Py_bswap32()
|
||||||
#include "pycore_moduleobject.h" // _PyModule_GetState()
|
#include "pycore_moduleobject.h" // _PyModule_GetState()
|
||||||
|
#include "pycore_typeobject.h" // _PyType_GetModuleState()
|
||||||
#include "pycore_strhex.h" // _Py_strhex()
|
#include "pycore_strhex.h" // _Py_strhex()
|
||||||
#include "structmember.h" // PyMemberDef
|
#include "structmember.h" // PyMemberDef
|
||||||
#include "hashlib.h"
|
#include "hashlib.h"
|
||||||
|
@ -217,7 +218,7 @@ SHA256Type_copy_impl(SHA256object *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=fabd515577805cd3 input=3137146fcb88e212]*/
|
/*[clinic end generated code: output=fabd515577805cd3 input=3137146fcb88e212]*/
|
||||||
{
|
{
|
||||||
SHA256object *newobj;
|
SHA256object *newobj;
|
||||||
sha2_state *state = PyType_GetModuleState(cls);
|
sha2_state *state = _PyType_GetModuleState(cls);
|
||||||
if (Py_IS_TYPE(self, state->sha256_type)) {
|
if (Py_IS_TYPE(self, state->sha256_type)) {
|
||||||
if ((newobj = newSHA256object(state)) == NULL) {
|
if ((newobj = newSHA256object(state)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -245,7 +246,7 @@ SHA512Type_copy_impl(SHA512object *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=66d2a8ef20de8302 input=f673a18f66527c90]*/
|
/*[clinic end generated code: output=66d2a8ef20de8302 input=f673a18f66527c90]*/
|
||||||
{
|
{
|
||||||
SHA512object *newobj;
|
SHA512object *newobj;
|
||||||
sha2_state *state = PyType_GetModuleState(cls);
|
sha2_state *state = _PyType_GetModuleState(cls);
|
||||||
|
|
||||||
if (Py_IS_TYPE((PyObject*)self, state->sha512_type)) {
|
if (Py_IS_TYPE((PyObject*)self, state->sha512_type)) {
|
||||||
if ((newobj = newSHA512object(state)) == NULL) {
|
if ((newobj = newSHA512object(state)) == NULL) {
|
||||||
|
@ -482,7 +483,7 @@ static PyType_Slot sha512_type_slots[] = {
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Using PyType_GetModuleState() on these types is safe since they
|
// Using _PyType_GetModuleState() on these types is safe since they
|
||||||
// cannot be subclassed: they don't have the Py_TPFLAGS_BASETYPE flag.
|
// cannot be subclassed: they don't have the Py_TPFLAGS_BASETYPE flag.
|
||||||
static PyType_Spec sha224_type_spec = {
|
static PyType_Spec sha224_type_spec = {
|
||||||
.name = "_sha2.SHA224Type",
|
.name = "_sha2.SHA224Type",
|
||||||
|
|
Loading…
Reference in New Issue