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: New function safe-copy-tree. Date: Tue, 07 Mar 2023 14:12:37 +0200 Message-ID: <83cz5k7oay.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31412"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 07 13:13:18 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 1pZWBw-0007zN-RB for ged-emacs-devel@m.gmane-mx.org; Tue, 07 Mar 2023 13:13:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZWBQ-0003zH-Os; Tue, 07 Mar 2023 07:12:44 -0500 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 1pZWBO-0003z1-Tr for emacs-devel@gnu.org; Tue, 07 Mar 2023 07:12:43 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZWBO-0006es-0w; Tue, 07 Mar 2023 07:12:42 -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=GU51+MxvBnazyKxUtXiPXSqaZiqP6ZzPDntQrFfow14=; b=N+jXEjbrP+ev xAklEJGW5HLziRlQqwQ/YksCSDS2mpdFPeqhYveh4YgpCjNo0+3J+fkPcm30JUST9ffF1ZxkAERxS XzLrYLkcA/Hc6oOu94QZ1Da4fhj14sZsHUNiiKmPGsM0fhWaSyeQ8PAA7A9CtoHntNC44Qb14/Exz sXfmqSdpuRglL0X4cVuLiLgs1L1bggnpfgLxSAmE+dWGhlOqcTRIikL7Ytmy/4SPq517H8EdFsngF 6qOl/K89I9dptxxX48YWz57CwxWSzTz+jx1SZcULMiyZ69CTOgeQQOcsNp1cLlEq5CuumBVtX4B/v PaP9OICpXcrbemrNonj04Q==; Original-Received: from [87.69.77.57] (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 1pZWBN-0005gM-8P; Tue, 07 Mar 2023 07:12:41 -0500 In-Reply-To: (message from Alan Mackenzie on Mon, 6 Mar 2023 21:14:13 +0000) 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:304078 Archived-At: > Date: Mon, 6 Mar 2023 21:14:13 +0000 > From: Alan Mackenzie > > In order to fix bug #61962, I'm intending to introduce a new function > safe-copy-tree in subr.el. It is like copy-tree, except it works with > circular lists as well as normal ones. > > My current implementation looks like this: This is for master, right? > +(defvar safe-copy-tree--seen nil > + "A hash table for conses/vectors/records already seen by safe-copy-tree-1. > +It's key is a cons or vector/record seen by the algorithm, and its value is ^^^^ "Its" > +(defun safe-copy-tree (tree &optional vecp) > + "Make a copy of TREE, taking circular structure into account. > +If TREE is a cons cell, this recursively copies both its car and its cdr. > +Contrast to `copy-sequence', which copies only along the cdrs. With second > +argument VECP, this copies vectors and records as well as conses." > + (setq safe-copy-tree--seen (make-hash-table :test #'eq)) > + (safe-copy-tree--1 tree vecp)) Where is this hash table deleted? And shouldn't this be inside unwind-protect, so that you could be sure the hash table is always reset to nil when the processing is done?