question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cython 0.29 broke support for C++ enum classes

See original GitHub issue

Before https://github.com/cython/cython/commit/be4ca1d685e8d703f2285183147f8587da56fe6d (a fix for #2186), on this input:

cpdef enum E "E":
    A

Cython was generating this:

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__E(enum E value) {
    const enum E neg_one = (enum E) -1, const_zero = (enum E) 0;

Since https://github.com/cython/cython/commit/6079a5b0b0936feb2ec339a1f31d7d708ae6d3a3 it is generating this:

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__E(enum E value) {
    const enum E neg_one = (enum E) ((enum E) 0 - (enum E) 1), const_zero = (enum E) 0;

This works for C enums, but fails to compile for C++ enum classes (https://godbolt.org/z/NY8PJT):

enum class E { X };
const enum E neg_one_class_28 = (enum E) -1;
const enum E neg_one_class_29 = (enum E) ((enum E) 0 - (enum E) 1);
<source>:3:54: error: invalid operands to binary expression ('enum E' and 'enum E')
const enum E neg_one_class_29 = (enum E) ((enum E) 0 - (enum E) 1);
                                          ~~~~~~~~~~ ^ ~~~~~~~~~~

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
orivejcommented, Dec 27, 2018

They are not fully supported: for example, it seems difficult to use enum class variables as function arguments; but what Cython already has is enough to wrap them. The original example in #1603 can be encoded like this:

cdef extern from "headername.h" namespace "lol::rofl":
    cdef enum rofl:
        SOMETHING
        MOAR

cdef void f(int arg):
    print(arg)

f(<int>rofl.MOAR)
0reactions
cf-natalicommented, Sep 1, 2020

https://github.com/cython/cython/pull/3803 fixes this (tested locally).

Read more comments on GitHub >

github_iconTop Results From Across the Web

defines as nameless enum in Cython (nested in struct)
I have the following code from a C header: typedef struct { /* struct description */ int type; /* variable purpose: */ #define...
Read more >
Cython Changelog — Cython 3.0.0a11 documentation
Improve compatibility between classes pickled in Cython 3.0 and 0.29.x by accepting MD5, ... C++17 execution policies are supported in libcpp.algorithm .
Read more >
Declare global variables and class attributes in pure ...
I'm using cython 0.29.12 and python 3.7.0. Also to resolve my issue with global variable, I try these different approaches without success:.
Read more >
Supported Python features
class definition: class (except for @jitclass); set, dict and generator comprehensions; generator delegation: yield from. Functions¶. Function calls ...
Read more >
Release Notes — NumPy v1.17 Manual
Downstream developers should use Cython >= 0.29.13 for Python 3.8 support and ... are very rare in practice and only available through the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found