From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: using finalizers Date: Sat, 01 Jan 2022 15:55:38 -0500 Message-ID: References: <878rw1pvcw.fsf@logand.com> <83r19tgqlq.fsf@gnu.org> <87v8z5nmsp.fsf@logand.com> <83ilv5gdsk.fsf@gnu.org> <87ee5rl4nq.fsf@logand.com> <837dbjfhcp.fsf@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="19845"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Tomas Hlavaty , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 01 21:56:41 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 1n3lQf-0004z3-6N for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 21:56:41 +0100 Original-Received: from localhost ([::1]:40296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3lQd-0007dd-67 for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 15:56:39 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3lPl-0006rN-4t for emacs-devel@gnu.org; Sat, 01 Jan 2022 15:55:45 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:43082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3lPj-00013k-Bh; Sat, 01 Jan 2022 15:55:44 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 426AF441431; Sat, 1 Jan 2022 15:55:41 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id BE3C9441420; Sat, 1 Jan 2022 15:55:39 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1641070539; bh=ydTzCj8CPkeJUJwra2jZ2oIN8+oVtMeaNczbVlL/YLE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=bzBurXvXZHXg3P+fituJa7TMDZTLNkEnLiGsFDuaFdLcb9HzrhvWmsVkK61/ur+7j ZanLNEhmlNvIapxC4kYmj3U6dpBcaxNi2rTrmZZMP6zFLz+uoh5sLxeaY5HbnfQkfl Yk83K78W5U+jALMmh7KMg/IBRDM5CSS3X2X2wsl4TEA3YL+TKU8tuYjMso2A+jDnWS QTwj3kMaaYAoLOGQp+all6+ZJbCtIZrdzlTaEpfuRScSRz+80UVUaJdnQDsvrwRhms nzdgE/7zfAkmtWbyB7iu/SMEh1f7j8jwXeO6iUf6lOmoTcI3T/E6hYygb8uIjPEwQq aB3vsojm6h/xA== Original-Received: from ceviche (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 858B61202B9; Sat, 1 Jan 2022 15:55:39 -0500 (EST) In-Reply-To: <837dbjfhcp.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 01 Jan 2022 20:20:22 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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" Xref: news.gmane.io gmane.emacs.devel:283821 Archived-At: >> 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. A common problem during manual experimentation is to have the offending value stashed in `values`. >> 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? Calling `garbage-collect` should usually work well enough for tests (tho this may have to be tweaked if/when we get a fancier GC), tho there's always the risk that some bitpattern somewhere inside the stack happens to look like a pointer to your finalizer (or an object that transitively references it), so no I don't know of a way to *reliably* get a finalizer to run. You can minimize the risk of a bitpattern getting in the way by trying to trigger a GC at a point where the C stack is as small as possible, but it still can't rule out the problem completely. Stefan