[clang] [libclang/python] Fix get_exception_specification_kind (PR #101548)

Jannick Kremer via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 00:07:06 PDT 2024


https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/101548

>From e7e66f0f90d7fb9adf3d3f546becd87c7527fa4c Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Thu, 1 Aug 2024 20:01:34 +0100
Subject: [PATCH 1/2] [libclang/python] Fix get_exception_specification_kind

---
 clang/bindings/python/clang/cindex.py                |  2 +-
 .../cindex/test_exception_specification_kind.py      | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7d..c251c46a04adf 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2654,7 +2654,7 @@ def get_exception_specification_kind(self):
         the ExceptionSpecificationKind enumeration.
         """
         return ExceptionSpecificationKind.from_id(
-            conf.lib.clang.getExceptionSpecificationType(self)
+            conf.lib.clang_getExceptionSpecificationType(self)
         )
 
     @property
diff --git a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
index 8e2a6b5c50223..e4742db31adbe 100644
--- a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
+++ b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
@@ -13,7 +13,7 @@
 
 def find_function_declarations(node, declarations=[]):
     if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
-        declarations.append((node.spelling, node.exception_specification_kind))
+        declarations.append(node)
     for child in node.get_children():
         declarations = find_function_declarations(child, declarations)
     return declarations
@@ -33,4 +33,12 @@ def test_exception_specification_kind(self):
             ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),
             ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),
         ]
-        self.assertListEqual(declarations, expected)
+        from_cursor = [
+            (node.spelling, node.exception_specification_kind) for node in declarations
+        ]
+        from_type = [
+            (node.spelling, node.type.get_exception_specification_kind())
+            for node in declarations
+        ]
+        self.assertListEqual(from_cursor, expected)
+        self.assertListEqual(from_type, expected)

>From 446507880b0204a7b7941826c1fcaab467c36109 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Fri, 2 Aug 2024 08:06:49 +0100
Subject: [PATCH 2/2] Add release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba70b138a04c4..8101d4327cd47 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -299,6 +299,7 @@ Sanitizers
 
 Python Binding Changes
 ----------------------
+- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
 
 OpenMP Support
 --------------



More information about the cfe-commits mailing list