@@ -3293,21 +3293,24 @@ PyUFunc_Accumulate(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
3293
3293
dataptr_copy [1 ] = dataptr [1 ];
3294
3294
dataptr_copy [2 ] = dataptr [0 ];
3295
3295
3296
- /* Copy the first element to start the reduction */
3296
+ /*
3297
+ * Copy the first element to start the reduction.
3298
+ *
3299
+ * Output (dataptr[0]) and input (dataptr[1]) may point to
3300
+ * the same memory, e.g. np.add.accumulate(a, out=a).
3301
+ */
3297
3302
if (otype == NPY_OBJECT ) {
3298
3303
/*
3299
- * Input (dataptr[0]) and output (dataptr[1]) may point
3300
- * to the same memory (i.e. np.add.accumulate(a, out=a)).
3301
- * In that case need to incref before decref to avoid the
3302
- * possibility of the reference count being zero temporarily.
3304
+ * Incref before decref to avoid the possibility of the
3305
+ * reference count being zero temporarily.
3303
3306
*/
3304
3307
Py_XINCREF (* (PyObject * * )dataptr_copy [1 ]);
3305
3308
Py_XDECREF (* (PyObject * * )dataptr_copy [0 ]);
3306
3309
* (PyObject * * )dataptr_copy [0 ] =
3307
3310
* (PyObject * * )dataptr_copy [1 ];
3308
3311
}
3309
3312
else {
3310
- memcpy (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3313
+ memmove (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3311
3314
}
3312
3315
3313
3316
if (count_m1 > 0 ) {
@@ -3355,21 +3358,24 @@ PyUFunc_Accumulate(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
3355
3358
dataptr_copy [1 ] = PyArray_BYTES (op [1 ]);
3356
3359
dataptr_copy [2 ] = PyArray_BYTES (op [0 ]);
3357
3360
3358
- /* Copy the first element to start the reduction */
3361
+ /*
3362
+ * Copy the first element to start the reduction.
3363
+ *
3364
+ * Output (dataptr[0]) and input (dataptr[1]) may point to the
3365
+ * same memory, e.g. np.add.accumulate(a, out=a).
3366
+ */
3359
3367
if (otype == NPY_OBJECT ) {
3360
3368
/*
3361
- * Input (dataptr[0]) and output (dataptr[1]) may point
3362
- * to the same memory (i.e. np.add.accumulate(a, out=a, axis=0)).
3363
- * In that case need to incref before decref to avoid the
3364
- * possibility of the reference count being zero temporarily.
3369
+ * Incref before decref to avoid the possibility of the
3370
+ * reference count being zero temporarily.
3365
3371
*/
3366
3372
Py_XINCREF (* (PyObject * * )dataptr_copy [1 ]);
3367
3373
Py_XDECREF (* (PyObject * * )dataptr_copy [0 ]);
3368
3374
* (PyObject * * )dataptr_copy [0 ] =
3369
3375
* (PyObject * * )dataptr_copy [1 ];
3370
3376
}
3371
3377
else {
3372
- memcpy (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3378
+ memmove (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3373
3379
}
3374
3380
3375
3381
if (count > 1 ) {
@@ -3698,23 +3704,25 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
3698
3704
dataptr_copy [1 ] = dataptr [1 ] + stride1 * start ;
3699
3705
dataptr_copy [2 ] = dataptr [0 ] + stride0_ind * i ;
3700
3706
3701
- /* Copy the first element to start the reduction */
3707
+ /*
3708
+ * Copy the first element to start the reduction.
3709
+ *
3710
+ * Output (dataptr[0]) and input (dataptr[1]) may point
3711
+ * to the same memory, e.g.
3712
+ * np.add.reduceat(a, np.arange(len(a)), out=a).
3713
+ */
3702
3714
if (otype == NPY_OBJECT ) {
3703
3715
/*
3704
- * Input (dataptr[0]) and output (dataptr[1]) may
3705
- * point to the same memory, e.g.
3706
- * np.add.reduceat(a, np.arange(len(a)), out=a).
3707
- * In that case need to incref before decref to
3708
- * avoid the possibility of the reference count
3709
- * being zero temporarily.
3716
+ * Incref before decref to avoid the possibility of
3717
+ * the reference count being zero temporarily.
3710
3718
*/
3711
3719
Py_XINCREF (* (PyObject * * )dataptr_copy [1 ]);
3712
3720
Py_XDECREF (* (PyObject * * )dataptr_copy [0 ]);
3713
3721
* (PyObject * * )dataptr_copy [0 ] =
3714
3722
* (PyObject * * )dataptr_copy [1 ];
3715
3723
}
3716
3724
else {
3717
- memcpy (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3725
+ memmove (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3718
3726
}
3719
3727
3720
3728
if (count > 1 ) {
@@ -3764,23 +3772,25 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
3764
3772
dataptr_copy [1 ] = PyArray_BYTES (op [1 ]) + stride1 * start ;
3765
3773
dataptr_copy [2 ] = PyArray_BYTES (op [0 ]) + stride0_ind * i ;
3766
3774
3767
- /* Copy the first element to start the reduction */
3775
+ /*
3776
+ * Copy the first element to start the reduction.
3777
+ *
3778
+ * Output (dataptr[0]) and input (dataptr[1]) may point to
3779
+ * the same memory, e.g.
3780
+ * np.add.reduceat(a, np.arange(len(a)), out=a).
3781
+ */
3768
3782
if (otype == NPY_OBJECT ) {
3769
3783
/*
3770
- * Input (dataptr[0]) and output (dataptr[1]) may point
3771
- * to the same memory, e.g.
3772
- * np.add.reduceat(a, np.arange(len(a)), out=a).
3773
- * In that case need to incref before decref to avoid
3774
- * the possibility of the reference count being zero
3775
- * temporarily.
3784
+ * Incref before decref to avoid the possibility of the
3785
+ * reference count being zero temporarily.
3776
3786
*/
3777
3787
Py_XINCREF (* (PyObject * * )dataptr_copy [1 ]);
3778
3788
Py_XDECREF (* (PyObject * * )dataptr_copy [0 ]);
3779
3789
* (PyObject * * )dataptr_copy [0 ] =
3780
3790
* (PyObject * * )dataptr_copy [1 ];
3781
3791
}
3782
3792
else {
3783
- memcpy (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3793
+ memmove (dataptr_copy [0 ], dataptr_copy [1 ], itemsize );
3784
3794
}
3785
3795
3786
3796
if (count > 1 ) {
0 commit comments