[cfe-commits] r164464 - /cfe/trunk/bindings/python/clang/cindex.py

Gregory Szorc gregory.szorc at gmail.com
Sat Sep 22 12:23:24 PDT 2012


The new behavior is contrary to the logic documented in 
Config.set_compatibility_check:

  	In case these bindings are used with an older version of libclang, parts
         that have been stable between releases may still work. Users of the
         python bindings can disable the compatibility check. This will cause
         the python bindings to load, even though they are written for a newer
         version of libclang. Failures now arise if unsupported or incompatible
         features are accessed. The user is required to test himself if the
         features he is using are available and compatible between different
         libclang versions.

In summary, individual applications should trap the exception that was 
previously raised and make the decision that is right for them. i.e. the 
Python bindings will not make assumptions about whether callers should 
treat missing functionality as a fatal or acceptable. This patch breaks 
that contract and thus I think it should be reverted.

This got me thinking, perhaps we should make the library instance a 
simple proxy type that converts KeyError into a MissingFunctionError or 
similar so callers can more easily trap missing libclang functions.

On 9/22/2012 10:52 AM, Dmitri Gribenko wrote:
> Author: gribozavr
> Date: Sat Sep 22 12:52:29 2012
> New Revision: 164464
>
> URL: http://llvm.org/viewvc/llvm-project?rev=164464&view=rev
> Log:
> Fix cindex.py compatibility with older libclang.so
>
> The issue is that we were calling clang_getCompletionBriefComment
> unconditionally.  New we check if this function is available before calling it.
>
> Modified:
>      cfe/trunk/bindings/python/clang/cindex.py
>
> Modified: cfe/trunk/bindings/python/clang/cindex.py
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=164464&r1=164463&r2=164464&view=diff
> ==============================================================================
> --- cfe/trunk/bindings/python/clang/cindex.py (original)
> +++ cfe/trunk/bindings/python/clang/cindex.py Sat Sep 22 12:52:29 2012
> @@ -1737,7 +1737,9 @@
>   
>       @property
>       def briefComment(self):
> -        return conf.lib.clang_getCompletionBriefComment(self.obj)
> +        if conf.function_exists("clang_getCompletionBriefComment"):
> +            return conf.lib.clang_getCompletionBriefComment(self.obj)
> +        return _CXString()
>   
>       def __repr__(self):
>           return " | ".join([str(a) for a in self]) \
> @@ -3097,6 +3099,13 @@
>   
>           return library
>   
> +    def function_exists(self, name):
> +        try:
> +            getattr(self.lib, name)
> +        except AttributeError:
> +            return False
> +
> +        return True
>   
>   def register_enumerations():
>       for name, value in clang.enumerations.TokenKinds:
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list