Issue 27 in ctypesgen: enum types issue

15 views
Skip to first unread message

codesite...@google.com

unread,
Feb 13, 2012, 8:44:22 AM2/13/12
to ctyp...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 27 by l...@segv.dk: enum types issue
http://code.google.com/p/ctypesgen/issues/detail?id=27

Consider the following header:

---------------------
enum testenum_e {
dummy0=0,
dummy1,
};

struct teststruct_s {
int dummy;
};
---------------------

This will give me the following object types in python:
enum_testenum_e
struct_teststruct_s
teststruct_s

But no "testenum_e" object type. To get "testenum_e" I need to typedef the
enum. I think it would be an good idea if the above header would produce
an "testenum_e = enum_testenum_e" without having to specify the typedef
(btw ctypeslib behaves like this).

If someone could point me in the right direction I'll be happy to provide a
patch.

This is tested on Ubuntu 11.10 x86_64 with Python 2.7.2+ and ctypesgen r137.


Timothy Maxwell

unread,
Feb 13, 2012, 11:58:41 AM2/13/12
to ctyp...@googlegroups.com
The automatically_typedef_structs() function is doing the typedeffing
for structs. You could create an equivalent function for enums.

Tim

codesite...@google.com

unread,
Mar 21, 2012, 2:24:49 PM3/21/12
to ctyp...@googlegroups.com

Comment #1 on issue 27 by l...@segv.dk: enum types issue
http://code.google.com/p/ctypesgen/issues/detail?id=27

I poked around ctypesgen a bit and made a small patch that solves my issue.
Comments?

Attachments:
add.enum.typedef.patch 738 bytes

codesite...@google.com

unread,
Mar 22, 2012, 12:41:15 PM3/22/12
to ctyp...@googlegroups.com

Comment #2 on issue 27 by TimM...@gmail.com: enum types issue
http://code.google.com/p/ctypesgen/issues/detail?id=27

Other than the obvious typo, it looks good. I would also rename
the "struct" variable to "object" and "automatically_typedef_structs()"
to "automatically_typedef_structs_and_enums()", but that's a matter of
taste. Also, I didn't test it; I assume you did.

codesite...@google.com

unread,
Mar 22, 2012, 3:33:24 PM3/22/12
to ctyp...@googlegroups.com

Comment #3 on issue 27 by l...@segv.dk: enum types issue
http://code.google.com/p/ctypesgen/issues/detail?id=27

I agree. My first patch was just to check if I was on the right track with
this fix.

I also fixed the: # XXX Check if it has already been aliased in the C code.

New patch attached.


Attachments:
add.enum.typedef.v2.patch 2.3 KB

codesite...@google.com

unread,
Apr 3, 2012, 5:00:34 AM4/3/12
to ctyp...@googlegroups.com

Comment #4 on issue 27 by l...@segv.dk: enum types issue
http://code.google.com/p/ctypesgen/issues/detail?id=27

I have been running with the attached patch for a while and all looks good.
Changes since v2 is the removal of a debug print.

Please apply.

Attachments:
add.enum.typedef.v3.patch 2.3 KB

Reply all
Reply to author
Forward
0 new messages