dotdotdot cannot be used in typedefed arrays

Issue #285 resolved
Avi B
created an issue

dotdotdot cannot be used in typedefed arrays

e.g

ffi.set_source("typedef int MyArr[10 / 2];")
ffi.cdef("typedef int MyArr[...];")

ffi.compile()

trace:

  File "C:\Python27\lib\site-packages\cffi\api.py", line 105, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "C:\Python27\lib\site-packages\cffi\api.py", line 119, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "C:\Python27\lib\site-packages\cffi\cparser.py", line 299, in parse
    self._internal_parse(csource)
  File "C:\Python27\lib\site-packages\cffi\cparser.py", line 335, in _internal_p
arse
    decl.type, name=decl.name)
  File "C:\Python27\lib\site-packages\cffi\cparser.py", line 512, in _get_type_a
nd_quals
    typenode.dim, partial_length_ok=partial_length_ok)
  File "C:\Python27\lib\site-packages\cffi\cparser.py", line 763, in _parse_cons
tant
    if isinstance(exprnode, pycparser.c_ast.Constant):
cffi.api.FFIError: :2: unsupported expression: expected a simple numeric constan
t
    *** Err: typedef int MyArr[__dotdotdotarray__];

Comments (10)

  1. Armin Rigo

    Can you be more precise? The syntax you're suggesting, i.e. literally typedef **struct** hello {...;} hello;, doesn't seem to make much sense... If you mean typedef struct hello {...;} hello; then it works fine as far as I know?

  2. KoshkinAlex31

    Asterisks are just my attempt to make bold text inside code block, sorry) exact code that fails:

    typedef enum fpta_value_type {
        ...;
    } fpta_value_type;
    

    It fails with

    cffi.error.CDefError: cannot parse "__dotdotdot__ ;"
    :3:6: before: __dotdotdot__
    
  3. Armin Rigo

    The syntax ...; only works for structs and unions. For enums, you have to use ... instead. That's not really an inconsistency, given that in standard C code you never use ; inside an enum { } either.

  4. Log in to comment