@@ -63,8 +63,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
6363 }
6464 for (j = 0 ; j < i ; j ++ ) {
6565 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 ));
6867 }
6968 }
7069 j = PyList_GET_SIZE (new_bases );
@@ -170,8 +169,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
170169 }
171170 if (winner != meta ) {
172171 Py_DECREF (meta );
173- meta = winner ;
174- Py_INCREF (meta );
172+ meta = Py_NewRef (winner );
175173 }
176174 }
177175 /* 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,
804802 goto error ;
805803 if (is_ast ) {
806804 if (flags & PyCF_ONLY_AST ) {
807- Py_INCREF (source );
808- result = source ;
805+ result = Py_NewRef (source );
809806 }
810807 else {
811808 PyArena * arena ;
@@ -1128,8 +1125,7 @@ builtin_getattr(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
11281125 if (nargs > 2 ) {
11291126 if (_PyObject_LookupAttr (v , name , & result ) == 0 ) {
11301127 PyObject * dflt = args [2 ];
1131- Py_INCREF (dflt );
1132- return dflt ;
1128+ return Py_NewRef (dflt );
11331129 }
11341130 }
11351131 else {
@@ -1162,8 +1158,7 @@ builtin_globals_impl(PyObject *module)
11621158 PyObject * d ;
11631159
11641160 d = PyEval_GetGlobals ();
1165- Py_XINCREF (d );
1166- return d ;
1161+ return Py_XNewRef (d );
11671162}
11681163
11691164
@@ -1390,12 +1385,10 @@ map_reduce(mapobject *lz, PyObject *Py_UNUSED(ignored))
13901385 Py_ssize_t i ;
13911386 if (args == NULL )
13921387 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 ));
13951389 for (i = 0 ; i < numargs ; i ++ ){
13961390 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 ));
13991392 }
14001393
14011394 return Py_BuildValue ("ON" , Py_TYPE (lz ), args );
@@ -1486,8 +1479,7 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
14861479 return NULL ;
14871480 PyErr_Clear ();
14881481 }
1489- Py_INCREF (def );
1490- return def ;
1482+ return Py_NewRef (def );
14911483 } else if (PyErr_Occurred ()) {
14921484 return NULL ;
14931485 } else {
@@ -1723,8 +1715,7 @@ builtin_locals_impl(PyObject *module)
17231715 PyObject * d ;
17241716
17251717 d = PyEval_GetLocals ();
1726- Py_XINCREF (d );
1727- return d ;
1718+ return Py_XNewRef (d );
17281719}
17291720
17301721
@@ -1785,8 +1776,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
17851776 }
17861777 /* no key function; the value is the item */
17871778 else {
1788- val = item ;
1789- Py_INCREF (val );
1779+ val = Py_NewRef (item );
17901780 }
17911781
17921782 /* maximum value and item are unset; set them */
@@ -1816,8 +1806,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
18161806 if (maxval == NULL ) {
18171807 assert (maxitem == NULL );
18181808 if (defaultval != NULL ) {
1819- Py_INCREF (defaultval );
1820- maxitem = defaultval ;
1809+ maxitem = Py_NewRef (defaultval );
18211810 } else {
18221811 PyErr_Format (PyExc_ValueError ,
18231812 "%s() arg is an empty sequence" , name );
@@ -2737,8 +2726,7 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
27372726 return NULL ;
27382727 }
27392728 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 ));
27422730 }
27432731
27442732 /* create zipobject structure */
0 commit comments