From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] Make purecopy create hash tables properly
Date: Fri, 27 Jan 2017 18:10:24 -0500 [thread overview]
Message-ID: <jwv60l0p0vp.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: CA+T2Sh15CUqGRUto5W6O5JGq1kJWj0w07HX9fMxGiCm9JNZ0bA@mail.gmail.com
> - 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))
next prev parent reply other threads:[~2017-01-27 23:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 18:37 [PATCH] Make purecopy create hash tables properly Vibhav Pant
2017-01-27 22:06 ` Paul Eggert
2017-01-27 23:10 ` Stefan Monnier [this message]
2017-01-28 10:25 ` Vibhav Pant
2017-01-28 10:26 ` Vibhav Pant
2017-01-28 14:58 ` Stefan Monnier
2017-01-28 20:06 ` Vibhav Pant
2017-01-29 2:18 ` Stefan Monnier
2017-01-29 17:23 ` Vibhav Pant
2017-01-29 17:58 ` Stefan Monnier
2017-01-29 19:14 ` Vibhav Pant
2017-01-29 19:41 ` Stefan Monnier
2017-01-30 12:43 ` Vibhav Pant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv60l0p0vp.fsf-monnier+gmane.emacs.devel@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).