@@ -401,8 +401,7 @@ itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc)
401
401
gbo -> tgtkey = NULL ;
402
402
gbo -> currkey = NULL ;
403
403
gbo -> currvalue = NULL ;
404
- gbo -> keyfunc = keyfunc ;
405
- Py_INCREF (keyfunc );
404
+ gbo -> keyfunc = Py_NewRef (keyfunc );
406
405
gbo -> it = PyObject_GetIter (it );
407
406
if (gbo -> it == NULL ) {
408
407
Py_DECREF (gbo );
@@ -444,8 +443,7 @@ groupby_step(groupbyobject *gbo)
444
443
return -1 ;
445
444
446
445
if (gbo -> keyfunc == Py_None ) {
447
- newkey = newvalue ;
448
- Py_INCREF (newvalue );
446
+ newkey = Py_NewRef (newvalue );
449
447
} else {
450
448
newkey = PyObject_CallOneArg (gbo -> keyfunc , newvalue );
451
449
if (newkey == NULL ) {
@@ -625,10 +623,8 @@ _grouper_create(groupbyobject *parent, PyObject *tgtkey)
625
623
igo = PyObject_GC_New (_grouperobject , & _grouper_type );
626
624
if (igo == NULL )
627
625
return NULL ;
628
- igo -> parent = (PyObject * )parent ;
629
- Py_INCREF (parent );
630
- igo -> tgtkey = tgtkey ;
631
- Py_INCREF (tgtkey );
626
+ igo -> parent = Py_NewRef (parent );
627
+ igo -> tgtkey = Py_NewRef (tgtkey );
632
628
parent -> currgrouper = igo ; /* borrowed reference */
633
629
634
630
PyObject_GC_Track (igo );
@@ -779,8 +775,7 @@ teedataobject_newinternal(PyObject *it)
779
775
tdo -> running = 0 ;
780
776
tdo -> numread = 0 ;
781
777
tdo -> nextlink = NULL ;
782
- Py_INCREF (it );
783
- tdo -> it = it ;
778
+ tdo -> it = Py_NewRef (it );
784
779
PyObject_GC_Track (tdo );
785
780
return (PyObject * )tdo ;
786
781
}
@@ -790,8 +785,7 @@ teedataobject_jumplink(teedataobject *tdo)
790
785
{
791
786
if (tdo -> nextlink == NULL )
792
787
tdo -> nextlink = teedataobject_newinternal (tdo -> it );
793
- Py_XINCREF (tdo -> nextlink );
794
- return tdo -> nextlink ;
788
+ return Py_XNewRef (tdo -> nextlink );
795
789
}
796
790
797
791
static PyObject *
@@ -818,8 +812,7 @@ teedataobject_getitem(teedataobject *tdo, int i)
818
812
tdo -> numread ++ ;
819
813
tdo -> values [i ] = value ;
820
814
}
821
- Py_INCREF (value );
822
- return value ;
815
+ return Py_NewRef (value );
823
816
}
824
817
825
818
static int
@@ -927,8 +920,7 @@ itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
927
920
if (!Py_IS_TYPE (next , & teedataobject_type ))
928
921
goto err ;
929
922
assert (tdo -> nextlink == NULL );
930
- Py_INCREF (next );
931
- tdo -> nextlink = next ;
923
+ tdo -> nextlink = Py_NewRef (next );
932
924
}
933
925
} else {
934
926
if (next != Py_None )
@@ -1026,8 +1018,7 @@ tee_copy(teeobject *to, PyObject *Py_UNUSED(ignored))
1026
1018
newto = PyObject_GC_New (teeobject , & tee_type );
1027
1019
if (newto == NULL )
1028
1020
return NULL ;
1029
- Py_INCREF (to -> dataobj );
1030
- newto -> dataobj = to -> dataobj ;
1021
+ newto -> dataobj = (teedataobject * )Py_NewRef (to -> dataobj );
1031
1022
newto -> index = to -> index ;
1032
1023
newto -> weakreflist = NULL ;
1033
1024
PyObject_GC_Track (newto );
@@ -1343,8 +1334,7 @@ cycle_next(cycleobject *lz)
1343
1334
lz -> index ++ ;
1344
1335
if (lz -> index >= PyList_GET_SIZE (lz -> saved ))
1345
1336
lz -> index = 0 ;
1346
- Py_INCREF (item );
1347
- return item ;
1337
+ return Py_NewRef (item );
1348
1338
}
1349
1339
1350
1340
static PyObject *
@@ -1480,8 +1470,7 @@ itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
1480
1470
Py_DECREF (it );
1481
1471
return NULL ;
1482
1472
}
1483
- Py_INCREF (func );
1484
- lz -> func = func ;
1473
+ lz -> func = Py_NewRef (func );
1485
1474
lz -> it = it ;
1486
1475
lz -> start = 0 ;
1487
1476
@@ -1643,8 +1632,7 @@ itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
1643
1632
Py_DECREF (it );
1644
1633
return NULL ;
1645
1634
}
1646
- Py_INCREF (func );
1647
- lz -> func = func ;
1635
+ lz -> func = Py_NewRef (func );
1648
1636
lz -> it = it ;
1649
1637
lz -> stop = 0 ;
1650
1638
@@ -1940,8 +1928,7 @@ islice_reduce(isliceobject *lz, PyObject *Py_UNUSED(ignored))
1940
1928
return Py_BuildValue ("O(Nn)n" , Py_TYPE (lz ), empty_it , 0 , 0 );
1941
1929
}
1942
1930
if (lz -> stop == -1 ) {
1943
- stop = Py_None ;
1944
- Py_INCREF (stop );
1931
+ stop = Py_NewRef (Py_None );
1945
1932
} else {
1946
1933
stop = PyLong_FromSsize_t (lz -> stop );
1947
1934
if (stop == NULL )
@@ -2062,8 +2049,7 @@ itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
2062
2049
Py_DECREF (it );
2063
2050
return NULL ;
2064
2051
}
2065
- Py_INCREF (func );
2066
- lz -> func = func ;
2052
+ lz -> func = Py_NewRef (func );
2067
2053
lz -> it = it ;
2068
2054
2069
2055
return (PyObject * )lz ;
@@ -2595,8 +2581,7 @@ product_next(productobject *lz)
2595
2581
goto empty ;
2596
2582
}
2597
2583
2598
- Py_INCREF (result );
2599
- return result ;
2584
+ return Py_NewRef (result );
2600
2585
2601
2586
empty :
2602
2587
lz -> stopped = 1 ;
@@ -2926,8 +2911,7 @@ combinations_next(combinationsobject *co)
2926
2911
}
2927
2912
}
2928
2913
2929
- Py_INCREF (result );
2930
- return result ;
2914
+ return Py_NewRef (result );
2931
2915
2932
2916
empty :
2933
2917
co -> stopped = 1 ;
@@ -3257,8 +3241,7 @@ cwr_next(cwrobject *co)
3257
3241
}
3258
3242
}
3259
3243
3260
- Py_INCREF (result );
3261
- return result ;
3244
+ return Py_NewRef (result );
3262
3245
3263
3246
empty :
3264
3247
co -> stopped = 1 ;
@@ -3615,8 +3598,7 @@ permutations_next(permutationsobject *po)
3615
3598
if (i < 0 )
3616
3599
goto empty ;
3617
3600
}
3618
- Py_INCREF (result );
3619
- return result ;
3601
+ return Py_NewRef (result );
3620
3602
3621
3603
empty :
3622
3604
po -> stopped = 1 ;
@@ -3819,13 +3801,11 @@ itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
3819
3801
}
3820
3802
3821
3803
if (binop != Py_None ) {
3822
- Py_XINCREF (binop );
3823
- lz -> binop = binop ;
3804
+ lz -> binop = Py_XNewRef (binop );
3824
3805
}
3825
3806
lz -> total = NULL ;
3826
3807
lz -> it = it ;
3827
- Py_XINCREF (initial );
3828
- lz -> initial = initial ;
3808
+ lz -> initial = Py_XNewRef (initial );
3829
3809
return (PyObject * )lz ;
3830
3810
}
3831
3811
@@ -3857,18 +3837,15 @@ accumulate_next(accumulateobject *lz)
3857
3837
3858
3838
if (lz -> initial != Py_None ) {
3859
3839
lz -> total = lz -> initial ;
3860
- Py_INCREF (Py_None );
3861
- lz -> initial = Py_None ;
3862
- Py_INCREF (lz -> total );
3863
- return lz -> total ;
3840
+ lz -> initial = Py_NewRef (Py_None );
3841
+ return Py_NewRef (lz -> total );
3864
3842
}
3865
3843
val = (* Py_TYPE (lz -> it )-> tp_iternext )(lz -> it );
3866
3844
if (val == NULL )
3867
3845
return NULL ;
3868
3846
3869
3847
if (lz -> total == NULL ) {
3870
- Py_INCREF (val );
3871
- lz -> total = val ;
3848
+ lz -> total = Py_NewRef (val );
3872
3849
return lz -> total ;
3873
3850
}
3874
3851
@@ -4186,8 +4163,7 @@ itertools_filterfalse_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
4186
4163
Py_DECREF (it );
4187
4164
return NULL ;
4188
4165
}
4189
- Py_INCREF (func );
4190
- lz -> func = func ;
4166
+ lz -> func = Py_NewRef (func );
4191
4167
lz -> it = it ;
4192
4168
4193
4169
return (PyObject * )lz ;
@@ -4581,8 +4557,7 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4581
4557
ro = (repeatobject * )type -> tp_alloc (type , 0 );
4582
4558
if (ro == NULL )
4583
4559
return NULL ;
4584
- Py_INCREF (element );
4585
- ro -> element = element ;
4560
+ ro -> element = Py_NewRef (element );
4586
4561
ro -> cnt = cnt ;
4587
4562
return (PyObject * )ro ;
4588
4563
}
@@ -4609,8 +4584,7 @@ repeat_next(repeatobject *ro)
4609
4584
return NULL ;
4610
4585
if (ro -> cnt > 0 )
4611
4586
ro -> cnt -- ;
4612
- Py_INCREF (ro -> element );
4613
- return ro -> element ;
4587
+ return Py_NewRef (ro -> element );
4614
4588
}
4615
4589
4616
4590
static PyObject *
@@ -4782,8 +4756,7 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4782
4756
lz -> tuplesize = tuplesize ;
4783
4757
lz -> numactive = tuplesize ;
4784
4758
lz -> result = result ;
4785
- Py_INCREF (fillvalue );
4786
- lz -> fillvalue = fillvalue ;
4759
+ lz -> fillvalue = Py_NewRef (fillvalue );
4787
4760
return (PyObject * )lz ;
4788
4761
}
4789
4762
@@ -4825,8 +4798,7 @@ zip_longest_next(ziplongestobject *lz)
4825
4798
for (i = 0 ; i < tuplesize ; i ++ ) {
4826
4799
it = PyTuple_GET_ITEM (lz -> ittuple , i );
4827
4800
if (it == NULL ) {
4828
- Py_INCREF (lz -> fillvalue );
4829
- item = lz -> fillvalue ;
4801
+ item = Py_NewRef (lz -> fillvalue );
4830
4802
} else {
4831
4803
item = PyIter_Next (it );
4832
4804
if (item == NULL ) {
@@ -4836,8 +4808,7 @@ zip_longest_next(ziplongestobject *lz)
4836
4808
Py_DECREF (result );
4837
4809
return NULL ;
4838
4810
} else {
4839
- Py_INCREF (lz -> fillvalue );
4840
- item = lz -> fillvalue ;
4811
+ item = Py_NewRef (lz -> fillvalue );
4841
4812
PyTuple_SET_ITEM (lz -> ittuple , i , NULL );
4842
4813
Py_DECREF (it );
4843
4814
}
@@ -4859,8 +4830,7 @@ zip_longest_next(ziplongestobject *lz)
4859
4830
for (i = 0 ; i < tuplesize ; i ++ ) {
4860
4831
it = PyTuple_GET_ITEM (lz -> ittuple , i );
4861
4832
if (it == NULL ) {
4862
- Py_INCREF (lz -> fillvalue );
4863
- item = lz -> fillvalue ;
4833
+ item = Py_NewRef (lz -> fillvalue );
4864
4834
} else {
4865
4835
item = PyIter_Next (it );
4866
4836
if (item == NULL ) {
@@ -4870,8 +4840,7 @@ zip_longest_next(ziplongestobject *lz)
4870
4840
Py_DECREF (result );
4871
4841
return NULL ;
4872
4842
} else {
4873
- Py_INCREF (lz -> fillvalue );
4874
- item = lz -> fillvalue ;
4843
+ item = Py_NewRef (lz -> fillvalue );
4875
4844
PyTuple_SET_ITEM (lz -> ittuple , i , NULL );
4876
4845
Py_DECREF (it );
4877
4846
}
0 commit comments