Skip to content

Syntax errors while parsing Linux header files #82

@manolis-andr

Description

@manolis-andr

On Debian Stretch, ctypesgen (1.0.2) produces syntax errors during the parsing phase, when trying to generate a ctype wrapper for headers assert.h or sys/cdefs.h (or any header file that includes one of them).

$ ctypesgen /usr/include/assert.h > /dev/null
WARNING: No libraries specified
INFO: Status: Preprocessing /tmp/tmpKDga8w.h
INFO: Status: gcc -E -U __GNUC__ -dD "-Dinline=" "-D__inline__=" "-D__extension__=" "-D__const=const" "-D__asm__(x)=" "-D__asm(x)=" "-DCTYPESGEN=1" "/tmp/tmpKDga8w.h"
INFO: Status: Parsing /tmp/tmpKDga8w.h
ERROR: /usr/include/x86_64-linux-gnu/sys/cdefs.h:248: Syntax error at '\n'
ERROR: /usr/include/assert.h:40: Syntax error at '\n'
INFO: Status: Processing description list.
WARNING: Could not parse macro "#define __ASSERT_VOID_CAST ( void )"
WARNING: Macro "assert" depends on an unknown identifier "__FILE__". Macro "assert" will not be output
WARNING: Macro "assert" depends on an unknown identifier "__LINE__". Macro "assert" will not be output
WARNING: Macro "__ASSERT_FUNCTION" depends on an unknown identifier "__func__". Macro "__ASSERT_FUNCTION" will not be output
WARNING: Macro "static_assert" depends on an unknown identifier "_Static_assert". Macro "static_assert" will not be output
INFO: Status: Writing to stdout.
INFO: Status: Wrapping complete.

Both header files are part of glibc 2.24 (relevant Debian package: libc6-dev 2.24-11+deb9u4). I have noticed that for ctypesgen 1.0.1, the parsing error for sys/cdefs.h does not appear.

Parsing errors also occur for header files of external libraries. For example trying to parse the /usr/include/ext2fs/ext2fs.h of the libext2fs library (e2fslibs-dev 1.43.4-2+deb9u1 on Debian) produces the following parsing errors:

$ ctypesgen /usr/include/ext2fs/ext2fs.h --library libext2fs.so -D __signed__= > /dev/null
...
ERROR: /usr/include/ext2fs/ext2_io.h:86: Syntax error at 'io_stats'
ERROR: /usr/include/ext2fs/ext2_io.h:99: Syntax error at '}'
ERROR: /usr/include/x86_64-linux-gnu/sys/cdefs.h:248: Syntax error at '\n'

[Used -D __signed__= to relieve ctypesgen from parsing it]:
Looking at the ext2_io.h source code, the first parsing error may occur because both type and variable have the same name.

errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);

Are the syntax errors important? Is there any prospect of eliminating the syntax errors from the parsing process or should one just ignore them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions