@@ -342,8 +342,7 @@ dict_getitem_knownhash(PyObject *self, PyObject *args)
342342 return NULL ;
343343 }
344344
345- Py_XINCREF (result );
346- return result ;
345+ return Py_XNewRef (result );
347346}
348347
349348/* Issue #4701: Check that PyObject_Hash implicitly calls
@@ -1242,8 +1241,7 @@ get_args(PyObject *self, PyObject *args)
12421241 if (args == NULL ) {
12431242 args = Py_None ;
12441243 }
1245- Py_INCREF (args );
1246- return args ;
1244+ return Py_NewRef (args );
12471245}
12481246
12491247static PyObject *
@@ -1252,8 +1250,7 @@ get_kwargs(PyObject *self, PyObject *args, PyObject *kwargs)
12521250 if (kwargs == NULL ) {
12531251 kwargs = Py_None ;
12541252 }
1255- Py_INCREF (kwargs );
1256- return kwargs ;
1253+ return Py_NewRef (kwargs );
12571254}
12581255
12591256/* Test tuple argument processing */
@@ -1514,8 +1511,7 @@ getargs_S(PyObject *self, PyObject *args)
15141511 PyObject * obj ;
15151512 if (!PyArg_ParseTuple (args , "S" , & obj ))
15161513 return NULL ;
1517- Py_INCREF (obj );
1518- return obj ;
1514+ return Py_NewRef (obj );
15191515}
15201516
15211517static PyObject *
@@ -1524,8 +1520,7 @@ getargs_Y(PyObject *self, PyObject *args)
15241520 PyObject * obj ;
15251521 if (!PyArg_ParseTuple (args , "Y" , & obj ))
15261522 return NULL ;
1527- Py_INCREF (obj );
1528- return obj ;
1523+ return Py_NewRef (obj );
15291524}
15301525
15311526static PyObject *
@@ -1534,8 +1529,7 @@ getargs_U(PyObject *self, PyObject *args)
15341529 PyObject * obj ;
15351530 if (!PyArg_ParseTuple (args , "U" , & obj ))
15361531 return NULL ;
1537- Py_INCREF (obj );
1538- return obj ;
1532+ return Py_NewRef (obj );
15391533}
15401534
15411535static PyObject *
@@ -1609,8 +1603,7 @@ getargs_z_star(PyObject *self, PyObject *args)
16091603 if (buffer .buf != NULL )
16101604 bytes = PyBytes_FromStringAndSize (buffer .buf , buffer .len );
16111605 else {
1612- Py_INCREF (Py_None );
1613- bytes = Py_None ;
1606+ bytes = Py_NewRef (Py_None );
16141607 }
16151608 PyBuffer_Release (& buffer );
16161609 return bytes ;
@@ -1873,8 +1866,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
18731866 buffers + 4 , buffers + 5 , buffers + 6 , buffers + 7 );
18741867
18751868 if (result ) {
1876- return_value = Py_None ;
1877- Py_INCREF (Py_None );
1869+ return_value = Py_NewRef (Py_None );
18781870 }
18791871
18801872exit :
@@ -2193,11 +2185,9 @@ get_timezone_utc_capi(PyObject* self, PyObject *args) {
21932185 return NULL ;
21942186 }
21952187 if (macro ) {
2196- Py_INCREF (PyDateTime_TimeZone_UTC );
2197- return PyDateTime_TimeZone_UTC ;
2188+ return Py_NewRef (PyDateTime_TimeZone_UTC );
21982189 } else {
2199- Py_INCREF (PyDateTimeAPI -> TimeZone_UTC );
2200- return PyDateTimeAPI -> TimeZone_UTC ;
2190+ return Py_NewRef (PyDateTimeAPI -> TimeZone_UTC );
22012191 }
22022192}
22032193
@@ -2984,8 +2974,7 @@ failing_converter(PyObject *obj, void *arg)
29842974{
29852975 /* Clone str1, then let the conversion fail. */
29862976 assert (str1 );
2987- str2 = str1 ;
2988- Py_INCREF (str2 );
2977+ str2 = Py_NewRef (str1 );
29892978 return 0 ;
29902979}
29912980static PyObject *
@@ -3428,8 +3417,7 @@ with_tp_del(PyObject *self, PyObject *args)
34283417 return NULL ;
34293418 }
34303419 tp -> tp_del = slot_tp_del ;
3431- Py_INCREF (obj );
3432- return obj ;
3420+ return Py_NewRef (obj );
34333421}
34343422
34353423static PyObject *
@@ -3447,8 +3435,7 @@ without_gc(PyObject *Py_UNUSED(self), PyObject *obj)
34473435 tp -> tp_clear = NULL ;
34483436 }
34493437 assert (!PyType_IS_GC (tp ));
3450- Py_INCREF (obj );
3451- return obj ;
3438+ return Py_NewRef (obj );
34523439}
34533440
34543441static PyMethodDef ml ;
@@ -3469,8 +3456,7 @@ static PyMethodDef ml = {
34693456static PyObject *
34703457_test_incref (PyObject * ob )
34713458{
3472- Py_INCREF (ob );
3473- return ob ;
3459+ return Py_NewRef (ob );
34743460}
34753461
34763462static PyObject *
@@ -3817,8 +3803,7 @@ test_setallocators(PyMemAllocatorDomain domain)
38173803 goto fail ;
38183804 }
38193805
3820- Py_INCREF (Py_None );
3821- res = Py_None ;
3806+ res = Py_NewRef (Py_None );
38223807 goto finally ;
38233808
38243809fail :
@@ -4078,8 +4063,7 @@ call_in_temporary_c_thread(PyObject *self, PyObject *callback)
40784063 goto exit ;
40794064 }
40804065
4081- Py_INCREF (callback );
4082- test_c_thread .callback = callback ;
4066+ test_c_thread .callback = Py_NewRef (callback );
40834067
40844068 PyThread_acquire_lock (test_c_thread .start_event , 1 );
40854069 PyThread_acquire_lock (test_c_thread .exit_event , 1 );
@@ -4100,8 +4084,7 @@ call_in_temporary_c_thread(PyObject *self, PyObject *callback)
41004084 PyThread_release_lock (test_c_thread .exit_event );
41014085 Py_END_ALLOW_THREADS
41024086
4103- Py_INCREF (Py_None );
4104- res = Py_None ;
4087+ res = Py_NewRef (Py_None );
41054088
41064089exit :
41074090 Py_CLEAR (test_c_thread .callback );
@@ -5037,8 +5020,7 @@ _null_to_none(PyObject* obj)
50375020 if (obj == NULL ) {
50385021 Py_RETURN_NONE ;
50395022 }
5040- Py_INCREF (obj );
5041- return obj ;
5023+ return Py_NewRef (obj );
50425024}
50435025
50445026static PyObject *
@@ -5554,8 +5536,7 @@ get_dict_watcher_events(PyObject *self, PyObject *Py_UNUSED(args))
55545536 PyErr_SetString (PyExc_RuntimeError , "no watchers active" );
55555537 return NULL ;
55565538 }
5557- Py_INCREF (g_dict_watch_events );
5558- return g_dict_watch_events ;
5539+ return Py_NewRef (g_dict_watch_events );
55595540}
55605541
55615542
@@ -5924,8 +5905,7 @@ function_get_code(PyObject *self, PyObject *func)
59245905{
59255906 PyObject * code = PyFunction_GetCode (func );
59265907 if (code != NULL ) {
5927- Py_INCREF (code );
5928- return code ;
5908+ return Py_NewRef (code );
59295909 } else {
59305910 return NULL ;
59315911 }
@@ -5936,8 +5916,7 @@ function_get_globals(PyObject *self, PyObject *func)
59365916{
59375917 PyObject * globals = PyFunction_GetGlobals (func );
59385918 if (globals != NULL ) {
5939- Py_INCREF (globals );
5940- return globals ;
5919+ return Py_NewRef (globals );
59415920 } else {
59425921 return NULL ;
59435922 }
@@ -5948,8 +5927,7 @@ function_get_module(PyObject *self, PyObject *func)
59485927{
59495928 PyObject * module = PyFunction_GetModule (func );
59505929 if (module != NULL ) {
5951- Py_INCREF (module );
5952- return module ;
5930+ return Py_NewRef (module );
59535931 } else {
59545932 return NULL ;
59555933 }
@@ -5960,8 +5938,7 @@ function_get_defaults(PyObject *self, PyObject *func)
59605938{
59615939 PyObject * defaults = PyFunction_GetDefaults (func );
59625940 if (defaults != NULL ) {
5963- Py_INCREF (defaults );
5964- return defaults ;
5941+ return Py_NewRef (defaults );
59655942 } else if (PyErr_Occurred ()) {
59665943 return NULL ;
59675944 } else {
@@ -5987,8 +5964,7 @@ function_get_kw_defaults(PyObject *self, PyObject *func)
59875964{
59885965 PyObject * defaults = PyFunction_GetKwDefaults (func );
59895966 if (defaults != NULL ) {
5990- Py_INCREF (defaults );
5991- return defaults ;
5967+ return Py_NewRef (defaults );
59925968 } else if (PyErr_Occurred ()) {
59935969 return NULL ;
59945970 } else {
@@ -6099,8 +6075,7 @@ get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(args))
60996075 PyErr_SetString (PyExc_RuntimeError , "no watchers active" );
61006076 return NULL ;
61016077 }
6102- Py_INCREF (g_type_modified_events );
6103- return g_type_modified_events ;
6078+ return Py_NewRef (g_type_modified_events );
61046079}
61056080
61066081static PyObject *
@@ -6729,8 +6704,7 @@ awaitObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
67296704 return NULL ;
67306705 }
67316706
6732- Py_INCREF (v );
6733- ao -> ao_iterator = v ;
6707+ ao -> ao_iterator = Py_NewRef (v );
67346708
67356709 return (PyObject * )ao ;
67366710}
@@ -6747,8 +6721,7 @@ awaitObject_dealloc(awaitObject *ao)
67476721static PyObject *
67486722awaitObject_await (awaitObject * ao )
67496723{
6750- Py_INCREF (ao -> ao_iterator );
6751- return ao -> ao_iterator ;
6724+ return Py_NewRef (ao -> ao_iterator );
67526725}
67536726
67546727static PyAsyncMethods awaitType_as_async = {
@@ -6969,8 +6942,7 @@ generic_alias_new(PyObject *item)
69696942 if (o == NULL ) {
69706943 return NULL ;
69716944 }
6972- Py_INCREF (item );
6973- o -> item = item ;
6945+ o -> item = Py_NewRef (item );
69746946 return (PyObject * ) o ;
69756947}
69766948
0 commit comments