diff --git a/src/alloc.c b/src/alloc.c index f7b6515f4e..b64f2de224 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5434,6 +5434,33 @@ make_pure_vector (ptrdiff_t len) return new; } +static struct Lisp_Hash_Table * make_pure_hash_table(struct Lisp_Hash_Table *table); + +/* Return a hash table with the same parameters and values as that of TABLE + allocated from pure space. */ +static struct Lisp_Hash_Table * +make_pure_hash_table(struct Lisp_Hash_Table *table) +{ + struct Lisp_Hash_Table *pure = pure_alloc (sizeof *pure, Lisp_Vectorlike); + pure->header = table->header; + pure->weak = purecopy (table->weak); + pure->rehash_size = purecopy (table->rehash_size); + pure->rehash_threshold = purecopy(table->rehash_threshold); + pure->hash = purecopy (table->hash); + pure->next = purecopy (table->next); + pure->next_free = purecopy (table->next_free); + pure->index = purecopy (table->index); + pure->count = table->count; + pure->key_and_value = purecopy (table->key_and_value); + pure->test = table->test; + + if (table->next_weak) { + pure->next_weak = make_pure_hash_table (table->next_weak); + } + + return pure; +} + DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0, doc: /* Make a copy of object OBJ in pure storage. Recursively copies contents of vectors and cons cells. @@ -5477,7 +5504,11 @@ purecopy (Lisp_Object obj) obj = make_pure_string (SSDATA (obj), SCHARS (obj), SBYTES (obj), STRING_MULTIBYTE (obj)); - 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);