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

Wrong enum conversion with cpdef enum (Cython language level=3) #3240

Open
EdwardSro opened this issue Nov 19, 2019 · 2 comments
Open

Wrong enum conversion with cpdef enum (Cython language level=3) #3240

EdwardSro opened this issue Nov 19, 2019 · 2 comments

Comments

@EdwardSro
Copy link

@EdwardSro EdwardSro commented Nov 19, 2019

When defining a cpdef enum in Cython, the enums seems to be considered as an int, meaning they are considered to be 32bit fields. Which is not always correct, for example if we have an external header file (test.h) with the following enum definition:

enum {
        ENUM_1 = ((uint64_t)(1 << 63)),
};

And if I try in my cython_test.pxd/pyx files to:

cdef extern from 'test.h':
        cpdef enum:
                 ENUM_1

The compilation ends with the warning:

In function 'PyInit_cython_test':
 warning: overflow in implicit constant conversion [-Woverflow]
PyObject* wrapped = __Pyx_PyInt_From_int(ENUM_1);

If I print the value on ENUM_1 in Cython's code it's really a 32bit, and the value of the original enum is cut !

@leofang

This comment has been minimized.

Copy link

@leofang leofang commented Nov 20, 2019

You are not complying with the C standard. enums should not be 64 bits.
https://stackoverflow.com/questions/366017/what-is-the-size-of-an-enum-in-c

@EdwardSro

This comment has been minimized.

Copy link
Author

@EdwardSro EdwardSro commented Nov 21, 2019

There are compiler extensions where larger (than int) enum values can be supported.
But Cython seems not to support that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.