diff options
| author | Yuan Fu | 2025-07-03 23:36:44 -0700 |
|---|---|---|
| committer | Yuan Fu | 2025-07-03 23:40:59 -0700 |
| commit | 30dae2ad23963bc902101544cbbe2c5698beddd7 (patch) | |
| tree | 2799cf352e029fa6d454a32968724be981f6ffaa | |
| parent | 985ad1da76d2ea1ef70765fe8b4fb62fc975ae0a (diff) | |
| download | emacs-30dae2ad23963bc902101544cbbe2c5698beddd7.tar.gz emacs-30dae2ad23963bc902101544cbbe2c5698beddd7.zip | |
Handle the case when ts_node_type returns NULL (bug#78938)
* src/treesit.c (Ftreesit_node_type): Handle NULL.
| -rw-r--r-- | src/treesit.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/treesit.c b/src/treesit.c index 45d1bc58b06..7393404f7ea 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -426,6 +426,7 @@ static Lisp_Object Vtreesit_str_space; | |||
| 426 | static Lisp_Object Vtreesit_str_equal; | 426 | static Lisp_Object Vtreesit_str_equal; |
| 427 | static Lisp_Object Vtreesit_str_match; | 427 | static Lisp_Object Vtreesit_str_match; |
| 428 | static Lisp_Object Vtreesit_str_pred; | 428 | static Lisp_Object Vtreesit_str_pred; |
| 429 | static Lisp_Object Vtreesit_str_empty; | ||
| 429 | 430 | ||
| 430 | /* This is the limit on recursion levels for some tree-sitter | 431 | /* This is the limit on recursion levels for some tree-sitter |
| 431 | functions. Remember to update docstrings when changing this value. | 432 | functions. Remember to update docstrings when changing this value. |
| @@ -2042,8 +2043,9 @@ If NODE is nil, return nil. */) | |||
| 2042 | treesit_initialize (); | 2043 | treesit_initialize (); |
| 2043 | 2044 | ||
| 2044 | TSNode treesit_node = XTS_NODE (node)->node; | 2045 | TSNode treesit_node = XTS_NODE (node)->node; |
| 2046 | /* ts_node_type could return NULL, see source code. */ | ||
| 2045 | const char *type = ts_node_type (treesit_node); | 2047 | const char *type = ts_node_type (treesit_node); |
| 2046 | return build_string (type); | 2048 | return type == NULL ? Vtreesit_str_empty : build_string (type); |
| 2047 | } | 2049 | } |
| 2048 | 2050 | ||
| 2049 | DEFUN ("treesit-node-start", | 2051 | DEFUN ("treesit-node-start", |
| @@ -4334,6 +4336,8 @@ the symbol of that THING. For example, (or sexp sentence). */); | |||
| 4334 | Vtreesit_str_match = build_pure_c_string ("match"); | 4336 | Vtreesit_str_match = build_pure_c_string ("match"); |
| 4335 | staticpro (&Vtreesit_str_pred); | 4337 | staticpro (&Vtreesit_str_pred); |
| 4336 | Vtreesit_str_pred = build_pure_c_string ("pred"); | 4338 | Vtreesit_str_pred = build_pure_c_string ("pred"); |
| 4339 | staticpro (&Vtreesit_str_empty); | ||
| 4340 | Vtreesit_str_empty = build_pure_c_string (""); | ||
| 4337 | 4341 | ||
| 4338 | defsubr (&Streesit_language_available_p); | 4342 | defsubr (&Streesit_language_available_p); |
| 4339 | defsubr (&Streesit_library_abi_version); | 4343 | defsubr (&Streesit_library_abi_version); |