Skip to content

Commit 568fc0d

Browse files
gh-101476: Use _PyType_GetModuleState where applicable (#102188)
1 parent 81bf10e commit 568fc0d

File tree

9 files changed

+19
-15
lines changed

9 files changed

+19
-15
lines changed

Modules/_abc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ abc_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
7979
return NULL;
8080
}
8181

82-
state = PyType_GetModuleState(type);
82+
state = _PyType_GetModuleState(type);
8383
if (state == NULL) {
8484
Py_DECREF(self);
8585
return NULL;

Modules/_asynciomodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ get_asyncio_state(PyObject *mod)
7676
static inline asyncio_state *
7777
get_asyncio_state_by_cls(PyTypeObject *cls)
7878
{
79-
asyncio_state *state = (asyncio_state *)PyType_GetModuleState(cls);
79+
asyncio_state *state = (asyncio_state *)_PyType_GetModuleState(cls);
8080
assert(state != NULL);
8181
return state;
8282
}

Modules/_lsprof.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ _lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls)
607607
/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/
608608
{
609609
statscollector_t collect;
610-
collect.state = PyType_GetModuleState(cls);
610+
collect.state = _PyType_GetModuleState(cls);
611611
if (pending_exception(self)) {
612612
return NULL;
613613
}

Modules/_operator.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10021002
} else {
10031003
item = args;
10041004
}
1005-
_operator_state *state = PyType_GetModuleState(type);
1005+
_operator_state *state = _PyType_GetModuleState(type);
10061006
/* create itemgetterobject structure */
10071007
ig = PyObject_GC_New(itemgetterobject, (PyTypeObject *) state->itemgetter_type);
10081008
if (ig == NULL) {
@@ -1298,7 +1298,7 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12981298
}
12991299
}
13001300

1301-
_operator_state *state = PyType_GetModuleState(type);
1301+
_operator_state *state = _PyType_GetModuleState(type);
13021302
/* create attrgetterobject structure */
13031303
ag = PyObject_GC_New(attrgetterobject, (PyTypeObject *)state->attrgetter_type);
13041304
if (ag == NULL) {
@@ -1578,7 +1578,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
15781578
return NULL;
15791579
}
15801580

