Skip to content

Add values to enum entries#4

Open
XL64 wants to merge 1 commit intogeggo:masterfrom
XL64:master
Open

Add values to enum entries#4
XL64 wants to merge 1 commit intogeggo:masterfrom
XL64:master

Conversation

@XL64
Copy link

@XL64 XL64 commented Jul 15, 2013

Hello,

In our C code we give values to our enum entries, I modified cwrap so that it takes those values.
This code break some tests but I think it's not a big deal, it just add values to enum where there wasn't.

eg.:

enum toto {
enum1,
enum2,
enum3
};

will give

ctypedef enum toto:
enum1 = 0
enum2 = 1
enum3 = 2

Thanks for all your work,

XL.

@geggo
Copy link
Owner

geggo commented Jul 16, 2013

Hi Xavier,

thanks for offering this possibility to expose enum values. I am curious what is the advantage you see in this change? I once thought about this, but I fear some problems that could arise: enum values could get inconsistent if the header file is changed (don't know whether cython actually makes use of the enum values). To be on the safe side, I would prefer putting the values into comments, and only for values which have been explicitly set in the header file.
thanks for your contribution
Gregor

@XL64
Copy link
Author

XL64 commented Jul 17, 2013

Hi Gregor,

In my header I have enums like this

enum name {
field1 = 1024,
field2 = 1025,
...
}

So it the enum start from 0 in Cython it leads to incompatibility. right ?

I agree with you values should only be there is explicitly set in C header file but I didn't no how to know it as the value field is always filled.

Have a nice day,

XL.
Le 17 juil. 2013 à 00:22, geggo a écrit :

Hi Xavier,

thanks for offering this possibility to expose enum values. I am curious what is the advantage you see in this change? I once thought about this, but I fear some problems that could arise: enum values could get inconsistent if the header file is changed (don't know whether cython actually makes use of the enum values). To be on the safe side, I would prefer putting the values into comments, and only for values which have been explicitly set in the header file.
thanks for your contribution
Gregor


Reply to this email directly or view it on GitHub.

@geggo
Copy link
Owner

geggo commented Jul 17, 2013

Hi Xavier,

if you have explicitly defined enum values in your C header file, then it is not necessary to repeat them in the pxd file. So it seems your patch is not necessary to create correct cython code.

It is true that the value field is always filled, but if you find an INTEGER_LITERAL child of an ENUM_CONST_DECL, you know it has been explicitly set. You can observe this if you run

python libclang_show_ast.py tests/test_enums.h

Gregor

@XL64
Copy link
Author

XL64 commented Jul 17, 2013

Hi Gregor,

I'm not familiar with Cython, sorry...

So you can forget my pull request as it's not needed.

Thanks again,

XL.
Le 17 juil. 2013 à 09:37, geggo a écrit :

Hi Xavier,

if you have explicitly defined enum values in your C header file, then it is not necessary to repeat them in the pxd file. So it seems your patch is not necessary to create correct cython code.

It is true that the value field is always filled, but if you find an INTEGER_LITERAL child of an ENUM_CONST_DECL, you know it has been explicitly set. You can observe this if you run

python libclang_show_ast.py tests/test_enums.h

Gregor


Reply to this email directly or view it on GitHub.

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 this pull request may close these issues.

2 participants