[PATCH] D52173: Python bindings TypeError in reparse method

Axel Tillequin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 17 07:26:54 PDT 2018


bdcht created this revision.
bdcht added a reviewer: clang.
bdcht added a project: clang.
Herald added a subscriber: cfe-commits.

In method 'reparse' of the python bindings (cindex.py), a TypeError is raised when 'unsaved_files_array' is set from name/value arguments when using Python3.
(This is due to Python3 mess with bytes vs unicode str...)
The way this unsaved_files_array is set here is not consistent with similar code in other methods like 'from_source' or 'codeComplete'. This proposed fix just
replicates what is done in from_source/codeComplete to set this ctypes unsaved_files_array.


Repository:
  rC Clang

https://reviews.llvm.org/D52173

Files:
  bindings/python/clang/cindex.py


Index: bindings/python/clang/cindex.py
===================================================================
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -2983,8 +2983,8 @@
                     print(value)
                 if not isinstance(value, str):
                     raise TypeError('Unexpected unsaved file contents.')
-                unsaved_files_array[i].name = name
-                unsaved_files_array[i].contents = value
+                unsaved_files_array[i].name = b(name)
+                unsaved_files_array[i].contents = b(value)
                 unsaved_files_array[i].length = len(value)
         ptr = conf.lib.clang_reparseTranslationUnit(self, len(unsaved_files),
                 unsaved_files_array, options)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52173.165764.patch
Type: text/x-patch
Size: 767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180917/0ca20732/attachment.bin>


More information about the cfe-commits mailing list