From 655b3aa4c8889a46e44b449cec16c85704a5e274 Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Wed, 29 Jun 2022 12:24:51 +0200 Subject: [PATCH] gh-94401: Remove unneeded overlapped module state (#94403) --- Modules/overlapped.c | 49 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 43 deletions(-) diff --git a/Modules/overlapped.c b/Modules/overlapped.c index e40a52476bd..19d25a53af7 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -105,18 +105,6 @@ typedef struct { }; } OverlappedObject; -typedef struct { - PyTypeObject *overlapped_type; -} OverlappedState; - -static inline OverlappedState* -overlapped_get_state(PyObject *module) -{ - void *state = PyModule_GetState(module); - assert(state != NULL); - return (OverlappedState *)state; -} - static inline void steal_buffer(Py_buffer * dst, Py_buffer * src) @@ -1996,28 +1984,6 @@ static PyMethodDef overlapped_functions[] = { {NULL} }; -static int -overlapped_traverse(PyObject *module, visitproc visit, void *arg) -{ - OverlappedState *state = overlapped_get_state(module); - Py_VISIT(state->overlapped_type); - return 0; -} - -static int -overlapped_clear(PyObject *module) -{ - OverlappedState *state = overlapped_get_state(module); - Py_CLEAR(state->overlapped_type); - return 0; -} - -static void -overlapped_free(void *module) -{ - overlapped_clear((PyObject *)module); -} - #define WINAPI_CONSTANT(fmt, con) \ do { \ PyObject *value = Py_BuildValue(fmt, con); \ @@ -2045,14 +2011,15 @@ overlapped_exec(PyObject *module) return -1; } - OverlappedState *st = overlapped_get_state(module); - st->overlapped_type = (PyTypeObject *)PyType_FromModuleAndSpec( + PyTypeObject *overlapped_type = (PyTypeObject *)PyType_FromModuleAndSpec( module, &overlapped_type_spec, NULL); - if (st->overlapped_type == NULL) { + if (overlapped_type == NULL) { return -1; } - if (PyModule_AddType(module, st->overlapped_type) < 0) { + int rc = PyModule_AddType(module, overlapped_type); + Py_DECREF(overlapped_type); + if (rc < 0) { return -1; } @@ -2077,14 +2044,10 @@ static PyModuleDef_Slot overlapped_slots[] = { }; static struct PyModuleDef overlapped_module = { - PyModuleDef_HEAD_INIT, + .m_base = PyModuleDef_HEAD_INIT, .m_name = "_overlapped", - .m_size = sizeof(OverlappedState), .m_methods = overlapped_functions, .m_slots = overlapped_slots, - .m_traverse = overlapped_traverse, - .m_clear = overlapped_clear, - .m_free = overlapped_free }; PyMODINIT_FUNC