Skip to content

Commit

Permalink
build in release mode by default; fix bugs revealed
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Aug 18, 2023
1 parent ebbedec commit c7c1e35
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion stringdtype/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ per-file-ignores = {"__init__.py" = ["F401"]}

[tool.meson-python.args]
dist = []
setup = ["-Dbuildtype=debug"]
setup = []
compile = []
install = []
1 change: 1 addition & 0 deletions stringdtype/stringdtype/src/casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion stringdtype/stringdtype/src/dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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 */
};
Expand Down
17 changes: 11 additions & 6 deletions stringdtype/stringdtype/src/umath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c7c1e35

Please sign in to comment.