@@ -200,8 +200,7 @@ get_future_loop(PyObject *fut)
200
200
201
201
if (Future_CheckExact (fut ) || Task_CheckExact (fut )) {
202
202
PyObject * loop = ((FutureObj * )fut )-> fut_loop ;
203
- Py_INCREF (loop );
204
- return loop ;
203
+ return Py_NewRef (loop );
205
204
}
206
205
207
206
if (_PyObject_LookupAttr (fut , & _Py_ID (get_loop ), & getloop ) < 0 ) {
@@ -265,8 +264,7 @@ get_running_loop(PyObject **loop)
265
264
}
266
265
#endif
267
266
268
- Py_INCREF (running_loop );
269
- * loop = running_loop ;
267
+ * loop = Py_NewRef (running_loop );
270
268
return 0 ;
271
269
272
270
not_found :
@@ -541,8 +539,7 @@ future_set_result(FutureObj *fut, PyObject *res)
541
539
}
542
540
543
541
assert (!fut -> fut_result );
544
- Py_INCREF (res );
545
- fut -> fut_result = res ;
542
+ fut -> fut_result = Py_NewRef (res );
546
543
fut -> fut_state = STATE_FINISHED ;
547
544
548
545
if (future_schedule_callbacks (fut ) == -1 ) {
@@ -573,8 +570,7 @@ future_set_exception(FutureObj *fut, PyObject *exc)
573
570
}
574
571
}
575
572
else {
576
- exc_val = exc ;
577
- Py_INCREF (exc_val );
573
+ exc_val = Py_NewRef (exc );
578
574
}
579
575
if (!PyExceptionInstance_Check (exc_val )) {
580
576
Py_DECREF (exc_val );
@@ -655,14 +651,12 @@ future_get_result(FutureObj *fut, PyObject **result)
655
651
if (PyException_SetTraceback (fut -> fut_exception , tb ) < 0 ) {
656
652
return -1 ;
657
653
}
658
- Py_INCREF (fut -> fut_exception );
659
- * result = fut -> fut_exception ;
654
+ * result = Py_NewRef (fut -> fut_exception );
660
655
Py_CLEAR (fut -> fut_exception_tb );
661
656
return 1 ;
662
657
}
663
658
664
- Py_INCREF (fut -> fut_result );
665
- * result = fut -> fut_result ;
659
+ * result = Py_NewRef (fut -> fut_result );
666
660
return 0 ;
667
661
}
668
662
@@ -704,10 +698,8 @@ future_add_done_callback(FutureObj *fut, PyObject *arg, PyObject *ctx)
704
698
*/
705
699
706
700
if (fut -> fut_callbacks == NULL && fut -> fut_callback0 == NULL ) {
707
- Py_INCREF (arg );
708
- fut -> fut_callback0 = arg ;
709
- Py_INCREF (ctx );
710
- fut -> fut_context0 = ctx ;
701
+ fut -> fut_callback0 = Py_NewRef (arg );
702
+ fut -> fut_context0 = Py_NewRef (ctx );
711
703
}
712
704
else {
713
705
PyObject * tup = PyTuple_New (2 );
@@ -896,8 +888,7 @@ _asyncio_Future_exception_impl(FutureObj *self)
896
888
897
889
if (self -> fut_exception != NULL ) {
898
890
self -> fut_log_tb = 0 ;
899
- Py_INCREF (self -> fut_exception );
900
- return self -> fut_exception ;
891
+ return Py_NewRef (self -> fut_exception );
901
892
}
902
893
903
894
Py_RETURN_NONE ;
@@ -1158,8 +1149,7 @@ _asyncio_Future_get_loop_impl(FutureObj *self)
1158
1149
/*[clinic end generated code: output=119b6ea0c9816c3f input=cba48c2136c79d1f]*/
1159
1150
{
1160
1151
ENSURE_FUTURE_ALIVE (self )
1161
- Py_INCREF (self -> fut_loop );
1162
- return self -> fut_loop ;
1152
+ return Py_NewRef (self -> fut_loop );
1163
1153
}
1164
1154
1165
1155
static PyObject *
@@ -1230,8 +1220,7 @@ FutureObj_get_loop(FutureObj *fut, void *Py_UNUSED(ignored))
1230
1220
if (!future_is_alive (fut )) {
1231
1221
Py_RETURN_NONE ;
1232
1222
}
1233
- Py_INCREF (fut -> fut_loop );
1234
- return fut -> fut_loop ;
1223
+ return Py_NewRef (fut -> fut_loop );
1235
1224
}
1236
1225
1237
1226
static PyObject *
@@ -1246,8 +1235,7 @@ FutureObj_get_callbacks(FutureObj *fut, void *Py_UNUSED(ignored))
1246
1235
Py_RETURN_NONE ;
1247
1236
}
1248
1237
1249
- Py_INCREF (fut -> fut_callbacks );
1250
- return fut -> fut_callbacks ;
1238
+ return Py_NewRef (fut -> fut_callbacks );
1251
1239
}
1252
1240
1253
1241
Py_ssize_t len = 1 ;
@@ -1293,8 +1281,7 @@ FutureObj_get_result(FutureObj *fut, void *Py_UNUSED(ignored))
1293
1281
if (fut -> fut_result == NULL) {
1294
1282
Py_RETURN_NONE ;
1295
1283
}
1296
- Py_INCREF (fut -> fut_result );
1297
- return fut -> fut_result ;
1284
+ return Py_NewRef (fut -> fut_result );
1298
1285
}
1299
1286
1300
1287
static PyObject *
@@ -1304,8 +1291,7 @@ FutureObj_get_exception(FutureObj *fut, void *Py_UNUSED(ignored))
1304
1291
if (fut -> fut_exception == NULL) {
1305
1292
Py_RETURN_NONE ;
1306
1293
}
1307
- Py_INCREF (fut -> fut_exception );
1308
- return fut -> fut_exception ;
1294
+ return Py_NewRef (fut -> fut_exception );
1309
1295
}
1310
1296
1311
1297
static PyObject *
@@ -1314,8 +1300,7 @@ FutureObj_get_source_traceback(FutureObj *fut, void *Py_UNUSED(ignored))
1314
1300
if (!future_is_alive (fut ) || fut -> fut_source_tb == NULL ) {
1315
1301
Py_RETURN_NONE ;
1316
1302
}
1317
- Py_INCREF (fut -> fut_source_tb );
1318
- return fut -> fut_source_tb ;
1303
+ return Py_NewRef (fut -> fut_source_tb );
1319
1304
}
1320
1305
1321
1306
static PyObject *
@@ -1324,8 +1309,7 @@ FutureObj_get_cancel_message(FutureObj *fut, void *Py_UNUSED(ignored))
1324
1309
if (fut -> fut_cancel_msg == NULL ) {
1325
1310
Py_RETURN_NONE ;
1326
1311
}
1327
- Py_INCREF (fut -> fut_cancel_msg );
1328
- return fut -> fut_cancel_msg ;
1312
+ return Py_NewRef (fut -> fut_cancel_msg );
1329
1313
}
1330
1314
1331
1315
static int
@@ -1361,8 +1345,7 @@ FutureObj_get_state(FutureObj *fut, void *Py_UNUSED(ignored))
1361
1345
default :
1362
1346
assert (0 );
1363
1347
}
1364
- Py_XINCREF (ret );
1365
- return ret ;
1348
+ return Py_XNewRef (ret );
1366
1349
}
1367
1350
1368
1351
static PyObject *
@@ -1587,8 +1570,7 @@ FutureIter_am_send(futureiterobject *it,
1587
1570
if (fut -> fut_state == STATE_PENDING ) {
1588
1571
if (!fut -> fut_blocking ) {
1589
1572
fut -> fut_blocking = 1 ;
1590
- Py_INCREF (fut );
1591
- * result = (PyObject * )fut ;
1573
+ * result = Py_NewRef (fut );
1592
1574
return PYGEN_NEXT ;
1593
1575
}
1594
1576
PyErr_SetString (PyExc_RuntimeError ,
@@ -1873,11 +1855,8 @@ TaskStepMethWrapper_new(TaskObj *task, PyObject *arg)
1873
1855
return NULL ;
1874
1856
}
1875
1857
1876
- Py_INCREF (task );
1877
- o -> sw_task = task ;
1878
-
1879
- Py_XINCREF (arg );
1880
- o -> sw_arg = arg ;
1858
+ o -> sw_task = (TaskObj * )Py_NewRef (task );
1859
+ o -> sw_arg = Py_XNewRef (arg );
1881
1860
1882
1861
PyObject_GC_Track (o );
1883
1862
return (PyObject * ) o ;
@@ -2105,8 +2084,7 @@ static PyObject *
2105
2084
TaskObj_get_coro (TaskObj * task , void * Py_UNUSED (ignored ))
2106
2085
{
2107
2086
if (task -> task_coro ) {
2108
- Py_INCREF (task -> task_coro );
2109
- return task -> task_coro ;
2087
+ return Py_NewRef (task -> task_coro );
2110
2088
}
2111
2089
2112
2090
Py_RETURN_NONE ;
@@ -2116,8 +2094,7 @@ static PyObject *
2116
2094
TaskObj_get_fut_waiter (TaskObj * task , void * Py_UNUSED (ignored ))
2117
2095
{
2118
2096
if (task -> task_fut_waiter ) {
2119
- Py_INCREF (task -> task_fut_waiter );
2120
- return task -> task_fut_waiter ;
2097
+ return Py_NewRef (task -> task_fut_waiter );
2121
2098
}
2122
2099
2123
2100
Py_RETURN_NONE ;
@@ -2360,8 +2337,7 @@ static PyObject *
2360
2337
_asyncio_Task_get_coro_impl (TaskObj * self )
2361
2338
/*[clinic end generated code: output=bcac27c8cc6c8073 input=d2e8606c42a7b403]*/
2362
2339
{
2363
- Py_INCREF (self -> task_coro );
2364
- return self -> task_coro ;
2340
+ return Py_NewRef (self -> task_coro );
2365
2341
}
2366
2342
2367
2343
/*[clinic input]
@@ -2372,8 +2348,7 @@ static PyObject *
2372
2348
_asyncio_Task_get_context_impl (TaskObj * self )
2373
2349
/*[clinic end generated code: output=6996f53d3dc01aef input=87c0b209b8fceeeb]*/
2374
2350
{
2375
- Py_INCREF (self -> task_context );
2376
- return self -> task_context ;
2351
+ return Py_NewRef (self -> task_context );
2377
2352
}
2378
2353
2379
2354
/*[clinic input]
@@ -2385,8 +2360,7 @@ _asyncio_Task_get_name_impl(TaskObj *self)
2385
2360
/*[clinic end generated code: output=0ecf1570c3b37a8f input=a4a6595d12f4f0f8]*/
2386
2361
{
2387
2362
if (self -> task_name ) {
2388
- Py_INCREF (self -> task_name );
2389
- return self -> task_name ;
2363
+ return Py_NewRef (self -> task_name );
2390
2364
}
2391
2365
2392
2366
Py_RETURN_NONE ;
@@ -3258,9 +3232,7 @@ new_running_loop_holder(PyObject *loop)
3258
3232
#if defined(HAVE_GETPID ) && !defined(MS_WINDOWS )
3259
3233
rl -> rl_pid = getpid ();
3260
3234
#endif
3261
-
3262
- Py_INCREF (loop );
3263
- rl -> rl_loop = loop ;
3235
+ rl -> rl_loop = Py_NewRef (loop );
3264
3236
3265
3237
return rl ;
3266
3238
}
0 commit comments