[Cython] How to define C-consts in python module scope
Vitja Makarov
vitja.makarov at gmail.com
Mon Jul 18 19:07:22 CEST 2011
2011/7/18 Lisandro Dalcin <dalcinl at gmail.com>:
> On 18 July 2011 06:38, Vitja Makarov <vitja.makarov at gmail.com> wrote:
>> cdef enum:
>> EV_READ = 1
>> EV_WRITE = 2
>>
>> Is there a way to put this constants into module dict?
>> I want to access this constants from pure python code, I tried this way:
>>
>> globals()['EV_READ'] = EV_READ
>> globals()['EV_WRITE'] = EV_WRITE
>>
>> But I don't like it, is there any other way?
>>
>
> cdef public enum:
> EV_READ = 1
> EV_WRITE = 2
>
> However, I do not like it, because I would like to use "public" for
> other meaning (API generation). Also note that using "public" will
> trigger the generation of a header file.
>
This header breaks my code, I have ev.pyx that includes ev.h,
actually I can change that to <ev.h> but I don't like it this way too..
And it actually produces bad code for me:
/* "ev.pxd":3
* cimport libev
*
* cdef api enum: # <<<<<<<<<<<<<<
* EV_NONE = libev.EV_NONE
* EV_READ = libev.EV_READ
*/
enum {
/* "ev.pxd":6
* EV_NONE = libev.EV_NONE
* EV_READ = libev.EV_READ
* EV_WRITE = libev.EV_WRITE # <<<<<<<<<<<<<<
*
* cdef:
*/
EV_NONE = EV_NONE,
EV_READ = EV_READ,
EV_WRITE = EV_WRITE
};
> Perhaps we should support "cpdef enum: ..."
>
Yes, that would be nice.
--
vitja.
More information about the cython-devel
mailing list