FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MAINT: make PyUFuncObject.types const · numpy/numpy@c2c50b6 · GitHub

/ numpy Public

Commit c2c50b6

Browse files
committed
MAINT: make PyUFuncObject.types const
Numpy's internals do not modify this field, and C extensions that call `PyUFunc_FromFuncAndDataAndSignature` and friends are likely to pass a (static) const char array for the types argument. Make this field const so that calling code does not see discarded qualifier warnings.
1 parent d32d6fa commit c2c50b6

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎numpy/core/include/numpy/ufuncobject.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ typedef struct _tagPyUFuncObject {
120120
const char *name;
121121

122122
/* Array of type numbers, of size ('nargs' * 'ntypes') */
123-
char *types;
123+
const char *types;
124124

125125
/* Documentation string */
126126
const char *doc;

‎numpy/core/src/umath/dispatching.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ promote_and_get_info_and_ufuncimpl(PyUFuncObject *ufunc,
826826
* This check should ensure a the right error message, but in principle
827827
* we could try to call the loop getter here.
828828
*/
829-
char *types = ufunc->types;
829+
const char *types = ufunc->types;
830830
npy_bool loop_exists = NPY_FALSE;
831831
for (int i = 0; i < ufunc->ntypes; ++i) {
832832
loop_exists = NPY_TRUE; /* assume it exists, break if not */

‎numpy/core/src/umath/ufunc_object.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,7 @@ PyUFunc_ReplaceLoopBySignature(PyUFuncObject *func,
51585158
/*UFUNC_API*/
51595159
NPY_NO_EXPORT PyObject *
51605160
PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data,
5161-
char *types, int ntypes,
5161+
const char *types, int ntypes,
51625162
int nin, int nout, int identity,
51635163
const char *name, const char *doc, int unused)
51645164
{
@@ -5169,7 +5169,7 @@ PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data,
51695169
/*UFUNC_API*/
51705170
NPY_NO_EXPORT PyObject *
51715171
PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data,
5172-
char *types, int ntypes,
5172+
const char *types, int ntypes,
51735173
int nin, int nout, int identity,
51745174
const char *name, const char *doc,
51755175
int unused, const char *signature)
@@ -5182,7 +5182,7 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data,
51825182
/*UFUNC_API*/
51835183
NPY_NO_EXPORT PyObject *
51845184
PyUFunc_FromFuncAndDataAndSignatureAndIdentity(PyUFuncGenericFunction *func, void **data,
5185-
char *types, int ntypes,
5185+
const char *types, int ntypes,
51865186
int nin, int nout, int identity,
51875187
const char *name, const char *doc,
51885188
const int unused, const char *signature,
@@ -5287,7 +5287,7 @@ PyUFunc_FromFuncAndDataAndSignatureAndIdentity(PyUFuncGenericFunction *func, voi
52875287
}
52885288
}
52895289

5290-
char *curr_types = ufunc->types;
5290+
const char *curr_types = ufunc->types;
52915291
for (int i = 0; i < ntypes * (nin + nout); i += nin + nout) {
52925292
/*
52935293
* Add all legacy wrapping loops here. This is normally not necessary,

‎numpy/core/src/umath/ufunc_type_resolution.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ linear_search_type_resolver(PyUFuncObject *self,
19601960
*/
19611961
no_castable_output = 0;
19621962
for (i = 0; i < self->ntypes; ++i) {
1963-
char *orig_types = self->types + i*self->nargs;
1963+
const char *orig_types = self->types + i*self->nargs;
19641964

19651965
/* Copy the types into an int array for matching */
19661966
for (j = 0; j < nop; ++j) {
@@ -2042,7 +2042,7 @@ type_tuple_type_resolver_core(PyUFuncObject *self,
20422042
}
20432043

20442044
for (i = 0; i < self->ntypes; ++i) {
2045-
char *orig_types = self->types + i*self->nargs;
2045+
const char *orig_types = self->types + i*self->nargs;
20462046

20472047
/*
20482048
* Check specified types and copy into an int array for matching

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL