Skip to content

Commit 6a1057c

Browse files
committed
void->quad gives error than segfault
1 parent d0620af commit 6a1057c

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
#include "casts.h"
2121
#include "dtype.h"
2222

23-
#define NUM_CASTS 29 // 14 to_casts + 14 from_casts + 1 quad_to_quad
23+
#define NUM_CASTS 30 // 14 to_casts + 14 from_casts + 1 quad_to_quad + 1 void_to_quad
2424

2525
static NPY_CASTING
2626
quad_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self),
@@ -717,6 +717,26 @@ add_cast_to(PyArray_DTypeMeta *from)
717717
add_spec(spec);
718718
}
719719

720+
static NPY_CASTING
721+
void_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self), PyArray_DTypeMeta *dtypes[2],
722+
PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2],
723+
npy_intp *view_offset)
724+
{
725+
PyErr_SetString(PyExc_TypeError,
726+
"Cannot cast void dtype to QuadPrecDType. "
727+
"Void arrays contain arbitrary binary data that cannot be meaningfully converted to quad-precision floats.");
728+
return (NPY_CASTING)-1;
729+
}
730+
731+
static int
732+
void_to_quad_strided_loop(PyArrayMethod_Context *context, char *const data[],
733+
npy_intp const dimensions[], npy_intp const strides[],
734+
void *NPY_UNUSED(auxdata))
735+
{
736+
PyErr_SetString(PyExc_RuntimeError, "void_to_quad_strided_loop should not be called");
737+
return -1;
738+
}
739+
720740
PyArrayMethod_Spec **
721741
init_casts_internal(void)
722742
{
@@ -739,6 +759,24 @@ init_casts_internal(void)
739759

740760
add_spec(quad2quad_spec);
741761

762+
PyArray_DTypeMeta **void_dtypes = new PyArray_DTypeMeta *[2]{&PyArray_VoidDType, &QuadPrecDType};
763+
PyType_Slot *void_slots = new PyType_Slot[]{
764+
{NPY_METH_resolve_descriptors, (void *)&void_to_quad_resolve_descriptors},
765+
{NPY_METH_strided_loop, (void *)&void_to_quad_strided_loop},
766+
{NPY_METH_unaligned_strided_loop, (void *)&void_to_quad_strided_loop},
767+
{0, nullptr}};
768+
769+
PyArrayMethod_Spec *void_spec = new PyArrayMethod_Spec{
770+
.name = "cast_Void_to_QuadPrec_ERROR",
771+
.nin = 1,
772+
.nout = 1,
773+
.casting = NPY_UNSAFE_CASTING,
774+
.flags = NPY_METH_SUPPORTS_UNALIGNED,
775+
.dtypes = void_dtypes,
776+
.slots = void_slots,
777+
};
778+
add_spec(void_spec);
779+
742780
add_cast_to<npy_bool>(&PyArray_BoolDType);
743781
add_cast_to<npy_byte>(&PyArray_ByteDType);
744782
add_cast_to<npy_short>(&PyArray_ShortDType);

quaddtype/reinstall.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if [ -d "build/" ]; then
88
rm -rf subprojects/sleef
99
fi
1010

11-
11+
export CFLAGS="-g -O0"
12+
export CXXFLAGS="-g -O0"
1213
python -m pip uninstall -y numpy_quaddtype
1314
python -m pip install . -v

0 commit comments

Comments
 (0)