tree-sitter / py-tree-sitter

Python bindings to the Tree-sitter parsing library
https://tree-sitter.github.io/py-tree-sitter/
MIT License
820 stars 98 forks source link

fix: prevent segmentation fault #216

Closed sceneq closed 5 months ago

sceneq commented 5 months ago

Fix the segmentation fault that occurs with the following code:

PY_LANGUAGE = Language(tspython.language(), "python") # type: ignore
parser = Parser()
parser.set_language(PY_LANGUAGE)

tree = parser.parse(b"i = 0")
node = tree.root_node
v = node.child(node.child_count)

print(v)  # This line will cause a SIGSEGV

assert v is None

This commit corresponds to this code in the Rust binding

ObserverOfTime commented 5 months ago

It will be fixed by #208