Commits

Simon Sapin committed 5e7df71

Map anonymous enum values to FFILibrary attributes.

Without this patch, this code gives an error:

from cffi import FFI
ffi = FFI()
ffi.cdef('typedef enum lipsum { LOREM, IPSUM } lipsum_t;'
'typedef enum { FOO, BAR } fb_t;')
lib = ffi.dlopen('m')
assert lib.IPSUM == 1 # Ok :)
assert lib.BAR == 1 # AttributeError :(

  • Participants
  • Parent commits c4ddde5

Comments (0)

Files changed (1)

         #
         if not copied_enums:
             for key, tp in ffi._parser._declarations.items():
-                if not key.startswith('enum '):
+                if not key.startswith(('enum ', 'anonymous ')):
                     continue
                 for enumname, enumval in zip(tp.enumerators, tp.enumvalues):
                     if enumname not in library.__dict__: