@@ -3282,14 +3282,15 @@ AK_build_pair_ssize_t(Py_ssize_t a, Py_ssize_t b)
3282
3282
Py_DECREF (py_a );
3283
3283
return NULL ;
3284
3284
}
3285
+ // steals refs
3285
3286
PyTuple_SET_ITEM (t , 0 , py_a );
3286
3287
PyTuple_SET_ITEM (t , 1 , py_b );
3287
3288
return t ;
3288
3289
}
3289
3290
3290
3291
// Returns NULL on error. Returns a new reference. Note that a reference is stolen from the PyObject argument.
3291
3292
static inline PyObject *
3292
- AK_build_pair_ssize_t_slice (Py_ssize_t a , PyObject * py_b )
3293
+ AK_build_pair_ssize_t_pyo (Py_ssize_t a , PyObject * py_b )
3293
3294
{
3294
3295
if (py_b == NULL ) { // construction failed
3295
3296
return NULL ;
@@ -3303,6 +3304,7 @@ AK_build_pair_ssize_t_slice(Py_ssize_t a, PyObject* py_b)
3303
3304
Py_DECREF (t );
3304
3305
return NULL ;
3305
3306
}
3307
+ // steals refs
3306
3308
PyTuple_SET_ITEM (t , 0 , py_a );
3307
3309
PyTuple_SET_ITEM (t , 1 , py_b );
3308
3310
return t ;
@@ -4497,7 +4499,7 @@ BIIterSeq_iternext(BIIterSeqObject *self)
4497
4499
static PyObject *
4498
4500
BIIterSeq_reversed (BIIterSeqObject * self )
4499
4501
{
4500
- return BIIterSelector_new (self -> bi , self -> selector , !self -> reversed , BIIS_SEQ , 0 );
4502
+ return BIIterSelector_new (self -> bi , self -> selector , !self -> reversed , BIIS_SEQ , false );
4501
4503
}
4502
4504
4503
4505
static PyObject *
@@ -4579,7 +4581,7 @@ BIIterSlice_iternext(BIIterSliceObject *self) {
4579
4581
static PyObject *
4580
4582
BIIterSlice_reversed (BIIterSliceObject * self )
4581
4583
{
4582
- return BIIterSelector_new (self -> bi , self -> selector , !self -> reversed , BIIS_SLICE , 0 );
4584
+ return BIIterSelector_new (self -> bi , self -> selector , !self -> reversed , BIIS_SLICE , false );
4583
4585
}
4584
4586
4585
4587
static PyObject *
@@ -4834,7 +4836,7 @@ BIIterContiguous_iternext(BIIterContiguousObject *self)
4834
4836
if (self -> last_block == -1 ) { // iter produced no values, terminate
4835
4837
break ;
4836
4838
}
4837
- return AK_build_pair_ssize_t_slice ( // steals ref
4839
+ return AK_build_pair_ssize_t_pyo ( // steals ref
4838
4840
self -> last_block ,
4839
4841
AK_build_slice_inclusive (slice_start ,
4840
4842
self -> last_column ,
@@ -4859,7 +4861,7 @@ BIIterContiguous_iternext(BIIterContiguousObject *self)
4859
4861
}
4860
4862
self -> next_block = block ;
4861
4863
self -> next_column = column ;
4862
- return AK_build_pair_ssize_t_slice ( // steals ref
4864
+ return AK_build_pair_ssize_t_pyo ( // steals ref
4863
4865
self -> last_block ,
4864
4866
AK_build_slice_inclusive (slice_start ,
4865
4867
self -> last_column ,
@@ -4910,13 +4912,18 @@ BIIterBlock_new(BlockIndexObject *bi, bool reversed) {
4910
4912
bii -> pos = 0 ;
4911
4913
4912
4914
// create a new ref of the null slice
4913
-
4915
+ PyObject * ns = AK_build_slice (-1 , -1 , 1 ); // get all null; new ref
4916
+ if (ns == NULL ) {
4917
+ return NULL ;
4918
+ }
4919
+ bii -> null_slice = ns ;
4914
4920
return (PyObject * )bii ;
4915
4921
}
4916
4922
4917
4923
static void
4918
4924
BIIterBlock_dealloc (BIIterBlockObject * self ) {
4919
4925
Py_DECREF ((PyObject * )self -> bi );
4926
+ Py_DECREF (self -> null_slice );
4920
4927
PyObject_Del ((PyObject * )self );
4921
4928
}
4922
4929
@@ -4941,8 +4948,14 @@ BIIterBlock_iternext(BIIterBlockObject *self) {
4941
4948
if (self -> bi -> block_count <= i ) {
4942
4949
return NULL ;
4943
4950
}
4944
- Py_RETURN_NONE ;
4945
- // return AK_BI_item(self->bi, i); // return new ref
4951
+ // AK_build_pair_ssize_t_pyo steals the reference to the object; so incref here
4952
+ Py_INCREF (self -> null_slice );
4953
+ PyObject * t = AK_build_pair_ssize_t_pyo (i , self -> null_slice ); // return new ref
4954
+ if (t == NULL ) {
4955
+ // if tuple creation failed need to undo incref
4956
+ Py_DECREF (self -> null_slice );
4957
+ }
4958
+ return t ;
4946
4959
}
4947
4960
4948
4961
static PyObject *
@@ -5551,7 +5564,7 @@ BlockIndex_iter(BlockIndexObject* self) {
5551
5564
// Given key, return an iterator of a selection.
5552
5565
static PyObject *
5553
5566
BlockIndex_iter_select (BlockIndexObject * self , PyObject * selector ){
5554
- return BIIterSelector_new (self , selector , 0 , BIIS_UNKNOWN , 0 );
5567
+ return BIIterSelector_new (self , selector , false , BIIS_UNKNOWN , false );
5555
5568
}
5556
5569
5557
5570
static char * iter_contiguous_kargs_names [] = {
@@ -5566,7 +5579,7 @@ static PyObject*
5566
5579
BlockIndex_iter_contiguous (BlockIndexObject * self , PyObject * args , PyObject * kwargs )
5567
5580
{
5568
5581
PyObject * selector ;
5569
- int ascending = 0 ;
5582
+ int ascending = 0 ; // must be int for parsing to "p"
5570
5583
int reduce = 0 ;
5571
5584
5572
5585
if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
0 commit comments