@@ -598,32 +598,37 @@ def errmess(s: str) -> None:
598
598
return ii;
599
599
}"""
600
600
cfuncs ['forcomb' ] = """
601
- static struct { int nd;npy_intp *d;int *i,*i_tr,tr; } forcombcache ;
602
- static int initforcomb(npy_intp *dims,int nd,int tr) {
601
+ struct ForcombCache { int nd;npy_intp *d;int *i,*i_tr,tr; };
602
+ static int initforcomb(struct ForcombCache *cache, npy_intp *dims,int nd,int tr) {
603
603
int k;
604
604
if (dims==NULL) return 0;
605
605
if (nd<0) return 0;
606
- forcombcache.nd = nd;
607
- forcombcache.d = dims;
608
- forcombcache.tr = tr;
609
- if ((forcombcache.i = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
610
- if ((forcombcache.i_tr = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
606
+ cache->nd = nd;
607
+ cache->d = dims;
608
+ cache->tr = tr;
609
+
610
+ cache->i = (int *)malloc(sizeof(int)*nd);
611
+ if (cache->i==NULL) return 0;
612
+ cache->i_tr = (int *)malloc(sizeof(int)*nd);
613
+ if (cache->i_tr==NULL) {free(cache->i); return 0;};
614
+
611
615
for (k=1;k<nd;k++) {
612
- forcombcache. i[k] = forcombcache. i_tr[nd-k-1] = 0;
616
+ cache-> i[k] = cache-> i_tr[nd-k-1] = 0;
613
617
}
614
- forcombcache. i[0] = forcombcache. i_tr[nd-1] = -1;
618
+ cache-> i[0] = cache-> i_tr[nd-1] = -1;
615
619
return 1;
616
620
}
617
- static int *nextforcomb(void) {
621
+ static int *nextforcomb(struct ForcombCache *cache) {
622
+ if (cache==NULL) return NULL;
618
623
int j,*i,*i_tr,k;
619
- int nd=forcombcache. nd;
620
- if ((i=forcombcache. i) == NULL) return NULL;
621
- if ((i_tr=forcombcache. i_tr) == NULL) return NULL;
622
- if (forcombcache. d == NULL) return NULL;
624
+ int nd=cache-> nd;
625
+ if ((i=cache-> i) == NULL) return NULL;
626
+ if ((i_tr=cache-> i_tr) == NULL) return NULL;
627
+ if (cache-> d == NULL) return NULL;
623
628
i[0]++;
624
- if (i[0]==forcombcache. d[0]) {
629
+ if (i[0]==cache-> d[0]) {
625
630
j=1;
626
- while ((j<nd) && (i[j]==forcombcache. d[j]-1)) j++;
631
+ while ((j<nd) && (i[j]==cache-> d[j]-1)) j++;
627
632
if (j==nd) {
628
633
free(i);
629
634
free(i_tr);
@@ -634,7 +639,7 @@ def errmess(s: str) -> None:
634
639
i_tr[nd-j-1]++;
635
640
} else
636
641
i_tr[nd-1]++;
637
- if (forcombcache. tr) return i_tr;
642
+ if (cache-> tr) return i_tr;
638
643
return i;
639
644
}"""
640
645
needs ['try_pyarr_from_string' ] = ['STRINGCOPYN' , 'PRINTPYOBJERR' , 'string' ]
0 commit comments