Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] values used for exception_value are really inconsistent #5709

Closed
da-woods opened this issue Sep 17, 2023 · 1 comment · Fixed by #5710
Closed

[BUG] values used for exception_value are really inconsistent #5709

da-woods opened this issue Sep 17, 2023 · 1 comment · Fixed by #5710
Assignees

Comments

@da-woods
Copy link
Contributor

da-woods commented Sep 17, 2023

Describe the bug

This is something I'm running into while trying to sort out implicit exception_value for fused types. But it's a general problem not related to fused functions.

Essentially for floating point types, Cython uses a number of different representations of the exception value, and this leads to mismatches where there should be no mismatch

Code to reproduce the behaviour:

cdef double return_double(double arg, bint fail):
    if fail:
        raise RuntimeError
    return arg

ctypedef double (*func_ptr1)(double, bint) except? -1

def test():
    # Test that we can assign to the function pointer we expect
    cdef func_ptr1 p1 = return_double

This fails with

Error compiling Cython file:
------------------------------------------------------------
...

ctypedef double (*func_ptr1)(double, bint) except? -1

def test():
    # Test that we can assign to the function pointer we expect
    cdef func_ptr1 p1 = return_double
                        ^
------------------------------------------------------------

fused_rettype3.pyx:10:24: Cannot assign type 'double (double, bool) except? -1' to 'func_ptr1'. Exception values are incompatible.

The reason is that the type for return_double has an exception_value of '-1' (note a str).
The type for func_ptr1 has an exception_value of '-1.0' (note also a str).

Therefore they're "incompatible" and the assignment fails.

Expected behaviour

No response

OS

No response

Python version

No response

Cython version

Current master

Additional context

I think the mistake is using strings to represent exception_value

@da-woods da-woods self-assigned this Sep 17, 2023
da-woods added a commit to da-woods/cython that referenced this issue Sep 17, 2023
The main advantage is that we don't end up hugely sensitive to
the exact string representation of a particular number.

Fixes cython#5709
@scoder
Copy link
Contributor

scoder commented Sep 17, 2023

I think the mistake is using strings to represent exception_value

Not entirely a mistake. You can have an exception value that is an enum name, for example. So, if we start using numeric values, we'll still have to deal with strings, but then in combination with different numeric data types.

da-woods added a commit that referenced this issue Mar 7, 2024
The main advantage is that we don't end up hugely sensitive to
the exact string representation of a particular number.

Fixes #5709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants