emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 2c3ca78e811: Fix bugs in treesit.o


From: Po Lu
Subject: master 2c3ca78e811: Fix bugs in treesit.o
Date: Thu, 13 Apr 2023 20:01:37 -0400 (EDT)

branch: master
commit 2c3ca78e811b288aa4801f78c11ba9ddf9ffe02c
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix bugs in treesit.o
    
    * src/treesit.c (treesit_traverse_match_predicate): Remove
    redundant cast.
    (treesit_search_forward, treesit_traverse_cleanup_cursor)
    (Ftreesit_search_subtree, Ftreesit_search_forward)
    (Ftreesit_induce_sparse_tree): Fix coding style and specpdl
    unwinding.
---
 src/treesit.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/treesit.c b/src/treesit.c
index 09d998b56c8..45b5ab15390 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3243,10 +3243,8 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, 
Lisp_Object pred,
       Lisp_Object cdr = XCDR (pred);
 
       if (EQ (car, Qnot))
-       {
-         return !treesit_traverse_match_predicate (cursor, XCAR (cdr),
-                                                   parser, named);
-       }
+       return !treesit_traverse_match_predicate (cursor, XCAR (cdr),
+                                                 parser, named);
       else if (EQ (car, Qor))
        {
          FOR_EACH_TAIL (cdr)
@@ -3287,6 +3285,7 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, 
Lisp_Object pred,
    forward, false backward.  If SKIP_ROOT is true, don't match ROOT.
 
    This function may signal if the predicate function signals.  */
+
 static bool
 treesit_search_dfs (TSTreeCursor *cursor,
                    Lisp_Object pred, Lisp_Object parser,
@@ -3325,6 +3324,7 @@ treesit_search_dfs (TSTreeCursor *cursor,
    position is undefined.
 
    This function may signal if the predicate function signals.  */
+
 static bool
 treesit_search_forward (TSTreeCursor *cursor,
                        Lisp_Object pred, Lisp_Object parser,
@@ -3334,8 +3334,7 @@ treesit_search_forward (TSTreeCursor *cursor,
      nodes.  This way repeated call of this function traverses each
      node in the tree once and only once:
 
-     (while node (setq node (treesit-search-forward node)))
-  */
+     (while node (setq node (treesit-search-forward node)))  */
   bool initial = true;
   while (true)
     {
@@ -3362,10 +3361,12 @@ treesit_search_forward (TSTreeCursor *cursor,
     }
 }
 
-/** Cleanup function for cursor.  */
-static void treesit_traverse_cleanup_cursor(void *cursor)
+/* Clean up the given tree cursor CURSOR.  */
+
+static void
+treesit_traverse_cleanup_cursor (void *cursor)
 {
-  ts_tree_cursor_delete ((TSTreeCursor *) cursor);
+  ts_tree_cursor_delete (cursor);
 }
 
 DEFUN ("treesit-search-subtree",
@@ -3421,10 +3422,7 @@ Return the first matched node, or nil if none matches.  
*/)
       return_value = make_treesit_node (parser, node);
     }
 
-  unbind_to (count, Qnil);
-
-  ts_tree_cursor_delete (&cursor);
-  return return_value;
+  return unbind_to (count, return_value);
 }
 
 DEFUN ("treesit-search-forward",
@@ -3486,10 +3484,7 @@ always traverse leaf nodes first, then upwards.  */)
       return_value = make_treesit_node (parser, node);
     }
 
-  unbind_to (count, Qnil);
-
-  ts_tree_cursor_delete (&cursor);
-  return return_value;
+  return unbind_to (count, return_value);
 }
 
 /* Recursively traverse the tree under CURSOR, and append the result
@@ -3616,8 +3611,8 @@ a regexp.  */)
 
   unbind_to (count, Qnil);
 
-  ts_tree_cursor_delete (&cursor);
   Fsetcdr (parent, Fnreverse (Fcdr (parent)));
+
   if (NILP (Fcdr (parent)))
     return Qnil;
   else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]