[clang] [libclang/python] Add check for reparsing (PR #172373)
Thomas Applencourt via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 16 08:14:10 PST 2025
https://github.com/TApplencourt updated https://github.com/llvm/llvm-project/pull/172373
>From 617d153250fb2a62a1a78e923cc7c4b205aa6e9c Mon Sep 17 00:00:00 2001
From: tapplencourt <tapplencourt at anl.gov>
Date: Mon, 15 Dec 2025 21:35:36 +0000
Subject: [PATCH 1/2] Add check for reparsing
---
clang/bindings/python/clang/cindex.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index d352373e85c60..ad1dcb56defab 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3602,6 +3602,9 @@ def reparse(self, unsaved_files=None, options=0):
self, len(unsaved_files), unsaved_files_array, options
)
+ if not ptr:
+ raise TranslationUnitLoadError("Error reparsing translation unit.")
+
def save(self, filename):
"""Saves the TranslationUnit to a file.
>From 8d55d8b5a1a0a0e6dac5fb2b2b04f09248b48104 Mon Sep 17 00:00:00 2001
From: Thomas Applencourt <tapplencourt at anl.gov>
Date: Tue, 16 Dec 2025 16:13:15 +0000
Subject: [PATCH 2/2] Fix error checking
---
clang/bindings/python/clang/cindex.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index ad1dcb56defab..745cb59e2299f 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3598,11 +3598,12 @@ def reparse(self, unsaved_files=None, options=0):
unsaved_files = []
unsaved_files_array = self.process_unsaved_files(unsaved_files)
- ptr = conf.lib.clang_reparseTranslationUnit(
- self, len(unsaved_files), unsaved_files_array, options
+ result = int(
+ conf.lib.clang_reparseTranslationUnit(
+ self, len(unsaved_files), unsaved_files_array, options
+ )
)
-
- if not ptr:
+ if result != 0:
raise TranslationUnitLoadError("Error reparsing translation unit.")
def save(self, filename):
More information about the cfe-commits
mailing list