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: Re: Calling Lisp in C functions Date: Wed, 22 Sep 2021 20:59:00 -0700 Message-ID: <87357FA2-4AF8-4E7E-BD26-1852D9C8CE6F@gmail.com> References: <83y27pw4c3.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) 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="14568"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs developers To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 23 05:59:54 2021 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 1mTFtp-0003YT-Io for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Sep 2021 05:59:53 +0200 Original-Received: from localhost ([::1]:46046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTFtn-0002W0-LL for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Sep 2021 23:59:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTFt3-0001rN-E6 for emacs-devel@gnu.org; Wed, 22 Sep 2021 23:59:05 -0400 Original-Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:37836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTFt2-0004UN-0Z; Wed, 22 Sep 2021 23:59:05 -0400 Original-Received: by mail-qt1-x831.google.com with SMTP id e16so2402123qts.4; Wed, 22 Sep 2021 20:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=dHEu333H+cJEVr6zh3S1HeY+yvRfKQuLh5ToXJH+XD8=; b=Yc0Jh1XgSKOOhmUE1nG3D0iuWvN7Ky01Xic853Pi5fDBtsESqUsnw7yP3yePlg44Vo jg5T9/EaSQYl0oNRLNDGinuOtjcn3UM3xnWzZus83m2X1iSNZ7CP99C/RbmhKpzNT+Y+ N2HZuqg+7F9v/Ut0Wand/2oEfKbbAQYHMhKM8aR7y1CLJFN5gKvYpBr3G9HAkEHXWEFH /B6P7RWJA7vFmwjmmmrOZkMwYSxl2aBnTC9Bu/Sm9iEuWFbUbi4g7MLbV1/9t0SrQXl+ 5ScOfrC4KB+YzcqjGUnLCUNpU781VntQLlJAnDGOwNuK0JsYA9tay7bYwZcjBbbJSSCU FXJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=dHEu333H+cJEVr6zh3S1HeY+yvRfKQuLh5ToXJH+XD8=; b=s3LNRGQTS4JDyxI9jnc29sIW/T4mDhLIPWzKdBvtAEzpE9HVp1LgSQtqMgshtEUPig //aBM3hH1kpsLTCKYsug2s53Snk1mG97J3K5YgCO1CgErNEb9EGbyJukA5alL8yAWIIQ bya3VnFIIQaAqXJweVhyIvnuktBPteWGIGxTnSPVGK1hHZ/WBsk7x1O94D9z5iCPwVXL bKihXyqoWHzm2U7bWEDiQg9yb84r3ticPPs5E0+iY61bqUUiRD/GAWRFYqNSkD4wrM3H USoKu58t/E4TnCQZE9yryDnSJwBtJUIDguwgkX8cBhPzY0bekF4XAf2hhOBZL+MnrO7x hLRQ== X-Gm-Message-State: AOAM531h/EWuG46fzqXAeqE+LONSK7dWwJsmODcEsYicoxncUdcxVcf5 X4oRYmxQMja+xJYLwDEifJmDp56E7cEuBQ== X-Google-Smtp-Source: ABdhPJz3IrVhMdJaAXNxKn8yTCZ4KyqS/mYszhz9YUXSeY1iOfuKTAMuW5nMBMUCgdmQuddKk/show== X-Received: by 2002:ac8:4089:: with SMTP id p9mr2719433qtl.363.1632369542016; Wed, 22 Sep 2021 20:59:02 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c9f:392c:6194:3fb2:fab2]) by smtp.gmail.com with ESMTPSA id g19sm3213416qki.58.2021.09.22.20.59.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Sep 2021 20:59:01 -0700 (PDT) In-Reply-To: <83y27pw4c3.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.13) Received-SPF: pass client-ip=2607:f8b0:4864:20::831; envelope-from=casouri@gmail.com; helo=mail-qt1-x831.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.23 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" Xref: news.gmane.io gmane.emacs.devel:275352 Archived-At: > On Sep 21, 2021, at 10:45 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Tue, 21 Sep 2021 12:38:21 -0700 >>=20 >> What=E2=80=99s the best way to evaluate Lisp or call a Lisp function = that could signal in a C function and then free allocated memory? I = assume that I can=E2=80=99t just call the Lisp function and hope it = doesn=E2=80=99t signal. >=20 > You want to catch the errors in Lisp that you call from C? If so, use > the safe_call functions we already have. >=20 > If all you want is make sure memory will be allocated, but don't mind > if the signal thrown by Lisp gets back to command loop, use > record_unwind_protect to register a function which will release the > memory. Thanks, I still don=E2=80=99t know how does stack works so here=E2=80=99s = some naive questions: I tried to write ptrdiff_t count =3D SPECPDL_INDEX (); record_unwind_protect_ptr (ts_delete_cursor, cursor); ... return unbind_to (count, xxx); But it give a type error, because ts_delete_cursor doesn=E2=80=99t take = a void*. I guess I need to define a wrapper function to avoid that = error? Can I use record_unwind_protect_ptr more than once? What does = that count mean? What is specpdl? Yuan=