Author: Jannick Kremer Date: 2025-05-16T10:03:48+02:00 New Revision: 82a9cb358b4977e06179419b472a5b7657e55963
URL: https://github.com/llvm/llvm-project/commit/82a9cb358b4977e06179419b472a5b7657e55963 DIFF: https://github.com/llvm/llvm-project/commit/82a9cb358b4977e06179419b472a5b7657e55963.diff LOG: [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. Added: clang/bindings/python/tests/cindex/test_lib.py Modified: clang/bindings/python/clang/cindex.py Removed: ################################################################################ diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 1bbe006fcb1b9..7a10f5618aad0 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -3969,6 +3969,7 @@ def set_property(self, property, value): ("clang_equalRanges", [SourceRange, SourceRange], bool), ("clang_equalTypes", [Type, Type], bool), ("clang_formatDiagnostic", [Diagnostic, c_uint], _CXString), + ("clang_getAddressSpace", [Type], c_uint), ("clang_getArgType", [Type, c_uint], Type), ("clang_getArrayElementType", [Type], Type), ("clang_getArraySize", [Type], c_longlong), @@ -3987,8 +3988,10 @@ def set_property(self, property, value): ("clang_getCursorAvailability", [Cursor], c_int), ("clang_getCursorDefinition", [Cursor], Cursor), ("clang_getCursorDisplayName", [Cursor], _CXString), + ("clang_getCursorExceptionSpecificationType", [Cursor], c_int), ("clang_getCursorExtent", [Cursor], SourceRange), ("clang_getCursorLexicalParent", [Cursor], Cursor), + ("clang_getCursorLinkage", [Cursor], c_int), ("clang_getCursorLocation", [Cursor], SourceLocation), ("clang_getCursorPrettyPrinted", [Cursor, PrintingPolicy], _CXString), ("clang_getCursorPrintingPolicy", [Cursor], c_object_p), @@ -3997,6 +4000,7 @@ def set_property(self, property, value): ("clang_getCursorResultType", [Cursor], Type), ("clang_getCursorSemanticParent", [Cursor], Cursor), ("clang_getCursorSpelling", [Cursor], _CXString), + ("clang_getCursorTLSKind", [Cursor], c_int), ("clang_getCursorType", [Cursor], Type), ("clang_getCursorUSR", [Cursor], _CXString), ("clang_Cursor_getMangling", [Cursor], _CXString), @@ -4022,6 +4026,7 @@ def set_property(self, property, value): ("clang_getEnumConstantDeclUnsignedValue", [Cursor], c_ulonglong), ("clang_getEnumConstantDeclValue", [Cursor], c_longlong), ("clang_getEnumDeclIntegerType", [Cursor], Type), + ("clang_getExceptionSpecificationType", [Type], c_int), ("clang_getFile", [TranslationUnit, c_interop_string], c_object_p), ("clang_getFileName", [File], _CXString), ("clang_getFileTime", [File], c_uint), @@ -4118,6 +4123,7 @@ def set_property(self, property, value): ("clang_Cursor_getBriefCommentText", [Cursor], _CXString), ("clang_Cursor_getRawCommentText", [Cursor], _CXString), ("clang_Cursor_getOffsetOfField", [Cursor], c_longlong), + ("clang_Cursor_getStorageClass", [Cursor], c_int), ("clang_Cursor_isAnonymous", [Cursor], bool), ("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool), ("clang_Cursor_isBitField", [Cursor], bool), diff --git a/clang/bindings/python/tests/cindex/test_lib.py b/clang/bindings/python/tests/cindex/test_lib.py new file mode 100644 index 0000000000000..5e88ebf9d8448 --- /dev/null +++ b/clang/bindings/python/tests/cindex/test_lib.py @@ -0,0 +1,31 @@ +import os + +import clang.cindex + +if "CLANG_LIBRARY_PATH" in os.environ: + clang.cindex.Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"]) + +import unittest +import ast + + +class TestLib(unittest.TestCase): + def test_functions_registered(self): + def get_function_spelling(node): + # The call expressions we are interested in have + # their spelling in .attr, not .id + if hasattr(node, "attr"): + return node.attr + return "" + + filename = clang.cindex.__file__ + with open(filename) as file: + root = ast.parse(file.read()) + functions = [ + get_function_spelling(node.func) + for node in ast.walk(root) + if isinstance(node, ast.Call) + ] + used_functions = set([func for func in functions if func.startswith("clang_")]) + registered_functions = set([item[0] for item in clang.cindex.FUNCTION_LIST]) + self.assertEqual(used_functions - registered_functions, set()) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits