gh-94401: Remove unneeded overlapped module state (#94403)

This commit is contained in:
Erlend Egeberg Aasland 2022-06-29 12:24:51 +02:00 committed by GitHub
parent 595baa4e06
commit 655b3aa4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 43 deletions

View File

@ -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