https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/224678
>From 66b2c944d449835496b9719e40f7c966fedbfe2e Mon Sep 17 00:00:00 2001 From: Jannick Kremer <[email protected]> Date: Sat, 19 Sep 2026 01:19:54 +0900 Subject: [PATCH 1/4] [libclang/python] Fold CCRStructure into CodeCompletionResults --- clang/bindings/python/clang/cindex.py | 42 ++++++------------- .../tests/cindex/test_code_completion.py | 2 - clang/docs/ReleaseNotes.md | 5 +++ 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 80283f624fb96b..4a2e2a6d0fec55 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -3216,38 +3216,20 @@ def __getitem__(self, key: int) -> CodeCompletionResult: return self.results[key] -class CodeCompletionResults(ClangObject): - def __init__(self, ptr: _Pointer[CCRStructure]): - assert isinstance(ptr, POINTER(CCRStructure)) and ptr - self.ptr = self._as_parameter_ = ptr - - def from_param(self) -> _Pointer[CCRStructure]: - return self._as_parameter_ +class CodeCompletionResults(Structure): + _fields_ = [("results", POINTER(CodeCompletionResult)), ("numResults", c_uint)] def __del__(self) -> None: - conf.lib.clang_disposeCodeCompleteResults(self) + conf.lib.clang_disposeCodeCompleteResults(byref(self)) def __len__(self) -> int: - return self.ptr.contents.numResults + return self.numResults def __getitem__(self, key: int) -> CodeCompletionResult: if len(self) <= key: raise IndexError - return self.ptr.contents.results[key] - - @property - def results(self) -> CCRStructure: - warnings.warn( - "'CodeCompletionResults.results' will become an implementation detail " - "with changed behavior in a future release and should not be used directly. " - "Existing uses of 'CodeCompletionResults.results' should be changed " - "to directly use 'CodeCompletionResults': it nows supports '__len__' " - "and '__getitem__', so it can be used the same as " - "'CodeCompletionResults.results'.", - DeprecationWarning, - ) - return self.ptr.contents + return self.results[key] @property def diagnostics(self) -> NoSliceSequence[Diagnostic]: @@ -3256,10 +3238,10 @@ def __init__(self, ccr: CodeCompletionResults): self.ccr = ccr def __len__(self) -> int: - return int(conf.lib.clang_codeCompleteGetNumDiagnostics(self.ccr)) + return int(conf.lib.clang_codeCompleteGetNumDiagnostics(byref(self.ccr))) def __getitem__(self, key: int) -> Diagnostic: - return conf.lib.clang_codeCompleteGetDiagnostic(self.ccr, key) # type: ignore [no-any-return] + return conf.lib.clang_codeCompleteGetDiagnostic(byref(self.ccr), key) # type: ignore [no-any-return] return DiagnosticsItr(self) @@ -3697,7 +3679,7 @@ def codeComplete( options, ) if ptr: - return CodeCompletionResults(ptr) + return ptr.contents return None def get_tokens( @@ -4149,10 +4131,10 @@ def set_property(self, property, value): ( "clang_codeCompleteAt", [TranslationUnit, c_interop_string, c_int, c_int, c_void_p, c_int, c_int], - POINTER(CCRStructure), + POINTER(CodeCompletionResults), ), - ("clang_codeCompleteGetDiagnostic", [CodeCompletionResults, c_int], Diagnostic), - ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int), + ("clang_codeCompleteGetDiagnostic", [POINTER(CodeCompletionResults), c_int], Diagnostic), + ("clang_codeCompleteGetNumDiagnostics", [POINTER(CodeCompletionResults)], c_int), ("clang_createIndex", [c_int, c_int], c_object_p), ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p), ("clang_CXRewriter_create", [TranslationUnit], c_object_p), @@ -4180,7 +4162,7 @@ def set_property(self, property, value): ("clang_EnumDecl_isScoped", [Cursor], c_uint), ("clang_defaultDiagnosticDisplayOptions", [], c_uint), ("clang_defaultSaveOptions", [TranslationUnit], c_uint), - ("clang_disposeCodeCompleteResults", [CodeCompletionResults]), + ("clang_disposeCodeCompleteResults", [POINTER(CodeCompletionResults)]), # ("clang_disposeCXTUResourceUsage", # [CXTUResourceUsage]), ("clang_disposeDiagnostic", [Diagnostic]), diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py index f89927e50ab0ab..672c96f57a5b7f 100644 --- a/clang/bindings/python/tests/cindex/test_code_completion.py +++ b/clang/bindings/python/tests/cindex/test_code_completion.py @@ -2,13 +2,11 @@ AvailabilityKind, CompletionChunk, CompletionChunkKind, - CompletionString, TranslationUnit, ) import unittest from pathlib import Path -import warnings class TestCodeCompletion(unittest.TestCase): diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index a1f24a8caedae5..3c440218ea495b 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -141,6 +141,11 @@ features cannot lower the translation-unit ABI level; As a result, the `__str__` representation of its return values changed. Like other libclang enums, it now follows the `CompletionChunkKind.VARIANT_NAME` scheme instead of `VariantName`. +- Change the behavior of the deprecated `CodeCompletionResults.results` property. + It is used as an implementation detail now and should not be accessed directly. + Existing uses of it should be changed to use `CodeCompletionResults` directly: + it nows supports `__len__` and `__getitem__`, so it can be used the same as `CodeCompletionResults.results` previously. + - `Cursor` instance's `enum_value` method now returns 1 instead of -1 for `true` bool enumeration values ### OpenCL Potentially Breaking Changes >From 4a903d1d430c451c6f2429bc5cdda01b9c3245e0 Mon Sep 17 00:00:00 2001 From: Jannick Kremer <[email protected]> Date: Sat, 19 Sep 2026 01:34:07 +0900 Subject: [PATCH 2/4] Fix formatting --- clang/bindings/python/clang/cindex.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 4a2e2a6d0fec55..17765d4b0cf272 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -3238,7 +3238,9 @@ def __init__(self, ccr: CodeCompletionResults): self.ccr = ccr def __len__(self) -> int: - return int(conf.lib.clang_codeCompleteGetNumDiagnostics(byref(self.ccr))) + return int( + conf.lib.clang_codeCompleteGetNumDiagnostics(byref(self.ccr)) + ) def __getitem__(self, key: int) -> Diagnostic: return conf.lib.clang_codeCompleteGetDiagnostic(byref(self.ccr), key) # type: ignore [no-any-return] @@ -4133,7 +4135,11 @@ def set_property(self, property, value): [TranslationUnit, c_interop_string, c_int, c_int, c_void_p, c_int, c_int], POINTER(CodeCompletionResults), ), - ("clang_codeCompleteGetDiagnostic", [POINTER(CodeCompletionResults), c_int], Diagnostic), + ( + "clang_codeCompleteGetDiagnostic", + [POINTER(CodeCompletionResults), c_int], + Diagnostic + ), ("clang_codeCompleteGetNumDiagnostics", [POINTER(CodeCompletionResults)], c_int), ("clang_createIndex", [c_int, c_int], c_object_p), ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p), >From 826b343fefa83946cdebb432cf470006e35c351c Mon Sep 17 00:00:00 2001 From: Jannick Kremer <[email protected]> Date: Sat, 19 Sep 2026 01:43:53 +0900 Subject: [PATCH 3/4] Fix formatting --- clang/bindings/python/clang/cindex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 17765d4b0cf272..7fe0d2fda8d9f9 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -4138,7 +4138,7 @@ def set_property(self, property, value): ( "clang_codeCompleteGetDiagnostic", [POINTER(CodeCompletionResults), c_int], - Diagnostic + Diagnostic, ), ("clang_codeCompleteGetNumDiagnostics", [POINTER(CodeCompletionResults)], c_int), ("clang_createIndex", [c_int, c_int], c_object_p), >From 124541819615241af608280c69aca1a9b6976095 Mon Sep 17 00:00:00 2001 From: Jannick Kremer <[email protected]> Date: Tue, 6 Oct 2026 22:40:11 +0900 Subject: [PATCH 4/4] Remove unused CCRStructure class --- clang/bindings/python/clang/cindex.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 7fe0d2fda8d9f9..0ba4bd2c013248 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -3200,22 +3200,6 @@ def string(self) -> CompletionString: return CompletionString(self.completionString) -class CCRStructure(Structure): - _fields_ = [("results", POINTER(CodeCompletionResult)), ("numResults", c_uint)] - - results: NoSliceSequence[CodeCompletionResult] - numResults: int - - def __len__(self) -> int: - return self.numResults - - def __getitem__(self, key: int) -> CodeCompletionResult: - if len(self) <= key: - raise IndexError - - return self.results[key] - - class CodeCompletionResults(Structure): _fields_ = [("results", POINTER(CodeCompletionResult)), ("numResults", c_uint)] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
