trolldbois / ctypeslib

Generate python ctypes classes from C headers. Requires LLVM clang
http://trolldbois.blogspot.com/search?q=ctypeslib
MIT License
218 stars 61 forks source link

Macro values with parenthesis are not converted #123

Closed tnakamot closed 1 year ago

tnakamot commented 1 year ago

Hi,

I am using this nice tool, clang2py, to convert macros, enums and structs in C headers to ctypes.Structure in Python. One thing I notice is that macro values with parenthesis are not converted by clang2py. Here is a quick example:

#define MACRO_NAME1 0x1000
#define MACRO_NAME2 (0x1000)

I converted this C header file by executing clang2py -k m /path/to/header.h, but the generated Python code only defined MACRO_NAME1 as a variable as shown below:

MACRO_NAME1 = 0x1000 # macro
# def MACRO_NAME2(0x1000):  # macro
#    return
__all__ = \
    ['MACRO_NAME1']

In general, having parenthesis around the macro values is a good practice in C/C++. The header files that I have follow that convention, so none of the macro values weren't converted to Python variables, unfortunately.

Could you probably fix clang2py in some way so that those macro values can be converted properly?

FYI, below is the dump of clang2py --version in my environment:

versions - clang2py:2.3.3 clang:14.0.0 python-clang:14.0
tnakamot commented 1 year ago

It just turned out that the same issue has been reported as #107. I confirmed a fix has been made in the latest master tree. Closing.

trolldbois commented 1 year ago

fixed in release 2.3.4.