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.

Compile error: using cpdef enum and typedef enum

See original GitHub issue

I observed a compilation error from clang-800.0.38 on a MacBook when using a c enum and a Cython cpdef enum. I could reproduce the issue using gcc version 4.9.2 (Raspbian 4.9.2-10). In both cases, Cython version 0.25.1 was used.

The code I ran was:

#lib.h
typedef enum { A, B, C, D} foo;
#lib.pyx
cdef extern from "./lib.h":
    cpdef enum foo:
        A, B, C, D

def t1():
    for e in foo: print(e.name)

When trying to compile, clang throws a lot of errors which all seem to correlate with the “enum foo”. A solution is to declare the enum in the .h file as following typedef enum foo { A, B, C, D} foo;or as typedef enum foo { A, B, C, D};. When changed, the code is compiled and linked to a .so file and is working as intended.

Is this intended behaviour or bug?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
embraycommented, Mar 19, 2018

+1 for some kind of “cptypedef”. Kinda ugly but I don’t see a better way…

2reactions
llchancommented, Feb 1, 2017

Is cptypedef something that we can add?

My current workaround is rather verbose, especially when there are a lot of enums values. It looks something like this:

cdef extern from './lib.h':
    ctypedef enum _foo 'foo':
        _A 'A'
        _B 'B'
        _C 'C'
        _D 'D'

cpdef enum foo:
    A = _A
    B = _B
    C = _C
    D = _D

My actual code is even more verbose because I prefix the ctypedef enum names so they don’t pollute the global namespace.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the reason for this Cython compile error when ...
I want to use a cpdef enum which creates a PEP 435 style Python Enum (available since Python 3.4). This feature was introduced...
Read more >
Developers - Compile error: using cpdef enum and typedef enum -
I observed a compilation error from clang-800.0.38 on a MacBook when using a c enum and a Cython cpdef enum. I could reproduce...
Read more >
cpdef enums can't be shared - Google Groups
When using a normal cdef enum these compile errors do not occur. #lib.h. typedef enum { A, B, C, D } test;. #test.pyx....
Read more >
What is the reason for this Cython compile error when ...
#lib.h file typedef enum { A, B, C, D } test; #lib.pyx file cdef extern from "lib.h": cpdef enum test: A, B, C,...
Read more >
Compiler Warning (level 1) C4920 - Microsoft Learn
If a .tlb that you pass to #import has the same symbol defined in two or more enums, this warning indicates that subsequent...
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