Skip to content

[BUG] except * seems to get interpretted as except -1 for int return type #4770

@da-woods

Description

@da-woods

Describe the bug

When a function point is declared with an integer return type, it seems to end up with except ?-1 return type instead. I suspect that this translation is deliberately applied to cdef functions defined in Cython, and erroneously applied to function pointers too

To Reproduce
Code to reproduce the behaviour:

cdef extern from *:
    """
    int g0() {
        PyErr_SetString(PyExc_RuntimeError, "Oh no!");
        return 1;
    }
    """
    cdef int g0() except *

def test():
    cdef int (*fptr)() except *
    fptr = g0
    fptr()

Fails to compile with the error message

    fptr = g0
          ^
------------------------------------------------------------

fptr_cast.pyx:20:11: Cannot assign type 'int (void) except *' to 'int (*)(void) except? -1'

Expected behavior
It should compile

Environment (please complete the following information):

  • OS: Linux
  • Python version: 3.8.12 (but I doubt it matters)
  • Cython version: current master branch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions