<
8000
button class="Button Button--iconOnly Button--invisible ExpandableHunkHeaderDiffLine-module__expand-button-line--rnQN5 ExpandableHunkHeaderDiffLine-module__expand-button-unified--j86KQ" aria-label="Expand file up from line 16" data-direction="up" aria-hidden="true" tabindex="-1">
@@ -16,6 +16,11 @@
16
16
17
17
#include "conversion_utils.h"
18
18
19
+ static int
20
+ PyArray_PyIntAsInt_ErrMsg (PyObject * o , const char * msg ) NPY_GCC_NONNULL (2 );
21
+ static npy_intp
22
+ PyArray_PyIntAsIntp_ErrMsg (PyObject * o , const char * msg ) NPY_GCC_NONNULL (2 );
23
+
19
24
/****************************************************************
20
25
* Useful function for conversion when used with PyArg_ParseTuple
21
26
****************************************************************/
@@ -215,8 +220,9 @@ PyArray_AxisConverter(PyObject *obj, int *axis)
215
220
* axis = NPY_MAXDIMS ;
216
221
}
217
222
else {
218
- * axis = PyArray_PyIntAsInt (obj );
219
- if (PyErr_Occurred ()) {
223
+ * axis = PyArray_PyIntAsInt_ErrMsg (obj ,
224
+ "an integer is required for the axis" );
225
+ if (error_converting (* axis )) {
220
226
return NPY_FAIL ;
221
227
}
222
228
}
@@ -251,7 +257,8 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
251
257
}
252
258
for (i = 0 ; i < naxes ; ++ i ) {
253
259
PyObject * tmp = PyTuple_GET_ITEM (axis_in , i );
254
- int axis = PyArray_PyIntAsInt (tmp );
260
+ int axis = PyArray_PyIntAsInt_ErrMsg (tmp ,
261
+ "integers are required for the axis tuple elements" );
255
262
int axis_orig = axis ;
256
263
if (error_converting (axis )) {
257
264
return NPY_FAIL ;
@@ -281,7 +288,8 @@ PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
281
288
282
289
memset (out_axis_flags , 0 , ndim );
283
290
284
- axis = PyArray_PyIntAsInt (axis_in );
291
+ axis = PyArray_PyIntAsInt_ErrMsg (axis_in ,
292
+ "an integer is required for the axis" );
285
293
axis_orig = axis ;
286
294
287
295
if (error_converting (axis )) {
@@ -736,13 +744,12 @@ PyArray_CastingConverter(PyObject *obj, NPY_CASTING *casting)
736
744
* Other conversion functions
737
745
*****************************/
738
746
739
- /*NUMPY_API*/
740
- NPY_NO_EXPORT int
741
- PyArray_PyIntAsInt (PyObject * o )
747
+ static int
748
+ PyArray_PyIntAsInt_ErrMsg (PyObject * o , const char * msg )
742
749
{
743
750
npy_intp long_value ;
744
751
/* This assumes that NPY_SIZEOF_INTP >= NPY_SIZEOF_INT */
745
- long_value = PyArray_PyIntAsIntp ( o );
752
+ long_value = PyArray_PyIntAsIntp_ErrMsg ( o , msg );
746
753
747
754
#if (NPY_SIZEOF_INTP > NPY_SIZEOF_INT )
748
755
if ((long_value < INT_MIN ) || (long_value > INT_MAX )) {
@@ -754,16 +761,21 @@ PyArray_PyIntAsInt(PyObject *o)
754
761
}
755
762
756
763
/*NUMPY_API*/
757
- NPY_NO_EXPORT npy_intp
758
- PyArray_PyIntAsIntp (PyObject * o )
764
+ NPY_NO_EXPORT int
765
+ PyArray_PyIntAsInt (PyObject * o )
766
+ {
767
+ return PyArray_PyIntAsInt_ErrMsg (o , "an integer is required" );
768
+ }
769
+
770
+ static npy_intp
771
+ PyArray_PyIntAsIntp_ErrMsg (PyObject * o , const char * msg )
759
772
{
760
773
#if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP )
761
774
long long long_value = -1 ;
762
775
#else
763
776
long long_value = -1 ;
764
777
#endif
765
778
PyObject * obj , * err ;
766
- static char * msg = "an integer is required" ;
767
779
768
780
if (!o ) {
769
781
PyErr_SetString (PyExc_TypeError , msg );
@@ -909,6 +921,13 @@ PyArray_PyIntAsIntp(PyObject *o)
909
921
return long_value ;
910
922
}
911
923
924
+ /*NUMPY_API*/
925
+ NPY_NO_EXPORT npy_intp
926
+ PyArray_PyIntAsIntp (PyObject * o )
927
+ {
928
+ return PyArray_PyIntAsIntp_ErrMsg (o , "an integer is required" );
929
+ }
930
+
912
931
913
932
/*
914
933
* PyArray_IntpFromIndexSequence
0 commit comments