@@ -702,15 +702,14 @@ check_and_fix_dimensions(const PyArrayObject *arr, const int rank,
702
702
npy_intp * dims );
703
703
704
704
static int
705
- count_negative_dimensions (const int rank , const npy_intp * dims )
705
+ find_first_negative_dimension (const int rank , const npy_intp * dims )
706
706
{
707
- int i = 0 , r = 0 ;
708
- while (i < rank ) {
709
- if (dims [i ] < 0 )
710
- ++ r ;
711
- ++ i ;
707
+ for (int i = 0 ; i < rank ; ++ i ) {
708
+ if (dims [i ] < 0 ) {
709
+ return i ;
710
+ }
712
711
}
713
- return r ;
712
+ return -1 ;
714
713
}
715
714
716
715
#ifdef DEBUG_COPY_ND_ARRAY
@@ -795,15 +794,12 @@ array_from_pyobj(const int type_num, npy_intp *dims, const int rank,
795
794
((intent & F2PY_INTENT_CACHE ) && (obj == Py_None )) ||
796
795
((intent & F2PY_OPTIONAL ) && (obj == Py_None ))) {
797
796
/* intent(cache), optional, intent(hide) */
798
- if (count_negative_dimensions (rank , dims ) > 0 ) {
799
- int i ;
800
- strcpy (mess ,
801
- "failed to create intent(cache|hide)|optional array"
802
- "-- must have defined dimensions but got (" );
803
- for (i = 0 ; i < rank ; ++ i )
804
- sprintf (mess + strlen (mess ), "%" NPY_INTP_FMT "," , dims [i ]);
805
- strcat (mess , ")" );
806
- PyErr_SetString (PyExc_ValueError , mess );
797
+ int i = find_first_negative_dimension (rank , dims );
798
+ if (i >= 0 ) {
799
+ PyErr_Format (PyExc_ValueError ,
800
+ "failed to create intent(cache|hide)|optional array"
801
+ " -- must have defined dimensions, but dims[%d] = %"
802
+ NPY_INTP_FMT , i , dims [i ]);
807
803
return NULL ;
808
804
}
809
805
arr = (PyArrayObject * )PyArray_New (& PyArray_Type , rank , dims , type_num ,
0 commit comments