mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:36:22 -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")]
|
#[doc(alias = "ts_node_type")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn kind(&self) -> &'tree str {
|
pub fn kind(&self) -> &'tree str {
|
||||||
unsafe { CStr::from_ptr(ffi::ts_node_type(self.0)) }
|
let ptr = unsafe { ffi::ts_node_type(self.0) };
|
||||||
.to_str()
|
assert!(!ptr.is_null());
|
||||||
.unwrap()
|
unsafe { CStr::from_ptr(ptr) }.to_str().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get this node's symbol name as it appears in the grammar ignoring
|
/// 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")]
|
#[doc(alias = "ts_node_grammar_type")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn grammar_name(&self) -> &'tree str {
|
pub fn grammar_name(&self) -> &'tree str {
|
||||||
unsafe { CStr::from_ptr(ffi::ts_node_grammar_type(self.0)) }
|
let ptr = unsafe { ffi::ts_node_grammar_type(self.0) };
|
||||||
.to_str()
|
assert!(!ptr.is_null());
|
||||||
.unwrap()
|
unsafe { CStr::from_ptr(ptr) }.to_str().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`Language`] that was used to parse this node's syntax tree.
|
/// Get the [`Language`] that was used to parse this node's syntax tree.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue