Author: hans Date: Tue Jan 17 22:45:43 2017 New Revision: 292339 URL: http://llvm.org/viewvc/llvm-project?rev=292339&view=rev Log: Merging r292247: ------------------------------------------------------------------------ r292247 | jbcoe | 2017-01-17 12:03:54 -0800 (Tue, 17 Jan 2017) | 14 lines
Fix Python 3 language issues and add an explicit check for Python version == 2. Summary: Python bindings cannot support Python 3 without work being done to fix Unicode c-string conversion. This was attempted in https://reviews.llvm.org/D26082. That patch was reverted due to memory access issues on Linux. This revision fixes enough language compatibility issues for the clang module to be loaded and raise an error if the Python version is not 2. Reviewers: mgorny, MathieuDuponchelle, rengolin, compnerd Reviewed By: compnerd Differential Revision: https://reviews.llvm.org/D28682 ------------------------------------------------------------------------ Modified: cfe/branches/release_40/ (props changed) cfe/branches/release_40/bindings/python/clang/__init__.py cfe/branches/release_40/bindings/python/clang/cindex.py Propchange: cfe/branches/release_40/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Jan 17 22:45:43 2017 @@ -1,4 +1,4 @@ /cfe/branches/type-system-rewrite:134693-134817 -/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291964,292032,292052,292183,292265 +/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291964,292032,292052,292183,292247,292265 /cfe/trunk/test:170344 /cfe/trunk/test/SemaTemplate:126920 Modified: cfe/branches/release_40/bindings/python/clang/__init__.py URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/bindings/python/clang/__init__.py?rev=292339&r1=292338&r2=292339&view=diff ============================================================================== --- cfe/branches/release_40/bindings/python/clang/__init__.py (original) +++ cfe/branches/release_40/bindings/python/clang/__init__.py Tue Jan 17 22:45:43 2017 @@ -20,5 +20,13 @@ The available modules are: Bindings for the Clang indexing library. """ + +# Python 3 uses unicode for strings. The bindings, in particular the interaction +# with ctypes, need modifying to handle conversions between unicode and +# c-strings. +import sys +if sys.version_info[0] != 2: + raise Exception("Only Python 2 is supported.") + __all__ = ['cindex'] Modified: cfe/branches/release_40/bindings/python/clang/cindex.py URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/bindings/python/clang/cindex.py?rev=292339&r1=292338&r2=292339&view=diff ============================================================================== --- cfe/branches/release_40/bindings/python/clang/cindex.py (original) +++ cfe/branches/release_40/bindings/python/clang/cindex.py Tue Jan 17 22:45:43 2017 @@ -554,8 +554,8 @@ class BaseEnumeration(object): if value >= len(self.__class__._kinds): self.__class__._kinds += [None] * (value - len(self.__class__._kinds) + 1) if self.__class__._kinds[value] is not None: - raise ValueError,'{0} value {1} already loaded'.format( - str(self.__class__), value) + raise ValueError('{0} value {1} already loaded'.format( + str(self.__class__), value)) self.value = value self.__class__._kinds[value] = self self.__class__._name_map = None @@ -577,7 +577,7 @@ class BaseEnumeration(object): @classmethod def from_id(cls, id): if id >= len(cls._kinds) or cls._kinds[id] is None: - raise ValueError,'Unknown template argument kind %d' % id + raise ValueError('Unknown template argument kind %d' % id) return cls._kinds[id] def __repr__(self): @@ -1777,7 +1777,7 @@ class StorageClass(object): if value >= len(StorageClass._kinds): StorageClass._kinds += [None] * (value - len(StorageClass._kinds) + 1) if StorageClass._kinds[value] is not None: - raise ValueError,'StorageClass already loaded' + raise ValueError('StorageClass already loaded') self.value = value StorageClass._kinds[value] = self StorageClass._name_map = None @@ -1798,7 +1798,7 @@ class StorageClass(object): @staticmethod def from_id(id): if id >= len(StorageClass._kinds) or not StorageClass._kinds[id]: - raise ValueError,'Unknown storage class %d' % id + raise ValueError('Unknown storage class %d' % id) return StorageClass._kinds[id] def __repr__(self): @@ -2729,9 +2729,9 @@ class TranslationUnit(ClangObject): # FIXME: It would be great to support an efficient version # of this, one day. value = value.read() - print value + print(value) if not isinstance(value, str): - raise TypeError,'Unexpected unsaved file contents.' + raise TypeError('Unexpected unsaved file contents.') unsaved_files_array[i].name = name unsaved_files_array[i].contents = value unsaved_files_array[i].length = len(value) @@ -2793,9 +2793,9 @@ class TranslationUnit(ClangObject): # FIXME: It would be great to support an efficient version # of this, one day. value = value.read() - print value + print(value) if not isinstance(value, str): - raise TypeError,'Unexpected unsaved file contents.' + raise TypeError('Unexpected unsaved file contents.') unsaved_files_array[i].name = name unsaved_files_array[i].contents = value unsaved_files_array[i].length = len(value) _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits