From: Po Lu <luangruo@yahoo.com>
To: emacs-devel@gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: Re: master a5eb9f6ad4e 2/3: Catch signals produced by PRED in tree-sitter search functions
Date: Fri, 14 Apr 2023 07:50:44 +0800 [thread overview]
Message-ID: <87sfd3jq97.fsf@yahoo.com> (raw)
In-Reply-To: <20230413220905.CB635C13A82@vcs2.savannah.gnu.org> (Yuan Fu's message of "Thu, 13 Apr 2023 18:09:05 -0400 (EDT)")
Yuan Fu <casouri@gmail.com> writes:
> +/** Cleanup function for cursor. */
> +static void treesit_traverse_cleanup_cursor(void *cursor)
> +{
> + ts_tree_cursor_delete ((TSTreeCursor *) cursor);
> +}
Please fix your coding style: place a newline after `void', and a space
after `treesit_traverse_cleanup_cursor'.
> DEFUN ("treesit-search-subtree",
> Ftreesit_search_subtree,
> Streesit_search_subtree, 2, 5, 0,
> @@ -3288,12 +3294,18 @@ Return the first matched node, or nil if none matches. */)
> if (!treesit_cursor_helper (&cursor, XTS_NODE (node)->node, parser))
> return return_value;
>
> + specpdl_ref count = SPECPDL_INDEX ();
> + record_unwind_protect_ptr (treesit_traverse_cleanup_cursor, &cursor);
> +
> if (treesit_search_dfs (&cursor, predicate, parser, NILP (backward),
> NILP (all), the_limit, false))
> {
> TSNode node = ts_tree_cursor_current_node (&cursor);
> return_value = make_treesit_node (parser, node);
> }
> +
> + unbind_to (count, Qnil);
> +
> ts_tree_cursor_delete (&cursor);
> return return_value;
> }
> @@ -3345,12 +3357,18 @@ always traverse leaf nodes first, then upwards. */)
> if (!treesit_cursor_helper (&cursor, XTS_NODE (start)->node, parser))
> return return_value;
>
> + specpdl_ref count = SPECPDL_INDEX ();
> + record_unwind_protect_ptr (treesit_traverse_cleanup_cursor, &cursor);
> +
> if (treesit_search_forward (&cursor, predicate, parser,
> NILP (backward), NILP (all)))
> {
> TSNode node = ts_tree_cursor_current_node (&cursor);
> return_value = make_treesit_node (parser, node);
> }
> +
> + unbind_to (count, Qnil);
> +
> ts_tree_cursor_delete (&cursor);
> return return_value;
> }
> @@ -3467,8 +3485,14 @@ a regexp. */)
> to use treesit_cursor_helper. */
> TSTreeCursor cursor = ts_tree_cursor_new (XTS_NODE (root)->node);
>
> + specpdl_ref count = SPECPDL_INDEX ();
> + record_unwind_protect_ptr (treesit_traverse_cleanup_cursor, &cursor);
> +
> treesit_build_sparse_tree (&cursor, parent, predicate, process_fn,
> the_limit, parser);
> +
> + unbind_to (count, Qnil);
> +
> ts_tree_cursor_delete (&cursor);
> Fsetcdr (parent, Fnreverse (Fcdr (parent)));
> if (NILP (Fcdr (parent)))
Unless you remove the redundant call to `ts_tree_cursor_delete' after
`unbind_to', you get a double free.
next parent reply other threads:[~2023-04-13 23:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <168142374534.3804.10641447592850495150@vcs2.savannah.gnu.org>
[not found] ` <20230413220905.CB635C13A82@vcs2.savannah.gnu.org>
2023-04-13 23:50 ` Po Lu [this message]
[not found] ` <20230413220905.E3C7BC13A84@vcs2.savannah.gnu.org>
2023-04-13 23:55 ` master 361c5fc2d8e 3/3: Support more predicates in tree-sitter search functions Po Lu
2023-04-14 1:57 ` Yuan Fu
2023-04-14 4:31 ` Po Lu
2023-04-15 0:05 ` Yuan Fu
2023-04-15 0:18 ` Po Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfd3jq97.fsf@yahoo.com \
--to=luangruo@yahoo.com \
--cc=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.