Skip to content

Commit 82a9cb3

Browse files
authored
[libclang/python] Ensure all used library functions are registered (#140015)
Add a few library functions that were not previously registered to the `CDLL` object. The current behavior relied on the default `restype` to work. Add a test to check that all used library functions are properly registered.
1 parent bb5566a commit 82a9cb3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,7 @@ def set_property(self, property, value):
39693969
("clang_equalRanges", [SourceRange, SourceRange], bool),
39703970
("clang_equalTypes", [Type, Type], bool),
39713971
("clang_formatDiagnostic", [Diagnostic, c_uint], _CXString),
3972+
("clang_getAddressSpace", [Type], c_uint),
39723973
("clang_getArgType", [Type, c_uint], Type),
39733974
("clang_getArrayElementType", [Type], Type),
39743975
("clang_getArraySize", [Type], c_longlong),
@@ -3987,8 +3988,10 @@ def set_property(self, property, value):
39873988
("clang_getCursorAvailability", [Cursor], c_int),
39883989
("clang_getCursorDefinition", [Cursor], Cursor),
39893990
("clang_getCursorDisplayName", [Cursor], _CXString),
3991+
("clang_getCursorExceptionSpecificationType", [Cursor], c_int),
39903992
("clang_getCursorExtent", [Cursor], SourceRange),
39913993
("clang_getCursorLexicalParent", [Cursor], Cursor),
3994+
("clang_getCursorLinkage", [Cursor], c_int),
39923995
("clang_getCursorLocation", [Cursor], SourceLocation),
39933996
("clang_getCursorPrettyPrinted", [Cursor, PrintingPolicy], _CXString),
39943997
("clang_getCursorPrintingPolicy", [Cursor], c_object_p),
@@ -3997,6 +4000,7 @@ def set_property(self, property, value):
39974000
("clang_getCursorResultType", [Cursor], Type),
39984001
("clang_getCursorSemanticParent", [Cursor], Cursor),
39994002
("clang_getCursorSpelling", [Cursor], _CXString),
4003+
("clang_getCursorTLSKind", [Cursor], c_int),
40004004
("clang_getCursorType", [Cursor], Type),
40014005
("clang_getCursorUSR", [Cursor], _CXString),
40024006
("clang_Cursor_getMangling", [Cursor], _CXString),
@@ -4022,6 +4026,7 @@ def set_property(self, property, value):
40224026
("clang_getEnumConstantDeclUnsignedValue", [Cursor], c_ulonglong),
40234027
("clang_getEnumConstantDeclValue", [Cursor], c_longlong),
40244028
("clang_getEnumDeclIntegerType", [Cursor], Type),
4029+
("clang_getExceptionSpecificationType", [Type], c_int),
40254030
("clang_getFile", [TranslationUnit, c_interop_string], c_object_p),
40264031
("clang_getFileName", [File], _CXString),
40274032
("clang_getFileTime", [File], c_uint),
@@ -4118,6 +4123,7 @@ def set_property(self, property, value):
41184123
("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
41194124
("clang_Cursor_getRawCommentText", [Cursor], _CXString),
41204125
("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
4126+
("clang_Cursor_getStorageClass", [Cursor], c_int),
41214127
("clang_Cursor_isAnonymous", [Cursor], bool),
41224128
("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
41234129
("clang_Cursor_isBitField", [Cursor], bool),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
3+
import clang.cindex
4+
5+
if "CLANG_LIBRARY_PATH" in os.environ:
6+
clang.cindex.Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
7+
8+
import unittest
9+
import ast
10+
11+
12+
class TestLib(unittest.TestCase):
13+
def test_functions_registered(self):
14+
def get_function_spelling(node):
15+
# The call expressions we are interested in have
16+
# their spelling in .attr, not .id
17+
if hasattr(node, "attr"):
18+
return node.attr
19+
return ""
20+
21+
filename = clang.cindex.__file__
22+
with open(filename) as file:
23+
root = ast.parse(file.read())
24+
functions = [
25+
get_function_spelling(node.func)
26+
for node in ast.walk(root)
27+
if isinstance(node, ast.Call)
28+
]
29+
used_functions = set([func for func in functions if func.startswith("clang_")])
30+
registered_functions = set([item[0] for item in clang.cindex.FUNCTION_LIST])
31+
self.assertEqual(used_functions - registered_functions, set())

0 commit comments

Comments
 (0)