Skip to content

Segfault when registering gufunc with signature "()->(4)" in C (with numpy 1.15) #14949

@jorisvandenbossche

Description

@jorisvandenbossche

In PyGEOS, we are writing (g)ufuncs in C, and are running into a problem with a generalized ufunc on older numpy versions: pygeos/pygeos#69

We are defining a generalized ufunc with a ()->(4) signature. With numpy 1.17 this works fine, but with older numpy (tested 1.15 locally, and on travis also 1.13) it is failing.
It doesn't fail when running, but already segfaults when registering the ufunc with that signature (to be more precise: it segfaults on importing the python package that on import loads the extension module that registers the ufuncs).

We are doing something like (the full diff can be seen in the issue linked above):

ufunc = PyUFunc_FromFuncAndDataAndSignature(
    bounds_funcs, null_data, bounds_dtypes, 1, 1, 1, PyUFunc_None,
    "bounds", "", 0, "()->(4)");
PyDict_SetItemString(d, "bounds", ufunc)

and there doesn't seem to be anything wrong with the inner functions and dtypes (bounds_funcs and bounds_dtypes), because if I change the signature from "()->(4)" to "()->()", it actually "works" (it no longer segfaults on registration, and it runs, only giving a wrong (partly) result).

I know this is a rather vague issue description, and in addition only happens for older numpy (but still, as a dependent library, we would like to support a range of numpy versions). But:

  • Was there a known problems with signatures like "()->(4)"? Or was this not a supported signature?
  • Would there be a workaround to still do something like this with older numpy versions like 1.15?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions