From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63509: [PATCH] Make copy-tree work with records Date: Sun, 14 May 2023 20:57:17 -0700 Message-ID: <87fs7yfdg2.fsf@breatheoutbreathe.in> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20783"; mail-complaints-to="usenet@ciao.gmane.io" To: 63509@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 15 06:05:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1pyPSb-0005E1-Pr for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 May 2023 06:05:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyPSK-0007r8-Ru; Mon, 15 May 2023 00:05:04 -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 1pyPSI-0007qs-On for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 00:05:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pyPSI-0000y3-CO for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 00:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pyPSI-0005V4-4U for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 00:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 May 2023 04:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63509 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168412345121056 (code B ref -1); Mon, 15 May 2023 04:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 May 2023 04:04:11 +0000 Original-Received: from localhost ([127.0.0.1]:42402 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyPRT-0005TU-Ek for submit@debbugs.gnu.org; Mon, 15 May 2023 00:04:11 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:46618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyPRS-0005TK-Q5 for submit@debbugs.gnu.org; Mon, 15 May 2023 00:04:11 -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 1pyPRP-0007nd-Vg for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 00:04:08 -0400 Original-Received: from out-12.mta0.migadu.com ([91.218.175.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyPRN-0000ri-TG for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 00:04:07 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1684123441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=tb2neSjwaD6bYH5LRm45blvqFBFS9+DMrAtfX7oaiSk=; b=lof+uG5xAnATOri/BMDrKwFfQ9e4Plo1fAV/DEeHKatT4CqsKddMJJ57+ySARwP5ASt3Mn 2bUP3evCK5QA9gYqgPElnEbAuMWu7vmfrxfqYGAGb9P/DEIxU6JzzMrG5sp3TWQLpZjNL1 hUUV/kKt/E2mDZPOU8+YoHRo7ZRg/z4= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.12; envelope-from=joseph@breatheoutbreathe.in; helo=out-12.mta0.migadu.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261725 Archived-At: --=-=-= Content-Type: text/plain Hello, copy-tree does not currently work with records: (cl-defstruct foo bar) (let* ((rec (make-foo :bar "hello")) (copy (copy-tree rec t))) (setf (foo-bar copy) "goodbye") (foo-bar rec)) Expected "hello"; actual "goodbye". Attached patch fixes this behavior. Please tell me if I misunderstand the intended behavior of copy-tree. Thank you, Joseph --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-copy-tree-work-with-records.patch >From a20e119a0f60f85039726bf6ebcbe441060f9ef2 Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sun, 14 May 2023 21:02:15 -0700 Subject: [PATCH] Make copy-tree work with records --- lisp/subr.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 03d3324f3d8..9573b19ae7e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -828,7 +828,7 @@ of course, also replace TO with a slightly larger value "Make a copy of TREE. 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 as well as conses." +argument VECP, this copies vectors and records as well as conses." (declare (side-effect-free error-free)) (if (consp tree) (let (result) @@ -839,8 +839,8 @@ argument VECP, this copies vectors as well as conses." (push newcar result)) (setq tree (cdr tree))) (nconc (nreverse result) - (if (and vecp (vectorp tree)) (copy-tree tree vecp) tree))) - (if (and vecp (vectorp tree)) + (if (and vecp (or (vectorp tree) (recordp tree))) (copy-tree tree vecp) tree))) + (if (and vecp (or (vectorp tree) (recordp tree))) (let ((i (length (setq tree (copy-sequence tree))))) (while (>= (setq i (1- i)) 0) (aset tree i (copy-tree (aref tree i) vecp))) -- 2.40.1 --=-=-=--