From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Catch arbitrary signal and throw it later in C Date: Thu, 13 Apr 2023 00:24:18 -0700 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21731"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 13 09:25:27 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 1pmrKg-0005N3-Qc for ged-emacs-devel@m.gmane-mx.org; Thu, 13 Apr 2023 09:25:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmrJt-0001o4-Jd; Thu, 13 Apr 2023 03:24:37 -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 1pmrJs-0001nv-5g for emacs-devel@gnu.org; Thu, 13 Apr 2023 03:24:36 -0400 Original-Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmrJq-0000p2-1V for emacs-devel@gnu.org; Thu, 13 Apr 2023 03:24:35 -0400 Original-Received: by mail-pj1-x1035.google.com with SMTP id hg14-20020a17090b300e00b002471efa7a8fso676516pjb.0 for ; Thu, 13 Apr 2023 00:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681370672; x=1683962672; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=LQGT8U076CyKjXCnHX9R2xZW2/ci6m/UNyAhgIshNbM=; b=cLSi9/60Fnvp7U1mEDf0qyg/ZQ3smF7GcrUw0HANycS9tMO+TgZfJS3FK7XZAh2XTC gTWcHXXQPzIZppPFcR/oPHacalIKvUQs58o+nTZzhIMnNRN/mCMAnZSLhNa0er7Eo32E 4oTSaxK89mPWuwxcKUxUJO1bSyUwh1y+l8MOIIm6CjEBxdNiKfaUn0M0OPvEUDFgxoGs RtVqiphHwxl+vziLSMbZZWkRsC8hzHtR/A9Nu2l60BWNV50GAFpGIbTxqwh2NCQQQSFU 77LiEp2jjILJdjBk9r1JclRHAhE8MZdicomgosfQBYtZ9nvT22LWsN5vLhg1y9O37Y50 LPDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681370672; x=1683962672; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LQGT8U076CyKjXCnHX9R2xZW2/ci6m/UNyAhgIshNbM=; b=curoAbvIPOlPqXBXyAnS0ylsvZjR4KXQEAYUjAv+8mBMcbLkXsbNFQ/U9yB6EWys1e 5EZrH58ESUsxVG5QbDqLoTrp1DDGisq/92Xbwc+ZMWGvEXyR0NU06CfmT2OxeBMoYgXE 3nMsrQL0DP+F7aL90HpmMzYKceHR56J29XDN8FxhvtVNX4AbxxwfL7uNpCEsUIxVIit6 0fVNQAP+S+Ut0bEYYb9GbCKhpI53ZXm4pCNjO/jmBYfo6ADSxKL42F0FNc7L+5ZJd67R 4JfklNBjfSPkLuZ46fWchQokNaCPXK7Qybsp3Tc4Sz5d2JYftd4IACbYHP+D+RaehcCq uf/Q== X-Gm-Message-State: AAQBX9fCOfc32D7i/Bb9giuo/Sz5Xl/Zo0x9owiraBC7bq8VuxAM/3nw a03Hhu5YDrO2KQ2Wrs5NQrSzX7ycInxXPw== X-Google-Smtp-Source: AKy350Z1Zzo43OKRCavjnc2UbrS2Zckb+Qt2Jpc8+37VyUjexu1Jm21sXwNrrcOCXI+oHuUFvWUOAg== X-Received: by 2002:a05:6a20:4712:b0:cc:5f27:d003 with SMTP id ek18-20020a056a20471200b000cc5f27d003mr1035852pzb.56.1681370671886; Thu, 13 Apr 2023 00:24:31 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id s22-20020a63dc16000000b00502f4c62fd3sm765147pgg.33.2023.04.13.00.24.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Apr 2023 00:24:31 -0700 (PDT) X-Mailer: Apple Mail (2.3731.500.231) Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=casouri@gmail.com; helo=mail-pj1-x1035.google.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, 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:305282 Archived-At: Say I have an arbitrary Lisp function func, and need to evaluate it in = C. But after evaluating the function, I need to do some clean up = (freeing something). Would be be possible to catch any signal thrown by = evaluating the function func, and throw it after cleaning up? I=E2=80=99m aware of safe_call and internal_condition_case_n. In = particular, what I described can probably be implemented with = internal_condition_case_n with a handler. But I wonder if there are = better/existing ways to do this? The real scenarios is this: treesit-search-forward and friends takes a = PRED argument, which can be either a regexp string or a predicate = function. In the meantime, treesit-search-forward and friends need to = clean up a tree-sitter cursor object before they return. So if this = predicate function signals in the middle of treesit-search-forward, the = tree-sitter cursor would be leaked. I can slap on a safe_call when = evaluating the predicate function, but I think throwing the signal would = be more user-friendly. (Plus safe_call will say =E2=80=9CAn error = occurred during redisplay=E2=80=9D, which isn=E2=80=99t necessarily = true) Yuan