Skip to content

Commit c42e350

Browse files
committed
MAINT: Add some const qualifiers to new DType related API
These are mostly for the places where we pass arrays.
1 parent dc33ac4 commit c42e350

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

numpy/_core/include/numpy/dtype_api.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct PyArrayMethod_Context_tag {
106106
struct PyArrayMethodObject_tag *method;
107107

108108
/* Operand descriptors, filled in by resolve_descriptors */
109-
PyArray_Descr **descriptors;
109+
PyArray_Descr *const *descriptors;
110110
/* Structure may grow (this is harmless for DType authors) */
111111
} PyArrayMethod_Context;
112112

@@ -159,9 +159,9 @@ typedef NPY_CASTING (PyArrayMethod_ResolveDescriptors)(
159159
/* "method" is currently opaque (necessary e.g. to wrap Python) */
160160
struct PyArrayMethodObject_tag *method,
161161
/* DTypes the method was created for */
162-
PyArray_DTypeMeta **dtypes,
162+
PyArray_DTypeMeta *const *dtypes,
163163
/* Input descriptors (instances). Outputs may be NULL. */
164-
PyArray_Descr **given_descrs,
164+
PyArray_Descr *const *given_descrs,
165165
/* Exact loop descriptors to use, must not hold references on error */
166166
PyArray_Descr **loop_descrs,
167167
npy_intp *view_offset);
@@ -177,9 +177,9 @@ typedef NPY_CASTING (PyArrayMethod_ResolveDescriptors)(
177177
*/
178178
typedef NPY_CASTING (PyArrayMethod_ResolveDescriptorsWithScalar)(
179179
struct PyArrayMethodObject_tag *method,
180-
PyArray_DTypeMeta **dtypes,
180+
PyArray_DTypeMeta *const *dtypes,
181181
/* Unlike above, these can have any DType and we may allow NULL. */
182-
PyArray_Descr **given_descrs,
182+
PyArray_Descr *const *given_descrs,
183183
/*
184184
* Input scalars or NULL. Only ever passed for python scalars.
185185
* WARNING: In some cases, a loop may be explicitly selected and the
@@ -227,7 +227,7 @@ typedef int (PyArrayMethod_GetLoop)(
227227
*/
228228
typedef int (PyArrayMethod_GetReductionInitial)(
229229
PyArrayMethod_Context *context, npy_bool reduction_is_empty,
230-
char *initial);
230+
void *initial);
231231

232232
/*
233233
* The following functions are only used by the wrapping array method defined
@@ -256,8 +256,8 @@ typedef int (PyArrayMethod_GetReductionInitial)(
256256
* `resolve_descriptors`, so that it can be filled there if not NULL.)
257257
*/
258258
typedef int (PyArrayMethod_TranslateGivenDescriptors)(int nin, int nout,
259-
PyArray_DTypeMeta *wrapped_dtypes[],
260-
PyArray_Descr *given_descrs[], PyArray_Descr *new_descrs[]);
259+
PyArray_DTypeMeta *const wrapped_dtypes[],
260+
PyArray_Descr *const given_descrs[], PyArray_Descr *new_descrs[]);
261261

