From c7c1e35d7699b8aba142e3230ce04dd04ad68e72 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Fri, 18 Aug 2023 10:50:42 -0600 Subject: [PATCH] build in release mode by default; fix bugs revealed --- stringdtype/pyproject.toml | 2 +- stringdtype/stringdtype/src/casts.c | 1 + stringdtype/stringdtype/src/dtype.c | 19 ++++++++++++++++++- stringdtype/stringdtype/src/umath.c | 17 +++++++++++------ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/stringdtype/pyproject.toml b/stringdtype/pyproject.toml index 014235a7..10b172d7 100644 --- a/stringdtype/pyproject.toml +++ b/stringdtype/pyproject.toml @@ -35,6 +35,6 @@ per-file-ignores = {"__init__.py" = ["F401"]} [tool.meson-python.args] dist = [] -setup = ["-Dbuildtype=debug"] +setup = [] compile = [] install = [] diff --git a/stringdtype/stringdtype/src/casts.c b/stringdtype/stringdtype/src/casts.c index 399b1047..a90d749f 100644 --- a/stringdtype/stringdtype/src/casts.c +++ b/stringdtype/stringdtype/src/casts.c @@ -388,6 +388,7 @@ string_to_unicode(PyArrayMethod_Context *context, char *const data[], } else { this_string = (unsigned char *)(default_string.buf); + n_bytes = default_string.len; } } else { diff --git a/stringdtype/stringdtype/src/dtype.c b/stringdtype/stringdtype/src/dtype.c index 61ed7919..bf54ea77 100644 --- a/stringdtype/stringdtype/src/dtype.c +++ b/stringdtype/stringdtype/src/dtype.c @@ -661,7 +661,7 @@ StringDType_richcompare(PyObject *self, PyObject *other, int op) StringDTypeObject *sself = (StringDTypeObject *)self; StringDTypeObject *sother = (StringDTypeObject *)other; - int eq; + int eq = 0; PyObject *sna = sself->na_object; PyObject *ona = sother->na_object; @@ -706,6 +706,22 @@ StringDType_richcompare(PyObject *self, PyObject *other, int op) return ret; } +static Py_hash_t +StringDType_hash(StringDTypeObject *self) +{ + PyObject *hash_tup = NULL; + if (self->na_object != NULL) { + hash_tup = Py_BuildValue("(iO)", self->coerce, self->na_object); + } + else { + hash_tup = Py_BuildValue("(i)", self->coerce); + } + + Py_hash_t ret = PyObject_Hash(hash_tup); + Py_DECREF(hash_tup); + return ret; +} + /* * This is the basic things that you need to create a Python Type/Class in C. * However, there is a slight difference here because we create a @@ -724,6 +740,7 @@ StringDType_type StringDType = { .tp_methods = StringDType_methods, .tp_members = StringDType_members, .tp_richcompare = StringDType_richcompare, + .tp_hash = StringDType_hash, }}}, /* rest, filled in during DTypeMeta initialization */ }; diff --git a/stringdtype/stringdtype/src/umath.c b/stringdtype/stringdtype/src/umath.c index 476b4440..77f0cceb 100644 --- a/stringdtype/stringdtype/src/umath.c +++ b/stringdtype/stringdtype/src/umath.c @@ -871,17 +871,22 @@ init_ufunc(PyObject *numpy, const char *ufunc_name, PyArray_DTypeMeta **dtypes, .casting = casting, .flags = flags, .dtypes = dtypes, + .slots = NULL, }; + PyType_Slot resolve_slots[] = { + {NPY_METH_resolve_descriptors, resolve_func}, + {NPY_METH_strided_loop, loop_func}, + {0, NULL}}; + + PyType_Slot strided_slots[] = {{NPY_METH_strided_loop, loop_func}, + {0, NULL}}; + if (resolve_func == NULL) { - PyType_Slot slots[] = {{NPY_METH_strided_loop, loop_func}, {0, NULL}}; - spec.slots = slots; + spec.slots = strided_slots; } else { - PyType_Slot slots[] = {{NPY_METH_resolve_descriptors, resolve_func}, - {NPY_METH_strided_loop, loop_func}, - {0, NULL}}; - spec.slots = slots; + spec.slots = resolve_slots; } if (PyUFunc_AddLoopFromSpec(ufunc, &spec) < 0) {