[cfe-dev] Dealing with parse errors with Python bindings of libclang

Vedant Kumar via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 12 18:45:44 PDT 2016


Hi Ethan,

Unfortunately, this is a known bug in the python bindings (see: the FIXME in
bindings/clang/cindex.py). The fix here should be to 1) expose a function which
can unwrap a CXErrorCode into a more pythonic error value and 2) use that
function to help move from the clang_parseTranslationUnit API to
clang_parseTranslationUnit2.

If you don't have the time to put together a patch, you might be able to get a
debugger to break on clang_parseTranslationUnit and inspect the error state
there.

best,
vedant

> On Aug 8, 2016, at 10:36 AM, Ethan Smith via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> First off, thanks for the awesome library!
> 
> I am using the Python bindings of libclang. I am trying to use it to parse really any c/c++ library for code generation, however, as an example, I tried to bind libui (https://github.com/andlabs/libui). However, when I try to index.parse after setting up a clang index, I get a TranslationUnitLoadError. Since this returns a null pointer, I can't figure out what went wrong. Is there a way to tell what is causing the parser to fail? I also tried to pass 0x200 ( CXTranslationUnit_KeepGoing) as an option, which should, as I understand it, tell the parser to continue on fail, it has no effect. How can I get some useful information to tell me what I need to do to fix the parser error? For the record, the library compiles fine with clang itself.
> 
> Could I expose more useful info from the c libclang? I suppose I'm not opposed to writing my own bindings.
> 
> Thanks!
> 
> Ethan
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list