return (PyObject *)self;
}
+
+/* Note (bpo-32710): OverlappedType.tp_clear is not defined to not release
+ buffers while overlapped are still running, to prevent a crash. */
+static int
+Overlapped_clear(OverlappedObject *self)
+{
+ switch (self->type) {
+ case TYPE_READ:
+ case TYPE_ACCEPT:
+ Py_CLEAR(self->allocated_buffer);
+ break;
+ case TYPE_WRITE:
+ case TYPE_READINTO:
+ if (self->user_buffer.obj) {
+ PyBuffer_Release(&self->user_buffer);
+ }
+ break;
+ }
+ self->type = TYPE_NOT_STARTED;
+ return 0;
+}
+
static void
Overlapped_dealloc(OverlappedObject *self)
{
}
}
- if (self->overlapped.hEvent != NULL)
+ if (self->overlapped.hEvent != NULL) {
CloseHandle(self->overlapped.hEvent);
-
- switch (self->type) {
- case TYPE_READ:
- case TYPE_ACCEPT:
- Py_CLEAR(self->allocated_buffer);
- break;
- case TYPE_WRITE:
- case TYPE_READINTO:
- if (self->user_buffer.obj)
- PyBuffer_Release(&self->user_buffer);
- break;
}
+
+ Overlapped_clear(self);
PyObject_Del(self);
SetLastError(olderr);
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- PyBuffer_Release(&self->user_buffer);
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- PyBuffer_Release(&self->user_buffer);
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
case ERROR_IO_PENDING:
Py_RETURN_FALSE;
default:
- self->type = TYPE_NOT_STARTED;
+ Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
self->type != TYPE_NOT_STARTED);
}
+static int
+Overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg)
+{
+ switch (self->type) {
+ case TYPE_READ:
+ case TYPE_ACCEPT:
+ Py_VISIT(self->allocated_buffer);
+ break;
+ case TYPE_WRITE:
+ case TYPE_READINTO:
+ if (self->user_buffer.obj) {
+ Py_VISIT(&self->user_buffer.obj);
+ }
+ break;
+ }
+ return 0;
+}
+
+
static PyMethodDef Overlapped_methods[] = {
{"getresult", (PyCFunction) Overlapped_getresult,
METH_VARARGS, Overlapped_getresult_doc},
/* tp_as_buffer */ 0,
/* tp_flags */ Py_TPFLAGS_DEFAULT,
/* tp_doc */ "OVERLAPPED structure wrapper",
- /* tp_traverse */ 0,
+ /* tp_traverse */ (traverseproc)Overlapped_traverse,
/* tp_clear */ 0,
/* tp_richcompare */ 0,
/* tp_weaklistoffset */ 0,