From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Make purecopy create hash tables properly Date: Fri, 27 Jan 2017 18:10:24 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1485558675 13412 195.159.176.226 (27 Jan 2017 23:11:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jan 2017 23:11:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 28 00:11:08 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXFfL-0001Jf-RX for ged-emacs-devel@m.gmane.org; Sat, 28 Jan 2017 00:10:47 +0100 Original-Received: from localhost ([::1]:49203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXFfR-0000kd-18 for ged-emacs-devel@m.gmane.org; Fri, 27 Jan 2017 18:10:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXFfL-0000kY-6g for emacs-devel@gnu.org; Fri, 27 Jan 2017 18:10:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXFfI-0004cZ-2j for emacs-devel@gnu.org; Fri, 27 Jan 2017 18:10:47 -0500 Original-Received: from [195.159.176.226] (port=39686 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXFfH-0004cL-S0 for emacs-devel@gnu.org; Fri, 27 Jan 2017 18:10:43 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cXFf9-0000N9-Ne for emacs-devel@gnu.org; Sat, 28 Jan 2017 00:10:35 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:piGGGc4WknDMZp5lbxe4A3U87GU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:211664 Archived-At: > - else if (COMPILEDP (obj) || VECTORP (obj) || HASH_TABLE_P (obj)) > + else if (HASH_TABLE_P (obj)) { > + struct Lisp_Hash_Table *h = make_pure_hash_table(XHASH_TABLE(obj)); > + XSET_HASH_TABLE(obj, h); > + } > + else if (COMPILEDP (obj) || VECTORP (obj)) > { > struct Lisp_Vector *objp = XVECTOR (obj); > ptrdiff_t nbytes = vector_nbytes (objp); Oh, indeed, I see what was the problem: We relied on the generic vector-copy code for the hash-tables, whereas those do not only contain Lisp_Object fields (and they also contain some Lisp_Object fields which are beyond the part copied by the generic code). So another way to fix the code would something like the patch below (100% untested). Whichever option you take, please pay attention to `next_weak` because in your patch, you'll end up purecopying some of the other weak hash-tables but you won't register this one as a weak hash table, so it will lead to serious problems. Stefan diff --git a/src/alloc.c b/src/alloc.c index 1a6d4e2d56..c15bbf3a2f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5519,6 +5519,18 @@ purecopy (Lisp_Object obj) memcpy (vec, objp, nbytes); for (i = 0; i < size; i++) vec->contents[i] = purecopy (vec->contents[i]); + if (HASH_TABLE_P (obj)) + { + struct Lisp_Hash_Table *old = (struct Lisp_Hash_Table *) objp; + struct Lisp_Hash_Table *new = (struct Lisp_Hash_Table *) vec; + new->count = new->count; + new->key_and_value = purecopy (old->key_and_value); + new->test = old->test; + new->next_weak = old->next_weak + if (!NILP (old->weak)) + /* Insert ourselves in the list of weak hash tables. */ + old->next_weak = new; + } XSETVECTOR (obj, vec); } else if (SYMBOLP (obj))