262262
/**
263263
* The function to convert the actual loop descriptors (as returned by the
@@ -278,7 +278,7 @@ typedef int (PyArrayMethod_TranslateGivenDescriptors)(int nin, int nout,
278278
* @returns 0 on success, -1 on failure.
279279
*/
280280
typedef int (PyArrayMethod_TranslateLoopDescriptors)(int nin, int nout,
281-
PyArray_DTypeMeta *new_dtypes[], PyArray_Descr *given_descrs[],
281+
PyArray_DTypeMeta *const new_dtypes[], PyArray_Descr *const given_descrs[],
282282
PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
283283

284284

@@ -303,7 +303,7 @@ typedef int (PyArrayMethod_TranslateLoopDescriptors)(int nin, int nout,
303303
*
304304
*/
305305
typedef int (PyArrayMethod_TraverseLoop)(
306-
void *traverse_context, PyArray_Descr *descr, char *data,
306+
void *traverse_context, const PyArray_Descr *descr, char *data,
307307
npy_intp size, npy_intp stride, NpyAuxData *auxdata);
308308

309309

@@ -317,7 +317,7 @@ typedef int (PyArrayMethod_TraverseLoop)(
317317
*
318318
*/
319319
typedef int (PyArrayMethod_GetTraverseLoop)(
320-
void *traverse_context, PyArray_Descr *descr,
320+
void *traverse_context, const PyArray_Descr *descr,
321321
int aligned, npy_intp fixed_stride,
322322
PyArrayMethod_TraverseLoop **out_loop, NpyAuxData **out_auxdata,
323323
NPY_ARRAYMETHOD_FLAGS *flags);
@@ -334,7 +334,7 @@ typedef int (PyArrayMethod_GetTraverseLoop)(
334334
* (There are potential use-cases, these are currently unsupported.)
335335
*/
336336
typedef int (PyArrayMethod_PromoterFunction)(PyObject *ufunc,
337-
PyArray_DTypeMeta *op_dtypes[], PyArray_DTypeMeta *signature[],
337+
PyArray_DTypeMeta *const op_dtypes[], PyArray_DTypeMeta *const signature[],
338338
PyArray_DTypeMeta *new_op_dtypes[]);
339339

340340
/*

numpy/_core/include/numpy/npy_2_compat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,19 @@ DESCR_ACCESSOR(C_METADATA, c_metadata, NpyAuxData *, 1)
220220
#if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
221221
#if NPY_FEATURE_VERSION >= NPY_2_0_API_VERSION
222222
static inline PyArray_ArrFuncs *
223-
PyDataType_GetArrFuncs(PyArray_Descr *descr)
223+
PyDataType_GetArrFuncs(const PyArray_Descr *descr)
224224
{
225225
return _PyDataType_GetArrFuncs(descr);
226226
}
227227
#elif NPY_ABI_VERSION < 0x02000000
228228
static inline PyArray_ArrFuncs *
229-
PyDataType_GetArrFuncs(PyArray_Descr *descr)
229+
PyDataType_GetArrFuncs(const PyArray_Descr *descr)
230230
{
231231
return descr->f;
232232
}
233233
#else
234234
static inline PyArray_ArrFuncs *
235-
PyDataType_GetArrFuncs(PyArray_Descr *descr)
235+
PyDataType_GetArrFuncs(const PyArray_Descr *descr)
236236
{
237237
if (PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION) {
238238
return _PyDataType_GetArrFuncs(descr);

numpy/_core/src/multiarray/array_method.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
static NPY_CASTING
6060
default_resolve_descriptors(
6161
PyArrayMethodObject *method,
62-
PyArray_DTypeMeta **dtypes,
63-
PyArray_Descr **input_descrs,
62+
PyArray_DTypeMeta *const *dtypes,
63+
PyArray_Descr *const *input_descrs,
6464
PyArray_Descr **output_descrs,
6565
npy_intp *view_offset)
6666
{
@@ -139,7 +139,7 @@ npy_default_get_strided_loop(
139139
PyArrayMethod_StridedLoop **out_loop, NpyAuxData **out_transferdata,
140140
NPY_ARRAYMETHOD_FLAGS *flags)
141141
{
142-
PyArray_Descr **descrs = context->descriptors;
142+
PyArray_Descr *const *descrs = context->descriptors;
143143
PyArrayMethodObject *meth = context->method;
144144
*flags = meth->flags & NPY_METH_RUNTIME_FLAGS;
145145
*out_transferdata = NULL;

numpy/_core/src/multiarray/dtypemeta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ PyArray_DTypeMeta *_Void_dtype = NULL;
14001400
* for convenience as we are allowed to access the `DType` slots directly.
14011401
*/
14021402
NPY_NO_EXPORT PyArray_ArrFuncs *
1403-
_PyDataType_GetArrFuncs(PyArray_Descr *descr)
1403+
_PyDataType_GetArrFuncs(const PyArray_Descr *descr)
14041404
{
14051405
return PyDataType_GetArrFuncs(descr);
14061406
}

numpy/_core/src/multiarray/dtypemeta.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ extern PyArray_DTypeMeta PyArray_StringDType;
261261

262262
/* Internal version see dtypmeta.c for more information. */
263263
static inline PyArray_ArrFuncs *
264-
PyDataType_GetArrFuncs(PyArray_Descr *descr)
264+
PyDataType_GetArrFuncs(const PyArray_Descr *descr)
265265
{
266266
return &NPY_DT_SLOTS(NPY_DTYPE(descr))->f;
267267
}

0 commit comments

Comments
 (0)