@@ -1705,7 +1705,7 @@ ImportError_getstate(PyObject *op)
1705
1705
1706
1706
/* Pickling support */
1707
1707
static PyObject *
1708
- ImportError_reduce (PyObject * self , PyObject * Py_UNUSED (igno + red ))
1708
+ ImportError_reduce (PyObject * self , PyObject * Py_UNUSED (ignored ))
1709
1709
{
1710
1710
PyObject * res ;
1711
1711
PyObject * state = ImportError_getstate (self );
@@ -1755,6 +1755,13 @@ MiddlingExtendsException(PyExc_ImportError, ModuleNotFoundError, ImportError,
1755
1755
* OSError extends Exception
1756
1756
*/
1757
1757
1758
+ static inline PyOSErrorObject *
1759
+ _PyOSError_CAST (PyObject * self )
1760
+ {
1761
+ assert (PyObject_TypeCheck (self , (PyTypeObject * )PyExc_OSError ));
1762
+ return (PyOSErrorObject * )self ;
1763
+ }
1764
+
1758
1765
#ifdef MS_WINDOWS
1759
1766
#include "errmap.h"
1760
1767
#endif
@@ -1891,7 +1898,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
1891
1898
static PyObject *
1892
1899
OSError_new (PyTypeObject * type , PyObject * args , PyObject * kwds );
1893
1900
static int
1894
- OSError_init (PyOSErrorObject * self , PyObject * args , PyObject * kwds );
1901
+ OSError_init (PyObject * self , PyObject * args , PyObject * kwds );
1895
1902
1896
1903
static int
1897
1904
oserror_use_init (PyTypeObject * type )
@@ -1983,8 +1990,9 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1983
1990
}
1984
1991
1985
1992
static int
1986
- OSError_init (PyOSErrorObject * self , PyObject * args , PyObject * kwds )
1993
+ OSError_init (PyObject * op , PyObject * args , PyObject * kwds )
1987
1994
{
1995
+ PyOSErrorObject * self = _PyOSError_CAST (op );
1988
1996
PyObject * myerrno = NULL , * strerror = NULL ;
1989
1997
PyObject * filename = NULL , * filename2 = NULL ;
1990
1998
#ifdef MS_WINDOWS
@@ -2021,43 +2029,45 @@ OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds)
2021
2029
}
2022
2030
2023
2031
static int
2024
- OSError_clear (PyOSErrorObject * self )
2032
+ OSError_clear (PyObject * op )
2025
2033
{
2034
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2026
2035
Py_CLEAR (self -> myerrno );
2027
2036
Py_CLEAR (self -> strerror );
2028
2037
Py_CLEAR (self -> filename );
2029
2038
Py_CLEAR (self -> filename2 );
2030
2039
#ifdef MS_WINDOWS
2031
2040
Py_CLEAR (self -> winerror );
2032
2041
#endif
2033
- return BaseException_clear (( PyBaseExceptionObject * ) self );
2042
+ return BaseException_clear (op );
2034
2043
}
2035
2044
2036
2045
static void
2037
- OSError_dealloc (PyOSErrorObject * self )
2046
+ OSError_dealloc (PyObject * self )
2038
2047
{
2039
2048
_PyObject_GC_UNTRACK (self );
2040
- OSError_clear (self );
2041
- Py_TYPE (self )-> tp_free (( PyObject * ) self );
2049
+ ( void ) OSError_clear (self );
2050
+ Py_TYPE (self )-> tp_free (self );
2042
2051
}
2043
2052
2044
2053
static int
2045
- OSError_traverse (PyOSErrorObject * self , visitproc visit ,
2046
- void * arg )
2054
+ OSError_traverse (PyObject * op , visitproc visit , void * arg )
2047
2055
{
2056
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2048
2057
Py_VISIT (self -> myerrno );
2049
2058
Py_VISIT (self -> strerror );
2050
2059
Py_VISIT (self -> filename );
2051
2060
Py_VISIT (self -> filename2 );
2052
2061
#ifdef MS_WINDOWS
2053
2062
Py_VISIT (self -> winerror );
2054
2063
#endif
2055
- return BaseException_traverse (( PyBaseExceptionObject * ) self , visit , arg );
2064
+ return BaseException_traverse (op , visit , arg );
2056
2065
}
2057
2066
2058
2067
static PyObject *
2059
- OSError_str (PyOSErrorObject * self )
2068
+ OSError_str (PyObject * op )
2060
2069
{
2070
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2061
2071
#define OR_NONE (x ) ((x)?(x):Py_None)
2062
2072
#ifdef MS_WINDOWS
2063
2073
/* If available, winerror has the priority over myerrno */
@@ -2097,12 +2107,13 @@ OSError_str(PyOSErrorObject *self)
2097
2107
if (self -> myerrno && self -> strerror )
2098
2108
return PyUnicode_FromFormat ("[Errno %S] %S" ,
2099
2109
self -> myerrno , self -> strerror );
2100
- return BaseException_str (( PyBaseExceptionObject * ) self );
2110
+ return BaseException_str (op );
2101
2111
}
2102
2112
2103
2113
static PyObject *
2104
- OSError_reduce (PyOSErrorObject * self , PyObject * Py_UNUSED (ignored ))
2114
+ OSError_reduce (PyObject * op , PyObject * Py_UNUSED (ignored ))
2105
2115
{
2116
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2106
2117
PyObject * args = self -> args ;
2107
2118
PyObject * res = NULL ;
2108
2119
@@ -2141,8 +2152,9 @@ OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored))
2141
2152
}
2142
2153
2143
2154
static PyObject *
2144
- OSError_written_get (PyOSErrorObject * self , void * context )
2155
+ OSError_written_get (PyObject * op , void * context )
2145
2156
{
2157
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2146
2158
if (self -> written == -1 ) {
2147
2159
PyErr_SetString (PyExc_AttributeError , "characters_written" );
2148
2160
return NULL ;
@@ -2151,8 +2163,9 @@ OSError_written_get(PyOSErrorObject *self, void *context)
2151
2163
}
2152
2164
2153
2165
static int
2154
- OSError_written_set (PyOSErrorObject * self , PyObject * arg , void * context )
2166
+ OSError_written_set (PyObject * op , PyObject * arg , void * context )
2155
2167
{
2168
+ PyOSErrorObject * self = _PyOSError_CAST (op );
2156
2169
if (arg == NULL ) {
2157
2170
if (self -> written == -1 ) {
2158
2171
PyErr_SetString (PyExc_AttributeError , "characters_written" );
@@ -2186,13 +2199,13 @@ static PyMemberDef OSError_members[] = {
2186
2199
};
2187
2200
2188
2201
static PyMethodDef OSError_methods [] = {
2189
- {"__reduce__" , ( PyCFunction ) OSError_reduce , METH_NOARGS },
2202
+ {"__reduce__" , OSError_reduce , METH_NOARGS },
2190
2203
{NULL }
2191
2204
};
2192
2205
2193
2206
static PyGetSetDef OSError_getset [] = {
2194
- {"characters_written" , ( getter ) OSError_written_get ,
2195
- ( setter ) OSError_written_set , NULL },
2207
+ {"characters_written" , OSError_written_get ,
2208
+ OSError_written_set , NULL },
2196
2209
{NULL }
2197
2210
};
2198
2211
0 commit comments