ctypeslib icon indicating copy to clipboard operation
ctypeslib copied to clipboard

ran clang2py on a header that had the "raise" symbol

Open bogen85 opened this issue 4 years ago • 3 comments

Since that is a python keyword, loading the resulting file is problematic....

I was able to fix and a few other issues with:

sed 's/^raise/#_raise/'
sed "s,^_libraries\['FIXME_STUB'].*,_libraries['FIXME_STUB'] = ctypes.CDLL('libc.so.6'),"
sed 's/^pthread/#pthread/'

bogen85 avatar Jun 28 '21 15:06 bogen85

In general clang2py does not like the headers I give it. I was trying to use cffi on some headers and it did not them either. The following made them more palatable, and clang2py likes headers resulting from this as well:

result = subprocess.check_output(f"clang -E -I. {header}", shell=True)
sanitized = []
for line in result.decode(encoding='utf-8').split('\n'):
  for bad in ['__asm__', '__attribute__']:
    if bad in line:
      line = f'{line.split(bad)[0]};'.replace(';;',';')
    sanitized.append(line)
lines = "\n".join(sanitized)

With sanitized headers and the above sed commands I'm having a lot more success with ctypeslib than I was having with cffi I'm passing in my library and getting most symbols resolved by it. When I try to pass in libc.so.6 as well, I get no output from clang2py, but that is a different issue.

bogen85 avatar Jun 28 '21 16:06 bogen85

Well, actually I'm fixing it all up in python now, the sed stuff was just temporary from the command line to get it working.

bogen85 avatar Jun 28 '21 17:06 bogen85

Sounds like clang2py would need a conflicting names resolver?

mara004 avatar Feb 21 '24 19:02 mara004