[clang] [libclang/python] Fold CCRStructure into CodeCompletionResults (PR #224678)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 01:15:06 PDT 2026
================
@@ -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]
----------------
Endilll wrote:
I'm surprised you can use square brackets on `POINTER(CodeCompletionResult)`, but I see this is what `CCRStructure.__getitem__` used to do, so I guess it's fine.
https://github.com/llvm/llvm-project/pull/224678
More information about the cfe-commits
mailing list