summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-12-05 22:49:16 +0100
committerGitHub <noreply@github.com>2022-12-05 22:49:16 +0100
commitf74b3720ca6148574da40ed96d4712e221ee84bd (patch)
tree465155a04f1cce3c644426d5ec65e4a648856ee3
parent38e7ab816b385befe1a410d6c0467c7f26a4e8ad (diff)
parent7d4cfcfdbb3cab0cd7ab7460defd70ea34a6a25a (diff)
downloadnumpy-f74b3720ca6148574da40ed96d4712e221ee84bd.tar.gz
Merge pull request #22738 from ngoldbaum/dtype-casts-error
MAINT: check if PyArrayDTypeMeta_Spec->casts is set
-rw-r--r--numpy/core/src/multiarray/experimental_public_dtype_api.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/experimental_public_dtype_api.c b/numpy/core/src/multiarray/experimental_public_dtype_api.c
index 79261a9a7..84507b481 100644
--- a/numpy/core/src/multiarray/experimental_public_dtype_api.c
+++ b/numpy/core/src/multiarray/experimental_public_dtype_api.c
@@ -258,6 +258,14 @@ PyArrayInitDTypeMeta_FromSpec(
/*
* And now, register all the casts that are currently defined!
*/
+ if (spec->casts == NULL) {
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "DType must at least provide a function to cast (or just copy) "
+ "between its own instances!");
+ return -1;
+ }
+
PyArrayMethod_Spec **next_meth_spec = spec->casts;
while (1) {
PyArrayMethod_Spec *meth_spec = *next_meth_spec;