@@ -598,32 +598,37 @@ def errmess(s: str) -> None:
598598 return ii;
599599}"""
600600cfuncs ['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) {
603603 int k;
604604 if (dims==NULL) return 0;
605605 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+
611615 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;
613617 }
614- forcombcache. i[0] = forcombcache. i_tr[nd-1] = -1;
618+ cache-> i[0] = cache-> i_tr[nd-1] = -1;
615619 return 1;
616620}
617- static int *nextforcomb(void) {
621+ static int *nextforcomb(struct ForcombCache *cache) {
622+ if (cache==NULL) return NULL;
618623 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;
623628 i[0]++;
624- if (i[0]==forcombcache. d[0]) {
629+ if (i[0]==cache-> d[0]) {
625630 j=1;
626- while ((j<nd) && (i[j]==forcombcache. d[j]-1)) j++;
631+ while ((j<nd) && (i[j]==cache-> d[j]-1)) j++;
627632 if (j==nd) {
628633 free(i);
629634 free(i_tr);
@@ -634,7 +639,7 @@ def errmess(s: str) -> None:
634639 i_tr[nd-j-1]++;
635640 } else
636641 i_tr[nd-1]++;
637- if (forcombcache. tr) return i_tr;
642+ if (cache-> tr) return i_tr;
638643 return i;
639644}"""
640645needs ['try_pyarr_from_string' ] = ['STRINGCOPYN' , 'PRINTPYOBJERR' , 'string' ]
0 commit comments