@@ -3656,7 +3656,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3656
3656
int i , naxes = 0 , ndim ;
3657
3657
int axes [NPY_MAXDIMS ];
3658
3658
PyObject * axes_in = NULL ;
3659
- PyArrayObject * mp , * ret = NULL ;
3659
+ PyArrayObject * mp = NULL , * ret = NULL ;
3660
3660
PyObject * op , * res = NULL ;
3661
3661
PyObject * obj_ind , * context ;
3662
3662
PyArrayObject * indices = NULL ;
@@ -3712,19 +3712,17 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3712
3712
PyArray_Descr * indtype ;
3713
3713
indtype = PyArray_DescrFromType (NPY_INTP );
<
10000
/td>3714
3714
if (!PyArg_ParseTupleAndKeywords (args , kwds , "OO|OO&O&:reduceat" , reduceat_kwlist ,
3715
- & op ,
3716
- & obj_ind ,
3717
- & axes_in ,
3718
- PyArray_DescrConverter2 , & otype ,
3719
- PyArray_OutputConverter , & out )) {
3720
- Py_XDECREF (otype );
3721
- return NULL ;
3715
+ & op ,
3716
+ & obj_ind ,
3717
+ & axes_in ,
3718
+ PyArray_DescrConverter2 , & otype ,
3719
+ PyArray_OutputConverter , & out )) {
3720
+ goto fail ;
3722
3721
}
3723
3722
indices = (PyArrayObject * )PyArray_FromAny (obj_ind , indtype ,
3724
3723
1 , 1 , NPY_ARRAY_CARRAY , NULL );
3725
3724
if (indices == NULL ) {
3726
- Py_XDECREF (otype );
3727
- return NULL ;
3725
+ goto fail ;
3728
3726
}
3729
3727
}
3730
3728
else if (operation == UFUNC_ACCUMULATE ) {
@@ -3734,8 +3732,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3734
3732
& axes_in ,
3735
3733
PyArray_DescrConverter2 , & otype ,
3736
3734
PyArray_OutputConverter , & out )) {
3737
- Py_XDECREF (otype );
3738
- return NULL ;
3735
+ goto fail ;
3739
3736
}
3740
3737
}
3741
3738
else {
@@ -3746,8 +3743,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3746
3743
PyArray_DescrConverter2 , & otype ,
3747
3744
PyArray_OutputConverter , & out ,
3748
3745
& keepdims )) {
3749
- Py_XDECREF (otype );
3750
- return NULL ;
3746
+ goto fail ;
3751
3747
}
3752
3748
}
3753
3749
/* Ensure input is an array */
@@ -3760,7 +3756,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3760
3756
mp = (PyArrayObject * )PyArray_FromAny (op , NULL , 0 , 0 , 0 , context );
3761
3757
Py_XDECREF (context );
3762
3758
if (mp == NULL ) {
3763
- return NULL ;
3759
+ goto fail ;
3764
3760
}
3765
3761
3766
3762
ndim = PyArray_NDIM (mp );
@@ -3771,9 +3767,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3771
3767
PyErr_Format (PyExc_TypeError ,
3772
3768
"cannot perform %s with flexible type" ,
3773
3769
_reduce_type [operation ]);
3774
- Py_XDECREF (otype );
3775
- Py_DECREF (mp );
3776
- return NULL ;
3770
+ goto fail ;
3777
3771
}
3778
3772
3779
3773
/* Convert the 'axis' parameter into a list of axes */
@@ -3793,22 +3787,16 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3793
3787
if (naxes < 0 || naxes > NPY_MAXDIMS ) {
3794
3788
PyErr_SetString (PyExc_ValueError ,
3795
3789
"too many values for 'axis'" );
3796
- Py_XDECREF (otype );
3797
- Py_DECREF (mp );
3798
- return NULL ;
3790
+ goto fail ;
3799
3791
}
3800
3792
for (i = 0 ; i < naxes ; ++ i ) {
3801
3793
PyObject * tmp = PyTuple_GET_ITEM (axes_in , i );
3802
3794
int axis = PyArray_PyIntAsInt (tmp );
3803
3795
if (error_converting (axis )) {
3804
- Py_XDECREF (otype );
3805
- Py_DECREF (mp );
3806
- return NULL ;
3796
+ goto fail ;
3807
3797
}
3808
3798
if (check_and_adjust_axis (& axis , ndim ) < 0 ) {
3809
- Py_XDECREF (otype );
3810
- Py_DECREF (mp );
3811
- return NULL ;
3799
+ goto fail ;
3812
3800
}
3813
3801
axes [i ] = (int )axis ;
3814
3802
}
@@ -3818,18 +3806,14 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3818
3806
int axis = PyArray_PyIntAsInt (axes_in );
3819
3807
/* TODO: PyNumber_Index would be good to use here */
3820
3808
if (error_converting (axis )) {
3821
- Py_XDECREF (otype );
3822
- Py_DECREF (mp );
3823
- return NULL ;
3809
+ goto fail ;
3824
3810
}
3825
3811
/* Special case letting axis={0 or -1} slip through for scalars */
3826
3812
if (ndim == 0 && (axis == 0 || axis == -1 )) {
3827
3813
axis = 0 ;
3828
3814
}
3829
3815
else if (check_and_adjust_axis (& axis , ndim ) < 0 ) {
3830
- Py_XDECREF (otype );
3831
- Py_DECREF (mp );
3832
- return NULL ;
3816
+ goto fail ;
3833
3817
}
3834
3818
axes [0 ] = (int )axis ;
3835
3819
naxes = 1 ;
@@ -3849,9 +3833,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3849
3833
(naxes == 0 || (naxes == 1 && axes [0 ] == 0 )))) {
3850
3834
PyErr_Format (PyExc_TypeError , "cannot %s on a scalar" ,
3851
3835
_reduce_type [operation ]);
3852
- Py_XDECREF (otype );
3853
- Py_DECREF (mp );
3854
- return NULL ;
3836
+ goto fail ;
3855
3837
}
3856
3838
}
3857
3839
@@ -3897,9 +3879,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3897
3879
if (naxes != 1 ) {
3898
3880
PyErr_SetString (PyExc_ValueError ,
3899
3881
"accumulate does not allow multiple axes" );
3900
- Py_XDECREF (otype );
3901
- Py_DECREF (mp );
3902
- return NULL ;
3882
+ goto fail ;
3903
3883
}
3904
3884
ret = (PyArrayObject * )PyUFunc_Accumulate (ufunc , mp , out , axes [0 ],
3905
3885
otype -> type_num );
@@ -3908,9 +3888,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3908
3888
if (naxes != 1 ) {
3909
3889
PyErr_SetString (PyExc_ValueError ,
3910
3890
"reduceat does not allow multiple axes" );
3911
- Py_XDECREF (otype );
3912
- Py_DECREF (mp );
3913
- return NULL ;
3891
+ goto fail ;
3914
3892
}
3915
3893
ret = (PyArrayObject * )PyUFunc_Reduceat (ufunc , mp , indices , out ,
3916
3894
axes [0 ], otype -> type_num );
@@ -3943,6 +3921,11 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
3943
3921
}
3944
3922
}
3945
3923
return PyArray_Return (ret );
3924
+
3925
+ fail :
3926
+ Py_XDECREF (otype );
3927
+ Py_XDECREF (mp );
3928
+ return NULL ;
3946
3929
}
3947
3930
3948
3931
/*
0 commit comments