From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: purecopying strings in add-hook? Date: Tue, 30 Apr 2019 15:59:27 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="79686"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Dan Nicolaescu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 30 22:00:00 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLYv1-000KYD-1f for ged-emacs-devel@m.gmane.org; Tue, 30 Apr 2019 21:59:59 +0200 Original-Received: from localhost ([127.0.0.1]:52585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLYv0-00081l-2p for ged-emacs-devel@m.gmane.org; Tue, 30 Apr 2019 15:59:58 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:47183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLYuZ-0007rd-BS for emacs-devel@gnu.org; Tue, 30 Apr 2019 15:59:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLYuY-0000gq-7h for emacs-devel@gnu.org; Tue, 30 Apr 2019 15:59:31 -0400 Original-Received: from mail01.iro.umontreal.ca ([132.204.25.201]:49926) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hLYuY-0000gE-0C for emacs-devel@gnu.org; Tue, 30 Apr 2019 15:59:30 -0400 Original-Received: from mail01.iro.umontreal.ca (mail01.iro.umontreal.ca [127.0.0.1]) by mail01.iro.umontreal.ca (Postfix) with ESMTP id 2147387D042F for ; Tue, 30 Apr 2019 15:59:29 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; h=content-type:content-type:mime-version:user-agent:date:date :message-id:subject:subject:to:from:from; s=dkim; t=1556654368; x=1557518369; bh=9xnemK9rDK4+ycq+rMABuUDoEIZwKZ3xgl+kKstNoEk=; b= UYbCYzBqfixIv+FAkrDMynuMP4uU15e8vFITK46CEc8hPabrHHd9dLF2tqLrogUL T6nENY+5iDc+fyGbLmJi4lWZ5qtA7kpLM6L/HnjP/reJfa1huot17hN3usWn+ov6 ovbrqGZZjO7BRCKX1/Qn0AktC6WfPjzBEwOpOHQDhyhBC6CGkFZps34gxb7SuQ7Z dh4PABpOIc4Sx+PKaGPoyf6jH6Kk6sVnFy+MaQyyoI88tiOyhBtAY2HG2atVxQ09 /qdtY9QftYUE9iKOjXE1y0jmXtwroZsKvS77FvZ8PQpKkEck1uSJzywfQyQDG4oz JCjxUHyOWrV4pEytD6TP9Q== X-Virus-Scanned: amavisd-new at iro.umontreal.ca Original-Received: from mail01.iro.umontreal.ca ([127.0.0.1]) by mail01.iro.umontreal.ca (mail01.iro.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id He3ZP9PddfpW for ; Tue, 30 Apr 2019 15:59:28 -0400 (EDT) Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E061587D0421; Tue, 30 Apr 2019 15:59:27 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.201 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:236071 Archived-At: Hi Dan, Do you remember why we purecopy the "function" argument of `add-hook` when it's a string(!)? This was introduced by commit ff917d632134b76be4c764dd6cf3ac1984b371a4, appended below, Stefan diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1f0ddc1217..3b58fe1125 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2009-11-11 Dan Nicolaescu + * subr.el (add-hook): Purecopy strings. + (eval-after-load): Purecopy load-history-regexp and the form. + * custom.el (custom-declare-group): Purecopy load-file-name. * subr.el (menu-bar-separator): New defconst. diff --git a/lisp/subr.el b/lisp/subr.el index bb3b37ebbf..fb832608cd 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1218,6 +1218,8 @@ add-hook (setq hook-value (list hook-value))) ;; Do the actual addition if necessary (unless (member function hook-value) + (when (stringp function) + (setq function (purecopy function))) (setq hook-value (if append (append hook-value (list function)) @@ -1660,14 +1662,14 @@ eval-after-load ;; Add this FORM into after-load-alist (regardless of whether we'll be ;; evaluating it now). (let* ((regexp-or-feature - (if (stringp file) (load-history-regexp file) file)) + (if (stringp file) (setq file (purecopy (load-history-regexp file))) file)) (elt (assoc regexp-or-feature after-load-alist))) (unless elt (setq elt (list regexp-or-feature)) (push elt after-load-alist)) ;; Add FORM to the element unless it's already there. (unless (member form (cdr elt)) - (nconc elt (list form))) + (nconc elt (purecopy (list form)))) ;; Is there an already loaded file whose name (or `provide' name) ;; matches FILE?