@@ -63,8 +63,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
63
63
}
64
64
for (j = 0 ; j < i ; j ++ ) {
65
65
base = args [j ];
66
- PyList_SET_ITEM (new_bases , j , base );
67
- Py_INCREF (base );
66
+ PyList_SET_ITEM (new_bases , j , Py_NewRef (base ));
68
67
}
69
68
}
70
69
j = PyList_GET_SIZE (new_bases );
@@ -170,8 +169,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
170
169
}
171
170
if (winner != meta ) {
172
171
Py_DECREF (meta );
173
- meta = winner ;
174
- Py_INCREF (meta );
172
+ meta = Py_NewRef (winner );
175
173
}
176
174
}
177
175
/* else: meta is not a class, so we cannot do the metaclass
@@ -804,8 +802,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
804
802
goto error ;
805
803
if (is_ast ) {
806
804
if (flags & PyCF_ONLY_AST ) {
807
- Py_INCREF (source );
808
- result = source ;
805
+ result = Py_NewRef (source );
809
806
}
810
807
else {
811
808
PyArena * arena ;
@@ -1128,8 +1125,7 @@ builtin_getattr(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1128
1125
if (nargs > 2 ) {
1129
1126
if (_PyObject_LookupAttr (v , name , & result ) == 0 ) {
1130
1127
PyObject * dflt = args [2 ];
1131
- Py_INCREF (dflt );
1132
- return dflt ;
1128
+ return Py_NewRef (dflt );
1133
1129
}
1134
1130
}
1135
1131
else {
@@ -1162,8 +1158,7 @@ builtin_globals_impl(PyObject *module)
1162
1158
PyObject * d ;
1163
1159
1164
1160
d = PyEval_GetGlobals ();
1165
- Py_XINCREF (d );
1166
- return d ;
1161
+ return Py_XNewRef (d );
1167
1162
}
1168
1163
1169
1164
@@ -1390,12 +1385,10 @@ map_reduce(mapobject *lz, PyObject *Py_UNUSED(ignored))
1390
1385
Py_ssize_t i ;
1391
1386
if (args == NULL )
1392
1387
return NULL ;
1393
- Py_INCREF (lz -> func );
1394
- PyTuple_SET_ITEM (args , 0 , lz -> func );
1388
+ PyTuple_SET_ITEM (args , 0 , Py_NewRef (lz -> func ));
1395
1389
for (i = 0 ; i < numargs ; i ++ ){
1396
1390
PyObject * it = PyTuple_GET_ITEM (lz -> iters , i );
1397
- Py_INCREF (it );
1398
- PyTuple_SET_ITEM (args , i + 1 , it );
1391
+ PyTuple_SET_ITEM (args , i + 1 , Py_NewRef (it ));
1399
1392
}
1400
1393
1401
1394
return Py_BuildValue ("ON" , Py_TYPE (lz ), args );
@@ -1486,8 +1479,7 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1486
1479
return NULL ;
1487
1480
PyErr_Clear ();
1488
1481
}
1489
- Py_INCREF (def );
1490
- return def ;
1482
+ return Py_NewRef (def );
1491
1483
} else if (PyErr_Occurred ()) {
1492
1484
return NULL ;
1493
1485
} else {
@@ -1723,8 +1715,7 @@ builtin_locals_impl(PyObject *module)
1723
1715
PyObject * d ;
1724
1716
1725
1717
d = PyEval_GetLocals ();
1726
- Py_XINCREF (d );
1727
- return d ;
1718
+ return Py_XNewRef (d );
1728
1719
}
1729
1720
1730
1721
@@ -1785,8 +1776,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
1785
1776
}
1786
1777
/* no key function; the value is the item */
1787
1778
else {
1788
- val = item ;
1789
- Py_INCREF (val );
1779
+ val = Py_NewRef (item );
1790
1780
}
1791
1781
1792
1782
/* maximum value and item are unset; set them */
@@ -1816,8 +1806,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
1816
1806
if (maxval == NULL ) {
1817
1807
assert (maxitem == NULL );
1818
1808
if (defaultval != NULL ) {
1819
- Py_INCREF (defaultval );
1820
- maxitem = defaultval ;
1809
+ maxitem = Py_NewRef (defaultval );
1821
1810
} else {
1822
1811
PyErr_Format (PyExc_ValueError ,
1823
1812
"%s() arg is an empty sequence" , name );
@@ -2737,8 +2726,7 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2737
2726
return NULL ;
2738
2727
}
2739
2728
for (i = 0 ; i < tuplesize ; i ++ ) {
2740
- Py_INCREF (Py_None );
2741
- PyTuple_SET_ITEM (result , i , Py_None );
2729
+ PyTuple_SET_ITEM (result , i , Py_NewRef (Py_None ));
2742
2730
}
2743
2731
2744
2732
/* create zipobject structure */
0 commit comments