From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel 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 Message-ID: <87sfd3jq97.fsf@yahoo.com> References: <168142374534.3804.10641447592850495150@vcs2.savannah.gnu.org> <20230413220905.CB635C13A82@vcs2.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40886"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Yuan Fu To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 14 01:51:37 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pn6j2-000AUo-Vz for ged-emacs-devel@m.gmane-mx.org; Fri, 14 Apr 2023 01:51:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pn6iW-0003AP-VW; Thu, 13 Apr 2023 19:51:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pn6iV-0003AG-12 for emacs-devel@gnu.org; Thu, 13 Apr 2023 19:51:03 -0400 Original-Received: from sonic306-22.consmr.mail.ne1.yahoo.com ([66.163.189.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pn6iP-0004wJ-Oq for emacs-devel@gnu.org; Thu, 13 Apr 2023 19:51:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681429856; bh=n1LoDbheN7Kx1U3QIbwbPyurY4SNqybb1su8ja+23DQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=lIFlXAthTuoPJQfh+6JIHthGqX8Nr6dQ3WZHT38oo586GJ5gwd7C2wV14RHIH/iBBO9aTYJNiV0WPtMrXdbmS2rfWxNL3FDnDlgUImhGR2KKf++rv6W6RuLfQXXX1idNVIHBV5RkgXCPgzzebhqfyqDRbHFVJFLPr96TrqlvefHFmFvxfYJPL6LenkIAjDJhwwYKwsQbaWrIMwuYuioaJYDhzqc6M1CABSaMqJ77d+gX7ENFD47yK2OBSjx28OY8tSv5HPZClNCj1PPKLLfrYn9HjA7N1/G5iSbZm3zeG5AcCuW+YebmOGM/Io3QH7xtWIBgQNTtLZNR7VtZmVnYHQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681429856; bh=ct+79voQ6VaaKp3+lF2vSfhPqq9vIo0/mAB+UQ3FFYo=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ovljm6mObPhKI4LrKvIcd3LolWeIMnuWHTcKLBucGZksRHjIbGlPMWILBkvas+Dsz2Z0y8+9Xi8WozfPhP+otDXYccPBOquj+ZiNp1t0l3/Uuf1FNKbYUC1zOHcHyU0zwXqlmY2366B6HmHGWEV0dcrzld7BRp9m99OsSAqz1HTjseXXNogOX2pG43t1B5kU6zrHVAn22TRtSpyv9YUg6AHHUfY1+XpkJZhToqJ6/R63Q1YDBKz1LoDLsc7BPr2DrNQ42Z7MiLlPi59Yd3EDDlC3DTOLY9B5wDP7i0vdyPwS+JPI3mcg2CSQ9GbU9kwv7uWE1pt/RL/zTk3SemP6YQ== X-YMail-OSG: coi.RqYVM1nznHN49ieUxmnErqNfkuEZIEN3RQ829vRmZyUqe6_vMcnugxJh6YM wijLSCOW4f4dxhtE.w5O06WK8DoB8HDkAZy5gXX.p2x7VkFgGkFCT5MAGQDhQ5J3eA0le9ENJAjM xflMQfx3mjTkm8p2MomqSD_.0g4etZhOGAEVpfAsOB0fwxNWFRR_12KJRr5_8mtydb48ZZiPNNL1 iL4k1VVT3Bl6Y4P7KrisMMP.3kqG13fdFUkTtFfps7BqFaIk7b.k4EpD.oSmFuUwKn4iTlsHeoMb FEDsgfKfpjMUCULDWn4pOOn1lX5To7L475q4n4yHVc9onnKlYNs18maPRYUgftwhy61B2UjvV1CU 5hd03yLWw4q6wwix43MlK5VoFR6WHZUHPyeF1qYBqKe79kFDXIQ3LNy_XAN6vEgGRKWywaW.qPsI N8mCR92vkOm8BQkGznVkQh2VHvzHVfKBQfdvLTLjMNjYB9qHG1rb_E8PY.fuKLdKW2Cwd08Cjf05 tt2vvdOwIK9SW4jEK4j8Y4XpZJZv_OEcXZwZnsaQJ1DltJxasUmeGAX5e45at0lGwcgOH_UMpMRc NAjO0G1OvnAyYAQnu_sU_3HxCyld1BuxdUYA98tqeHAQiHXk0DfPwXpJmCaTCnvczujm_8wHhvg. WoeBexD1Ry53G0xY1pfLZ2VW5Wj3jOsEL4sdiLlvpN.j.2I.j3OauXHjWLOnA._JNipd6S0JSial zu9DUjjJbxrw4neAThVueSt3PGOtWYz0kLk.PXae6qrfYCVrNDVSY.hnen0QS4Wg5LyTUNBKX.uy 3Zgnd9eWJ3WR9DdWTrJOEJEBjlhKBLRisUBsmOfgR0 X-Sonic-MF: X-Sonic-ID: b473d991-5aee-4a9a-b642-be01f9243263 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Thu, 13 Apr 2023 23:50:56 +0000 Original-Received: by hermes--production-sg3-6d6fb994f6-djl48 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID fffba3c5ee6f91ad84e1500fbbdfeb53; Thu, 13 Apr 2023 23:50:48 +0000 (UTC) In-Reply-To: <20230413220905.CB635C13A82@vcs2.savannah.gnu.org> (Yuan Fu's message of "Thu, 13 Apr 2023 18:09:05 -0400 (EDT)") X-Mailer: WebService/1.1.21365 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.189.84; envelope-from=luangruo@yahoo.com; helo=sonic306-22.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:305299 Archived-At: Yuan Fu 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.