@@ -124,6 +124,8 @@ typedef struct {
124
124
};
125
125
} OverlappedObject ;
126
126
127
+ #define OverlappedObject_CAST (op ) ((OverlappedObject *)(op))
128
+
127
129
128
130
static inline void
129
131
steal_buffer (Py_buffer * dst , Py_buffer * src )
@@ -666,8 +668,14 @@ _overlapped_Overlapped_impl(PyTypeObject *type, HANDLE event)
666
668
667
669
668
670
/* Note (bpo-32710): OverlappedType.tp_clear is not defined to not release
669
- buffers while overlapped are still running, to prevent a crash. */
670
- static int
671
+ * buffers while overlapped are still running, to prevent a crash.
672
+ *
673
+ * Note (gh-111178): Since OverlappedType.tp_clear is not used, we do not
674
+ * need to prevent an undefined behaviour by changing the type of 'self'.
675
+ * To avoid suppressing unused return values, we however make this function
676
+ * return nothing instead of 0, as we never use it.
677
+ */
678
+ static void
671
679
Overlapped_clear (OverlappedObject * self )
672
680
{
673
681
switch (self -> type ) {
@@ -709,16 +717,16 @@ Overlapped_clear(OverlappedObject *self)
709
717
}
710
718
}
711
719
self -> type = TYPE_NOT_STARTED ;
712
- return 0 ;
713
720
}
714
721
715
722
static void
716
- Overlapped_dealloc (OverlappedObject * self )
723
+ Overlapped_dealloc (PyObject * op )
717
724
{
718
725
DWORD bytes ;
719
726
DWORD olderr = GetLastError ();
720
727
BOOL wait = FALSE;
721
728
BOOL ret ;
729
+ OverlappedObject * self = OverlappedObject_CAST (op );
722
730
723
731
if (!HasOverlappedIoCompleted (& self -> overlapped ) &&
724
732
self -> type != TYPE_NOT_STARTED )
@@ -1642,21 +1650,24 @@ _overlapped_Overlapped_ConnectPipe_impl(OverlappedObject *self,
1642
1650
}
1643
1651
1644
1652
static PyObject *
1645
- Overlapped_getaddress (OverlappedObject * self )
1653
+ Overlapped_getaddress (PyObject * op , void * Py_UNUSED ( closure ) )
1646
1654
{
1655
+ OverlappedObject * self = OverlappedObject_CAST (op );
1647
1656
return PyLong_FromVoidPtr (& self -> overlapped );
1648
1657
}
1649
1658
1650
1659
static PyObject *
1651
- Overlapped_getpending (OverlappedObject * self )
1660
+ Overlapped_getpending (PyObject * op , void * Py_UNUSED ( closure ) )
1652
1661
{
1662
+ OverlappedObject * self = OverlappedObject_CAST (op );
1653
1663
return PyBool_FromLong (!HasOverlappedIoCompleted (& self -> overlapped ) &&
1654
1664
self -> type != TYPE_NOT_STARTED );
1655
1665
}
1656
1666
1657
1667
static int
1658
- Overlapped_traverse (OverlappedObject * self , visitproc visit , void * arg )
1668
+ Overlapped_traverse (PyObject * op , visitproc visit , void * arg )
1659
1669
{
1670
+ OverlappedObject * self = OverlappedObject_CAST (op );
1660
1671
switch (self -> type ) {
1661
1672
case TYPE_READ :
1662
1673
case TYPE_ACCEPT :
@@ -1976,9 +1987,9 @@ static PyMemberDef Overlapped_members[] = {
1976
1987
};
1977
1988
1978
1989
static PyGetSetDef Overlapped_getsets [] = {
1979
- {"address" , ( getter ) Overlapped_getaddress , NULL ,
1990
+ {"address" , Overlapped_getaddress , NULL ,
1980
1991
"Address of overlapped structure" },
1981
- {"pending" , ( getter ) Overlapped_getpending , NULL ,
1992
+ {"pending" , Overlapped_getpending , NULL ,
1982
1993
"Whether the operation is pending" },
1983
1994
{NULL },
1984
1995
};
0 commit comments