From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: using finalizers Date: Sat, 01 Jan 2022 20:20:22 +0200 Message-ID: <837dbjfhcp.fsf@gnu.org> References: <878rw1pvcw.fsf@logand.com> <83r19tgqlq.fsf@gnu.org> <87v8z5nmsp.fsf@logand.com> <83ilv5gdsk.fsf@gnu.org> <87ee5rl4nq.fsf@logand.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32926"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Tomas Hlavaty Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 01 19:21:19 2022 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 1n3j0I-0008PV-JA for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 19:21:18 +0100 Original-Received: from localhost ([::1]:34206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3j0H-0007lu-AS for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 13:21:17 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3izP-0006re-VK for emacs-devel@gnu.org; Sat, 01 Jan 2022 13:20:24 -0500 Original-Received: from [2001:470:142:3::e] (port=36986 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3izP-0002Ui-AX; Sat, 01 Jan 2022 13:20:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=yFYtdzJjw3Kn0GAIKjUy1hEi5azsIv32wJaerrmYWG8=; b=Tw+E08Ni75s8 +0uA7yblDKJm/UoFl+EZ03hbkF/fG4fvPO/dN0K7fJwUwlkzUygtaVPtVFltUgbasHva72XBv5tAh olrzxQR3yO3QMBeOdK+RkfN0DGtrSlV6yHsxe/EQGzvRhezZhEpC0ImDnHVRnxRlcuAlahV0FE7ZI Jodg5eOO6B4jCRAhGi7bgxzELDm+3OvTsCVd47U58Jguo4dYW5hW9eN39P7DpZklIzliTwam9ktUl tCPEmjQhn2PSRdOqvJVM6yVAolOxPheIvltFMq80i5ec7D+9PQbPX34xwGG8GFg5Q8mIgH1RC5wl0 M2mTD7teYolL/2jL50Z8rA==; Original-Received: from [87.69.77.57] (port=3041 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3izP-0008Ux-5Q; Sat, 01 Jan 2022 13:20:23 -0500 In-Reply-To: <87ee5rl4nq.fsf@logand.com> (message from Tomas Hlavaty on Sat, 01 Jan 2022 18:58:01 +0100) 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" Xref: news.gmane.io gmane.emacs.devel:283810 Archived-At: > From: Tomas Hlavaty > Cc: andpuke@foxmail.com, emacs-devel@gnu.org > Date: Sat, 01 Jan 2022 18:58:01 +0100 > > On Fri 31 Dec 2021 at 14:27, Eli Zaretskii wrote: > > That does happen, but you seem to expect more: you expect that the > > object is collected as soon as you do something in Lisp to break the > > binding between the object and the variable that was bound to it. > > No, that's not what I expect. I even said that. What I meant is that I > did not expect some other code not under my control to keep references > to the object forever preventing gc to run the finalizer eventually, > which is how I understood your reply. Not "forever", of course, but depending on the program a reference to an object could live for quite some time. Having a reference on the C stack is the most sinister of these. > On another note, I see that finalizers are rarely used and tested: > > ./test/src/alloc-tests.el33: (should (equal (type-of (make-finalizer nil)) 'finalizer))) > ./lisp/emacs-lisp/generator.el642: (make-finalizer > > For example the cps-generate-evaluator function has 70 lines and it is > not obvious to me, that the use of finalizer is not buggy. > > Do you have an advice, how are programmers supposed to test finalizers? > > My original issue did not run the finalizer because of a bug in my use > of letrec. Unless there is a good way to actually trigger the > finalizer, there is no good way to test such code paths. Or shall the > programmers just hope for the best? I hope Stefan could answer that, but it sounds like he doesn't understand the issue you are describing (and neither do I, frankly).