cffi parses 'typedef signed char INT8, *PINT8;' failed.

45 views
Skip to first unread message

Mi Zou

unread,
Oct 18, 2015, 10:24:17 AM10/18/15
to python-cffi
import cffi

ffi = cffi.FFI()
ffi.cdef(r'typedef signed char INT8, *PINT8;')  # error is raised here

And I get the exception:

cffi.api.CDefError: cannot parse "typedef signed char INT8, *PINT8;"
:3:25: before: ,

Ryan Gonzalez

unread,
Oct 18, 2015, 1:57:23 PM10/18/15
to pytho...@googlegroups.com, Mi Zou
Is this even valid C syntax? Try:

typedef char INT8;
typedef INT8* PINT8;
--
Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.

Armin Rigo

unread,
Oct 18, 2015, 3:13:31 PM10/18/15
to pytho...@googlegroups.com, Mi Zou
Hi Ryan,

On Sun, Oct 18, 2015 at 7:57 PM, Ryan Gonzalez <rym...@gmail.com> wrote:
>> ffi.cdef(r'typedef signed char INT8, *PINT8;') # error is raised here
> Is this even valid C syntax?

Yes, it is valid C syntax. Mi Zou: you're hitting this problem,
written in cffi/cparser.py:

# Look in the source for what looks like usages of types from the
# list of common types. A "usage" is approximated here as the
# appearance of the word, minus a "definition" of the type, which
# is the last word in a "typedef" statement. Approximative only
# but should be fine for all the common types.

The problem is that the types INT8 and PINT8 are predefined on Windows
and you don't need to redefine them, but you can. If you do, then
normally this is the logic that figures out you're redefining the
types and doesn't include the predefined version. It fails in this
case to figure out that "INT8" is redefined because it only looks for
the word just before the semicolon following a typedef statement.

You can fix it for now by using Ryan's version (or by omitting that
line entirely if you are only building for Windows). I'll try to fix
it inside CFFI.


A bientôt,

Armin.

Armin Rigo

unread,
Oct 18, 2015, 3:33:36 PM10/18/15
to pytho...@googlegroups.com, Mi Zou
Hi Mi Zou,

Ok, should be fixed in e6fe9d4612bb.


Armin

Mi Zou

unread,
Oct 19, 2015, 7:19:08 AM10/19/15
to python-cffi, aaasuo...@gmail.com, ar...@tunes.org
Thank you for your detailed explanation!

在 2015年10月19日星期一 UTC+8上午3:13:31,Armin Rigo写道:
Reply all
Reply to author
Forward
0 new messages