mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-09 23:26:20 -04:00
fix(rust): ensure C returned pointers are non-null in
`Node::grammar_name` and `Node::kind`
This commit is contained in:
parent
9540ea3b10
commit
49dbf70ebd
|
|
@ -1666,9 +1666,9 @@ impl<'tree> Node<'tree> {
|
|||
#[doc(alias = "ts_node_type")]
|
||||
#[must_use]
|
||||
pub fn kind(&self) -> &'tree str {
|
||||
unsafe { CStr::from_ptr(ffi::ts_node_type(self.0)) }
|
||||
.to_str()
|
||||
.unwrap()
|
||||
let ptr = unsafe { ffi::ts_node_type(self.0) };
|
||||
assert!(!ptr.is_null());
|
||||
unsafe { CStr::from_ptr(ptr) }.to_str().unwrap()
|
||||
}
|
||||
|
||||
/// Get this node's symbol name as it appears in the grammar ignoring
|
||||
|
|
@ -1676,9 +1676,9 @@ impl<'tree> Node<'tree> {
|
|||
#[doc(alias = "ts_node_grammar_type")]
|
||||
#[must_use]
|
||||
pub fn grammar_name(&self) -> &'tree str {
|
||||
unsafe { CStr::from_ptr(ffi::ts_node_grammar_type(self.0)) }
|
||||
.to_str()
|
||||
.unwrap()
|
||||
let ptr = unsafe { ffi::ts_node_grammar_type(self.0) };
|
||||
assert!(!ptr.is_null());
|
||||
unsafe { CStr::from_ptr(ptr) }.to_str().unwrap()
|
||||
}
|
||||
|
||||
/// Get the [`Language`] that was used to parse this node's syntax tree.
|
||||
|
|
|
|||
Loading…
Reference in a new issue