1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #20 resolved

Better support for hexadecimal or implicit enum literals

Leonard Ritter
created an issue

While creating bindings for SDL (which I hope to be more of a cut-away job rather than a rewrite-headers job), I'm running into issues like these: {{{

!python

ffi.cdef(""" typedef enum SomeEnum { ONE = 0x0001, TWO = 0x0002, THREE = 0x0004, } SomeEnum_t; """) C = ffi.verify(""" typedef enum SomeEnum { ONE = 0x0001, TWO = 0x0002, THREE = 0x0004, } SomeEnum_t; """) assert C.ONE == 0x0001 assert C.TWO == 0x0002 assert C.HEX == 0x0004 }}}

causes {{{ ValueError: invalid literal for int() with base 10: '0x0001' }}}

It would be helpful to be able to either declare hexadecimal literals (which is a floor without bottom: other libs notate bit flags as (1<<0), (1<<2), or worse!), or just move straight to "...", if information can be augmented from the verify() step.

Comments (3)

  1. Leonard Ritter reporter

    Correction: "..." mostly serves for information to be discarded. It's not an implicit fill-in tool. I forgot. Is there a chance CFFI will understand most literal enum expressions one day?

  2. Log in to comment