@@ -53,8 +53,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
53
53
self -> suppress_context = 0 ;
54
54
55
55
if (args ) {
56
- self -> args = args ;
57
- Py_INCREF (args );
56
+ self -> args = Py_NewRef (args );
58
57
return (PyObject * )self ;
59
58
}
60
59
@@ -73,9 +72,7 @@ BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
73
72
if (!_PyArg_NoKeywords (Py_TYPE (self )-> tp_name , kwds ))
74
73
return -1 ;
75
74
76
- Py_INCREF (args );
77
- Py_XSETREF (self -> args , args );
78
-
75
+ Py_XSETREF (self -> args , Py_NewRef (args ));
79
76
return 0 ;
80
77
}
81
78
@@ -185,8 +182,7 @@ BaseException_with_traceback(PyObject *self, PyObject *tb) {
185
182
if (PyException_SetTraceback (self , tb ))
186
183
return NULL ;
187
184
188
- Py_INCREF (self );
189
- return self ;
185
+ return Py_NewRef (self );
190
186
}
191
187
192
188
PyDoc_STRVAR (with_traceback_doc ,
@@ -258,8 +254,7 @@ BaseException_get_args(PyBaseExceptionObject *self, void *Py_UNUSED(ignored))
258
254
if (self -> args == NULL ) {
259
255
Py_RETURN_NONE ;
260
256
}
261
- Py_INCREF (self -> args );
262
- return self -> args ;
257
+ return Py_NewRef (self -> args );
263
258
}
264
259
265
260
static int
@@ -283,8 +278,7 @@ BaseException_get_tb(PyBaseExceptionObject *self, void *Py_UNUSED(ignored))
283
278
if (self -> traceback == NULL ) {
284
279
Py_RETURN_NONE ;
285
280
}
286
- Py_INCREF (self -> traceback );
287
- return self -> traceback ;
281
+ return Py_NewRef (self -> traceback );
288
282
}
289
283
290
284
static int
@@ -300,8 +294,7 @@ BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb, void *Py_UNUSED(
300
294
return -1 ;
301
295
}
302
296
303
- Py_INCREF (tb );
304
- Py_XSETREF (self -> traceback , tb );
297
+ Py_XSETREF (self -> traceback , Py_NewRef (tb ));
305
298
return 0 ;
306
299
}
307
300
@@ -380,8 +373,7 @@ PyObject *
380
373
PyException_GetTraceback (PyObject * self )
381
374
{
382
375
PyBaseExceptionObject * base_self = _PyBaseExceptionObject_cast (self );
383
- Py_XINCREF (base_self -> traceback );
384
- return base_self -> traceback ;
376
+ return Py_XNewRef (base_self -> traceback );
385
377
}
386
378
387
379
@@ -395,8 +387,7 @@ PyObject *
395
387
PyException_GetCause (PyObject * self )
396
388
{
397
389
PyObject * cause = _PyBaseExceptionObject_cast (self )-> cause ;
398
- Py_XINCREF (cause );
399
- return cause ;
390
+ return Py_XNewRef (cause );
400
391
}
401
392
402
393
/* Steals a reference to cause */
@@ -412,8 +403,7 @@ PyObject *
412
403
PyException_GetContext (PyObject * self )
413
404
{
414
405
PyObject * context = _PyBaseExceptionObject_cast (self )-> context ;
415
- Py_XINCREF (context );
416
- return context ;
406
+ return Py_XNewRef (context );
417
407
}
418
408
419
409
/* Steals a reference to context */
@@ -579,8 +569,7 @@ StopIteration_init(PyStopIterationObject *self, PyObject *args, PyObject *kwds)
579
569
value = PyTuple_GET_ITEM (args , 0 );
580
570
else
581
571
value = Py_None ;
582
- Py_INCREF (value );
583
- self -> value = value ;
572
+ self -> value = Py_NewRef (value );
584
573
return 0 ;
585
574
}
586
575
@@ -633,12 +622,10 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
633
622
if (size == 0 )
634
623
return 0 ;
635
624
if (size == 1 ) {
636
- Py_INCREF (PyTuple_GET_ITEM (args , 0 ));
637
- Py_XSETREF (self -> code , PyTuple_GET_ITEM (args , 0 ));
625
+ Py_XSETREF (self -> code , Py_NewRef (PyTuple_GET_ITEM (args , 0 )));
638
626
}
639
627
else { /* size > 1 */
640
- Py_INCREF (args );
641
- Py_XSETREF (self -> code , args );
628
+ Py_XSETREF (self -> code , Py_NewRef (args ));
642
629
}
643
630
return 0 ;
644
631
}
@@ -1493,18 +1480,12 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
1493
1480
}
1494
1481
Py_DECREF (empty_tuple );
1495
1482
1496
- Py_XINCREF (name );
1497
- Py_XSETREF (self -> name , name );
1498
-
1499
- Py_XINCREF (path );
1500
- Py_XSETREF (self -> path , path );
1501
-
1502
- Py_XINCREF (name_from );
1503
- Py_XSETREF (self -> name_from , name_from );
1483
+ Py_XSETREF (self -> name , Py_XNewRef (name ));
1484
+ Py_XSETREF (self -> path , Py_XNewRef (path ));
1485
+ Py_XSETREF (self -> name_from , Py_XNewRef (name_from ));
1504
1486
1505
1487
if (PyTuple_GET_SIZE (args ) == 1 ) {
1506
- msg = PyTuple_GET_ITEM (args , 0 );
1507
- Py_INCREF (msg );
1488
+ msg = Py_NewRef (PyTuple_GET_ITEM (args , 0 ));
1508
1489
}
1509
1490
Py_XSETREF (self -> msg , msg );
1510
1491
@@ -1543,8 +1524,7 @@ static PyObject *
1543
1524
ImportError_str (PyImportErrorObject * self )
1544
1525
{
1545
1526
if (self -> msg && PyUnicode_CheckExact (self -> msg )) {
1546
- Py_INCREF (self -> msg );
1547
- return self -> msg ;
1527
+ return Py_NewRef (self -> msg );
1548
1528
}
1549
1529
else {
1550
1530
return BaseException_str ((PyBaseExceptionObject * )self );
@@ -1574,8 +1554,7 @@ ImportError_getstate(PyImportErrorObject *self)
1574
1554
return dict ;
1575
1555
}
1576
1556
else if (dict ) {
1577
- Py_INCREF (dict );
1578
- return dict ;
1557
+ return Py_NewRef (dict );
1579
1558
}
1580
1559
else {
1581
1560
Py_RETURN_NONE ;
@@ -1702,8 +1681,7 @@ oserror_parse_args(PyObject **p_args,
1702
1681
PyTuple_SET_ITEM (newargs , 0 , * myerrno );
1703
1682
for (i = 1 ; i < nargs ; i ++ ) {
1704
1683
PyObject * val = PyTuple_GET_ITEM (args , i );
1705
- Py_INCREF (val );
1706
- PyTuple_SET_ITEM (newargs , i , val );
1684
+ PyTuple_SET_ITEM (newargs , i , Py_NewRef (val ));
1707
1685
}
1708
1686
Py_DECREF (args );
1709
1687
args = * p_args = newargs ;
@@ -1738,12 +1716,10 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
1738
1716
return -1 ;
1739
1717
}
1740
1718
else {
1741
- Py_INCREF (filename );
1742
- self -> filename = filename ;
1719
+ self -> filename = Py_NewRef (filename );
1743
1720
1744
1721
if (filename2 && filename2 != Py_None ) {
1745
- Py_INCREF (filename2 );
1746
- self -> filename2 = filename2 ;
1722
+ self -> filename2 = Py_NewRef (filename2 );
1747
1723
}
1748
1724
1749
1725
if (nargs >= 2 && nargs <= 5 ) {
@@ -1758,15 +1734,10 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
1758
1734
}
1759
1735
}
1760
1736
}
1761
- Py_XINCREF (myerrno );
1762
- self -> myerrno = myerrno ;
1763
-
1764
- Py_XINCREF (strerror );
1765
- self -> strerror = strerror ;
1766
-
1737
+ self -> myerrno = Py_XNewRef (myerrno );
1738
+ self -> strerror = Py_XNewRef (strerror );
1767
1739
#ifdef MS_WINDOWS
1768
- Py_XINCREF (winerror );
1769
- self -> winerror = winerror ;
1740
+ self -> winerror = Py_XNewRef (winerror );
1770
1741
#endif
1771
1742
1772
1743
/* Steals the reference to args */
@@ -1992,7 +1963,7 @@ static PyObject *
1992
1963
OSError_reduce (PyOSErrorObject * self , PyObject * Py_UNUSED (ignored ))
1993
1964
{
1994
1965
PyObject * args = self -> args ;
1995
- PyObject * res = NULL , * tmp ;
1966
+ PyObject * res = NULL ;
1996
1967
1997
1968
/* self->args is only the first two real arguments if there was a
1998
1969
* file name given to OSError. */
@@ -2002,29 +1973,20 @@ OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored))
2002
1973
if (!args )
2003
1974
return NULL ;
2004
1975
2005
- tmp = PyTuple_GET_ITEM (self -> args , 0 );
2006
- Py_INCREF (tmp );
2007
- PyTuple_SET_ITEM (args , 0 , tmp );
2008
-
2009
- tmp = PyTuple_GET_ITEM (self -> args , 1 );
2010
- Py_INCREF (tmp );
2011
- PyTuple_SET_ITEM (args , 1 , tmp );
2012
-
2013
- Py_INCREF (self -> filename );
2014
- PyTuple_SET_ITEM (args , 2 , self -> filename );
1976
+ PyTuple_SET_ITEM (args , 0 , Py_NewRef (PyTuple_GET_ITEM (self -> args , 0 )));
1977
+ PyTuple_SET_ITEM (args , 1 , Py_NewRef (PyTuple_GET_ITEM (self -> args , 1 )));
1978
+ PyTuple_SET_ITEM (args , 2 , Py_NewRef (self -> filename ));
2015
1979
2016
1980
if (self -> filename2 ) {
2017
1981
/*
2018
1982
* This tuple is essentially used as OSError(*args).
2019
1983
* So, to recreate filename2, we need to pass in
2020
1984
* winerror as well.
2021
1985
*/
2022
- Py_INCREF (Py_None );
2023
- PyTuple_SET_ITEM (args , 3 , Py_None );
1986
+ PyTuple_SET_ITEM (args , 3 , Py_NewRef (Py_None ));
2024
1987
2025
1988
/* filename2 */
2026
- Py_INCREF (self -> filename2 );
2027
- PyTuple_SET_ITEM (args , 4 , self -> filename2 );
1989
+ PyTuple_SET_ITEM (args , 4 , Py_NewRef (self -> filename2 ));
2028
1990
}
2029
1991
} else
2030
1992
Py_INCREF (args );
@@ -2185,8 +2147,7 @@ NameError_init(PyNameErrorObject *self, PyObject *args, PyObject *kwds)
2185
2147
}
2186
2148
Py_DECREF (empty_tuple );
2187
2149
2188
- Py_XINCREF (name );
2189
- Py_XSETREF (self -> name , name );
2150
+ Py_XSETREF (self -> name , Py_XNewRef (name ));
2190
2151
2191
2152
return 0 ;
2192
2153
}
@@ -2260,11 +2221,8 @@ AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds
2260
2221
}
2261
2222
Py_DECREF (empty_tuple );
2262
2223
2263
- Py_XINCREF (name );
2264
- Py_XSETREF (self -> name , name );
2265
-
2266
- Py_XINCREF (obj );
2267
- Py_XSETREF (self -> obj , obj );
2224
+ Py_XSETREF (self -> name , Py_XNewRef (name ));
2225
+ Py_XSETREF (self -> obj , Py_XNewRef (obj ));
2268
2226
2269
2227
return 0 ;
2270
2228
}
@@ -2322,8 +2280,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
2322
2280
return -1 ;
2323
2281
2324
2282
if (lenargs >= 1 ) {
2325
- Py_INCREF (PyTuple_GET_ITEM (args , 0 ));
2326
- Py_XSETREF (self -> msg , PyTuple_GET_ITEM (args , 0 ));
2283
+ Py_XSETREF (self -> msg , Py_NewRef (PyTuple_GET_ITEM (args , 0 )));
2327
2284
}
2328
2285
if (lenargs == 2 ) {
2329
2286
info = PyTuple_GET_ITEM (args , 1 );
@@ -2419,8 +2376,7 @@ my_basename(PyObject *name)
2419
2376
return PyUnicode_Substring (name , offset , size );
2420
2377
}
2421
2378
else {
2422
- Py_INCREF (name );
2423
- return name ;
2379
+ return Py_NewRef (name );
2424
2380
}
2425
2381
}
2426
2382
@@ -2572,8 +2528,7 @@ get_string(PyObject *attr, const char *name)
2572
2528
PyErr_Format (PyExc_TypeError , "%.200s attribute must be bytes" , name );
2573
2529
return NULL ;
2574
2530
}
2575
- Py_INCREF (attr );
2576
- return attr ;
2531
+ return Py_NewRef (attr );
2577
2532
}
2578
2533
2579
2534
static PyObject *
@@ -2589,8 +2544,7 @@ get_unicode(PyObject *attr, const char *name)
2589
2544
"%.200s attribute must be unicode" , name );
2590
2545
return NULL ;
2591
2546
}
2592
- Py_INCREF (attr );
2593
- return attr ;
2547
+ return Py_NewRef (attr );
2594
2548
}
2595
2549
2596
2550
static int
0 commit comments