Skip to content

Commit a799aab

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ceeb93096c79' from llvm.org/release/21.x into stable/21.x
2 parents 0e0dbbc + ceeb930 commit a799aab

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,8 @@ def cursor(self):
38533853
cursor._tu = self._tu
38543854

38553855
conf.lib.clang_annotateTokens(self._tu, byref(self), 1, byref(cursor))
3856+
if cursor.is_null():
3857+
return None
38563858

38573859
return cursor
38583860

clang/bindings/python/tests/cindex/test_tokens.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ def test_token_extent(self):
5353

5454
self.assertEqual(extent.start.offset, 4)
5555
self.assertEqual(extent.end.offset, 7)
56+
57+
def test_null_cursor(self):
58+
"""Ensure that the cursor property converts null cursors to None"""
59+
tu = get_tu("int i = 5;")
60+
tokens = list(tu.get_tokens(extent=tu.cursor.extent))
61+
self.assertEqual(tokens[-1].cursor, None)

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Clang Frontend Potentially Breaking Changes
9494

9595
Clang Python Bindings Potentially Breaking Changes
9696
--------------------------------------------------
97+
- Return ``None`` instead of null cursors from ``Token.cursor``
9798
- ``Cursor.from_location`` now returns ``None`` instead of a null cursor.
9899
This eliminates the last known source of null cursors.
99100
- Almost all ``Cursor`` methods now assert that they are called on non-null cursors.

0 commit comments

Comments
 (0)