@@ -2367,14 +2367,21 @@ MiddlingExtendsException(PyExc_NameError, UnboundLocalError, NameError,
2367
2367
* AttributeError extends Exception
2368
2368
*/
2369
2369
2370
+ static inline PyAttributeErrorObject *
2371
+ _PyAttributeError_CAST (PyObject * self )
2372
+ {
2373
+ assert (PyObject_TypeCheck (self , (PyTypeObject * )PyExc_AttributeError ));
2374
+ return (PyAttributeErrorObject * )self ;
2375
+ }
2376
+
2370
2377
static int
2371
- AttributeError_init (PyAttributeErrorObject * self , PyObject * args , PyObject * kwds )
2378
+ AttributeError_init (PyObject * op , PyObject * args , PyObject * kwds )
2372
2379
{
2373
2380
static char * kwlist [] = {"name" , "obj" , NULL };
2374
2381
PyObject * name = NULL ;
2375
2382
PyObject * obj = NULL ;
2376
2383
2377
- if (BaseException_init (( PyBaseExceptionObject * ) self , args , NULL ) == -1 ) {
2384
+ if (BaseException_init (op , args , NULL ) == -1 ) {
2378
2385
return -1 ;
2379
2386
}
2380
2387
@@ -2389,41 +2396,45 @@ AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds
2389
2396
}
2390
2397
Py_DECREF (empty_tuple );
2391
2398
2399
+ PyAttributeErrorObject * self = _PyAttributeError_CAST (op );
2392
2400
Py_XSETREF (self -> name , Py_XNewRef (name ));
2393
2401
Py_XSETREF (self -> obj , Py_XNewRef (obj ));
2394
2402
2395
2403
return 0 ;
2396
2404
}
2397
2405
2398
2406
static int
2399
- AttributeError_clear (PyAttributeErrorObject * self )
2407
+ AttributeError_clear (PyObject * op )
2400
2408
{
2409
+ PyAttributeErrorObject * self = _PyAttributeError_CAST (op );
2401
2410
Py_CLEAR (self -> obj );
2402
2411
Py_CLEAR (self -> name );
2403
- return BaseException_clear (( PyBaseExceptionObject * ) self );
2412
+ return BaseException_clear (op );
2404
2413
}
2405
2414
2406
2415
static void
2407
- AttributeError_dealloc (PyAttributeErrorObject * self )
2416
+ AttributeError_dealloc (PyObject * self )
2408
2417
{
2409
2418
_PyObject_GC_UNTRACK (self );
2410
- AttributeError_clear (self );
2411
- Py_TYPE (self )-> tp_free (( PyObject * ) self );
2419
+ ( void ) AttributeError_clear (self );
2420
+ Py_TYPE (self )-> tp_free (self );
2412
2421
}
2413
2422
2414
2423
static int
2415
- AttributeError_traverse (PyAttributeErrorObject * self , visitproc visit , void * arg )
2424
+ AttributeError_traverse (PyObject * op , visitproc visit , void * arg )
2416
2425
{
2426
+ PyAttributeErrorObject * self = _PyAttributeError_CAST (op );
2417
2427
Py_VISIT (self -> obj );
2418
2428
Py_VISIT (self -> name );
2419
- return BaseException_traverse (( PyBaseExceptionObject * ) self , visit , arg );
2429
+ return BaseException_traverse (op , visit , arg );
2420
2430
}
2421
2431
2422
2432
/* Pickling support */
2423
2433
static PyObject *
2424
- AttributeError_getstate (PyAttributeErrorObject * self , PyObject * Py_UNUSED (ignored ))
2434
+ AttributeError_getstate (PyObject * op , PyObject * Py_UNUSED (ignored ))
2425
2435
{
2426
- PyObject * dict = ((PyAttributeErrorObject * )self )-> dict ;
2436
+ PyAttributeErrorObject * self = _PyAttributeError_CAST (op );
2437
+ PyObject * dict = self -> dict ;
2427
2438
if (self -> name || self -> args ) {
2428
2439
dict = dict ? PyDict_Copy (dict ) : PyDict_New ();
2429
2440
if (dict == NULL ) {
@@ -2449,13 +2460,14 @@ AttributeError_getstate(PyAttributeErrorObject *self, PyObject *Py_UNUSED(ignore
2449
2460
}
2450
2461
2451
2462
static PyObject *
2452
- AttributeError_reduce (PyAttributeErrorObject * self , PyObject * Py_UNUSED (ignored ))
2463
+ AttributeError_reduce (PyObject * op , PyObject * Py_UNUSED (ignored ))
2453
2464
{
2454
- PyObject * state = AttributeError_getstate (self , NULL );
2465
+ PyObject * state = AttributeError_getstate (op , NULL );
2455
2466
if (state == NULL ) {
2456
2467
return NULL ;
2457
2468
}
2458
2469
2470
+ PyAttributeErrorObject * self = _PyAttributeError_CAST (op );
2459
2471
PyObject * return_value = PyTuple_Pack (3 , Py_TYPE (self ), self -> args , state );
2460
2472
Py_DECREF (state );
2461
2473
return return_value ;
@@ -2468,8 +2480,8 @@ static PyMemberDef AttributeError_members[] = {
2468
2480
};
2469
2481
2470
2482
static PyMethodDef AttributeError_methods [] = {
2471
- {"__getstate__" , ( PyCFunction ) AttributeError_getstate , METH_NOARGS },
2472
- {"__reduce__" , ( PyCFunction ) AttributeError_reduce , METH_NOARGS },
2483
+ {"__getstate__" , AttributeError_getstate , METH_NOARGS },
2484
+ {"__reduce__" , AttributeError_reduce , METH_NOARGS },
2473
2485
{NULL }
2474
2486
};
2475
2487
0 commit comments