1581-
_operator_state *state = PyType_GetModuleState(type);
1581+
_operator_state *state = _PyType_GetModuleState(type);
15821582
/* create methodcallerobject structure */
15831583
mc = PyObject_GC_New(methodcallerobject, (PyTypeObject *)state->methodcaller_type);
15841584
if (mc == NULL) {

Modules/_sha3/sha3module.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "Python.h"
2323
#include "pycore_strhex.h" // _Py_strhex()
24+
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2425
#include "../hashlib.h"
2526

2627
#include "sha3.c"
@@ -106,7 +107,7 @@ py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity)
106107
{
107108
HashReturn res;
108109
Py_buffer buf = {NULL, NULL};
109-
SHA3State *state = PyType_GetModuleState(type);
110+
SHA3State *state = _PyType_GetModuleState(type);
110111
SHA3object *self = newSHA3object(type);
111112
if (self == NULL) {
112113
goto error;
@@ -337,7 +338,7 @@ SHA3_get_name(SHA3object *self, void *closure)
337338
{
338339
PyTypeObject *type = Py_TYPE(self);
339340

340-
SHA3State *state = PyType_GetModuleState(type);
341+
SHA3State *state = _PyType_GetModuleState(type);
341342
assert(state != NULL);
342343

343344
if (type == state->sha3_224_type) {
@@ -408,7 +409,7 @@ static PyGetSetDef SHA3_getseters[] = {
408409
{0,0} \
409410
}
410411

411-
// Using PyType_GetModuleState() on these types is safe since they
412+
// Using _PyType_GetModuleState() on these types is safe since they
412413
// cannot be subclassed: it does not have the Py_TPFLAGS_BASETYPE flag.
413414
#define SHA3_TYPE_SPEC(type_spec_obj, type_name, type_slots) \
414415
static PyType_Spec type_spec_obj = { \

Modules/_zoneinfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ zoneinfo_get_state(PyObject *mod)
204204
static inline zoneinfo_state *
205205
zoneinfo_get_state_by_cls(PyTypeObject *cls)
206206
{
207-
zoneinfo_state *state = (zoneinfo_state *)PyType_GetModuleState(cls);
207+
zoneinfo_state *state = (zoneinfo_state *)_PyType_GetModuleState(cls);
208208
assert(state != NULL);
209209
return state;
210210
}

Modules/md5module.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Python.h"
2323
#include "hashlib.h"
2424
#include "pycore_strhex.h" // _Py_strhex()
25+
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2526

2627
/*[clinic input]
2728
module _md5
@@ -108,7 +109,7 @@ static PyObject *
108109
MD5Type_copy_impl(MD5object *self, PyTypeObject *cls)
109110
/*[clinic end generated code: output=bf055e08244bf5ee input=d89087dcfb2a8620]*/
110111
{
111-
MD5State *st = PyType_GetModuleState(cls);
112+
MD5State *st = _PyType_GetModuleState(cls);
112113

113114
MD5object *newobj;
114115
if ((newobj = newMD5object(st))==NULL)

Modules/sha1module.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Python.h"
2323
#include "hashlib.h"
2424
#include "pycore_strhex.h" // _Py_strhex()
25+
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2526

2627
/*[clinic input]
2728
module _sha1
@@ -108,7 +109,7 @@ static PyObject *
108109
SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls)
109110
/*[clinic end generated code: output=b32d4461ce8bc7a7 input=6c22e66fcc34c58e]*/
110111
{
111-
SHA1State *st = PyType_GetModuleState(cls);
112+
SHA1State *st = _PyType_GetModuleState(cls);
112113

113114
SHA1object *newobj;
114115
if ((newobj = newSHA1object(st)) == NULL)

Modules/sha2module.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Python.h"
2424
#include "pycore_bitutils.h" // _Py_bswap32()
2525
#include "pycore_moduleobject.h" // _PyModule_GetState()
26+
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2627
#include "pycore_strhex.h" // _Py_strhex()
2728
#include "structmember.h" // PyMemberDef
2829
#include "hashlib.h"
@@ -217,7 +218,7 @@ SHA256Type_copy_impl(SHA256object *self, PyTypeObject *cls)
217218
/*[clinic end generated code: output=fabd515577805cd3 input=3137146fcb88e212]*/
218219
{
219220
SHA256object *newobj;
220-
sha2_state *state = PyType_GetModuleState(cls);
221+
sha2_state *state = _PyType_GetModuleState(cls);
221222
if (Py_IS_TYPE(self, state->sha256_type)) {
222223
if ((newobj = newSHA256object(state)) == NULL) {
223224
return NULL;
@@ -245,7 +246,7 @@ SHA512Type_copy_impl(SHA512object *self, PyTypeObject *cls)
245246
/*[clinic end generated code: output=66d2a8ef20de8302 input=f673a18f66527c90]*/
246247
{
247248
SHA512object *newobj;
248-
sha2_state *state = PyType_GetModuleState(cls);
249+
sha2_state *state = _PyType_GetModuleState(cls);
249250

250251
if (Py_IS_TYPE((PyObject*)self, state->sha512_type)) {
251252
if ((newobj = newSHA512object(state)) == NULL) {
@@ -482,7 +483,7 @@ static PyType_Slot sha512_type_slots[] = {
482483
{0,0}
483484
};
484485

485-
// Using PyType_GetModuleState() on these types is safe since they
486+
// Using _PyType_GetModuleState() on these types is safe since they
486487
// cannot be subclassed: they don't have the Py_TPFLAGS_BASETYPE flag.
487488
static PyType_Spec sha224_type_spec = {
488489
.name = "_sha2.SHA224Type",

0 commit comments

Comments
 (0)