eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.26k stars 612 forks source link

dirent DIR typedef #557

Closed MegaManSec closed 6 days ago

MegaManSec commented 1 week ago

Hi,

Thanks for this project, it's really helpful.

I'm trying to work out how to best contribute a new typedef in fake_libc_include.

I have a C program that uses dirent.h's DIR typedef. pycparser doesn't seem to be able to pick up the include in my C file to understand the typedef.

The problem is, I'm unsure how to add it to fake_libc_include, as DIR can either be a typedef for the dirdesc struct, or a void pointer. Obviously for my machine, the dirdesc struct is fine, but I'm unsure whether this project prefers Linux.

On my FreeBSD machine, /usr/include/dirent.h defines DIR as:

#if __BSD_VISIBLE

typedef struct _dirdesc DIR;

#else /* !__BSD_VISIBLE */

typedef void *  DIR;

#endif /* __BSD_VISIBLE */

Thank you.

eliben commented 1 week ago

It doesn't really matter what type you actually assign it to. pycparser doesn't do semantic analysis - it's only parsing, so all it needs to know is that some identifier is a type at all. Look at the current _fake_typedefs.h - they all pretty much alias the types to int

MegaManSec commented 6 days ago

Understood; thank you!