mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Handle ts_node_type return NULL (bug#78938)
* src/treesit.c (treesit_traverse_match_predicate): Handle the case when ts_node_type returns NULL. (Ftreesit_node_type): Add some comment.
This commit is contained in:
parent
5bdacbe460
commit
060f964906
1 changed files with 11 additions and 1 deletions
|
|
@ -2043,7 +2043,9 @@ If NODE is nil, return nil. */)
|
||||||
treesit_initialize ();
|
treesit_initialize ();
|
||||||
|
|
||||||
TSNode treesit_node = XTS_NODE (node)->node;
|
TSNode treesit_node = XTS_NODE (node)->node;
|
||||||
/* ts_node_type could return NULL, see source code. */
|
/* ts_node_type could return NULL, see source code (tree-sitter can't
|
||||||
|
find the string name of a node type by its id in its node name
|
||||||
|
obarray). */
|
||||||
const char *type = ts_node_type (treesit_node);
|
const char *type = ts_node_type (treesit_node);
|
||||||
return type == NULL ? Vtreesit_str_empty : build_string (type);
|
return type == NULL ? Vtreesit_str_empty : build_string (type);
|
||||||
}
|
}
|
||||||
|
|
@ -3595,6 +3597,10 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
|
||||||
if (STRINGP (pred))
|
if (STRINGP (pred))
|
||||||
{
|
{
|
||||||
const char *type = ts_node_type (node);
|
const char *type = ts_node_type (node);
|
||||||
|
/* ts_node_type returning NULL means something unexpected happend
|
||||||
|
in tree-sitter, in this case the only reasonable thing is to
|
||||||
|
not match anything. */
|
||||||
|
if (type == NULL) return false;
|
||||||
return fast_c_string_match (pred, type, strlen (type)) >= 0;
|
return fast_c_string_match (pred, type, strlen (type)) >= 0;
|
||||||
}
|
}
|
||||||
else if (FUNCTIONP (pred))
|
else if (FUNCTIONP (pred))
|
||||||
|
|
@ -3632,6 +3638,10 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
|
||||||
{
|
{
|
||||||
/* A bit of code duplication here, but should be fine. */
|
/* A bit of code duplication here, but should be fine. */
|
||||||
const char *type = ts_node_type (node);
|
const char *type = ts_node_type (node);
|
||||||
|
/* ts_node_type returning NULL means something unexpected
|
||||||
|
happend in tree-sitter, in this case the only reasonable
|
||||||
|
thing is to not match anything */
|
||||||
|
if (type == NULL) return false;
|
||||||
if (!(fast_c_string_match (car, type, strlen (type)) >= 0))
|
if (!(fast_c_string_match (car, type, strlen (type)) >= 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue