Skip to content

[libclang/python] Fix get_exception_specification_kind #101548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

DeinAlptraum
Copy link
Contributor

@DeinAlptraum DeinAlptraum commented Aug 1, 2024

Fix a bug with get_exception_specification_kind. The function did not work before. Also add a test that confirms that it works now.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2024

@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)

Changes

This fixes a bug with get_exception_ specification_kind. The function did not work before. Also add a test that confirms that it works now.


Full diff: https://github.com/llvm/llvm-project/pull/101548.diff

2 Files Affected:

  • (modified) clang/bindings/python/clang/cindex.py (+1-1)
  • (modified) clang/bindings/python/tests/cindex/test_exception_specification_kind.py (+5-2)
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..6653c22eaf9cd 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,7 @@ 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)

Copy link

github-actions bot commented Aug 1, 2024

✅ With the latest revision this PR passed the Python code formatter.

@DeinAlptraum
Copy link
Contributor Author

@Endilll I found another bug on the way, so here's a fix+test. Does this need a release note under Python Binding Changes?

@Endilll
Copy link
Contributor

Endilll commented Aug 1, 2024

@Endilll I found another bug on the way, so here's a fix+test. Does this need a release note under Python Binding Changes?

Yes, the general approach is that every change should come with a test and a release note.

On a different note, I wonder if there's a way to prevent this kind of bugs. Seems quite unfortunate that our python binding might not work because of something this silly.

@Endilll Endilll added the clang:as-a-library libclang and C++ API label Aug 1, 2024
@DeinAlptraum
Copy link
Contributor Author

I can't think of any more genereal approach that prevents this sort of problem. Type checking would help with this (e.g. giving an error when an unknown attribute is called on an object) though it wouldn't have worked in this specific case... otherwise nothing to do but add more tests I guess.

@Endilll Endilll changed the title [libclang/python] Fix get_exception_specification_kind [libclang/python] Fix get_exception_specification_kind Aug 2, 2024
@DeinAlptraum
Copy link
Contributor Author

Could you merge this for me?

On related note, do you think my contributions would count for "a track record of submitting high quality patches", i.e. should I apply for commit access?

@Endilll Endilll merged commit e7ee21f into llvm:main Aug 2, 2024
9 of 10 checks passed
@Endilll
Copy link
Contributor

Endilll commented Aug 2, 2024

Could you merge this for me?

Done.

On related note, do you think my contributions would count for "a track record of submitting high quality patches", i.e. should I apply for commit access?

You have unread messages in Discord :)

@DeinAlptraum DeinAlptraum deleted the bugfix branch August 2, 2024 13:36
@Endilll
Copy link
Contributor

Endilll commented Aug 2, 2024

On related note, do you think my contributions would count for "a track record of submitting high quality patches", i.e. should I apply for commit access?

To this end, I consider you eligible, as I mentioned offline yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:as-a-library libclang and C++ API clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants