From a38b50b84ddd126bf2cdecfce0ba1e878b05c7a9 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Wed, 29 May 2024 10:12:04 +0200 Subject: [PATCH 2/5] Use igc_make_byte_vec for hash tables This avoids the need for finalization. * src/alloc.c (hash_table_alloc_bytes, hash_table_free_bytes): Delegate to igc_make_byte_vec. * src/igc.c (fix_hash_table): Fix hash, next, and index vectors. (finalize_hash_table): Delete. No longer needed. (finalize_vector, maybe_finalize): Remove finalizers for hash tables. --- src/alloc.c | 8 ++++++++ src/igc.c | 25 +++++-------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 8054deca197..f22e0e8dfb0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5794,7 +5794,11 @@ hash_table_alloc_bytes (ptrdiff_t nbytes) return NULL; tally_consing (nbytes); hash_table_allocated_bytes += nbytes; +#ifdef HAVE_MPS + void *p = igc_make_byte_vec (nbytes); +#else void *p = xmalloc (nbytes); +#endif return p; } @@ -5804,7 +5808,11 @@ hash_table_free_bytes (void *p, ptrdiff_t nbytes) { tally_consing (-nbytes); hash_table_allocated_bytes -= nbytes; +#ifdef HAVE_MPS + /* let igc handle this */ +#else xfree (p); +#endif } Lisp_Object * diff --git a/src/igc.c b/src/igc.c index acf8ddbbb4e..aad7e9d2779 100644 --- a/src/igc.c +++ b/src/igc.c @@ -1597,6 +1597,9 @@ fix_hash_table (mps_ss_t ss, struct Lisp_Hash_Table *h) // FIXME: weak IGC_FIX12_RAW (ss, &h->key); IGC_FIX12_RAW (ss, &h->value); + IGC_FIX12_RAW (ss, &h->hash); + IGC_FIX12_RAW (ss, &h->next); + IGC_FIX12_RAW (ss, &h->index); } MPS_SCAN_END (ss); return MPS_RES_OK; @@ -2475,21 +2478,6 @@ igc_create_charset_root (void *table, size_t size) root_create_ambig (global_igc, table, (char *) table + size); } -static void -finalize_hash_table (struct Lisp_Hash_Table *h) -{ - if (h->table_size) - { - /* Set the table size to 0 so that we don't further scan a hash - table after it has been finalized. Also, keep in mind that - xfree works with objects in a loaded dump. */ - h->table_size = 0; - xfree (h->index); - xfree (h->next); - xfree (h->hash); - } -} - static void finalize_bignum (struct Lisp_Bignum *n) { @@ -2605,10 +2593,6 @@ finalize_vector (mps_addr_t v) case PVEC_FREE: emacs_abort (); - case PVEC_HASH_TABLE: - finalize_hash_table (v); - break; - case PVEC_BIGNUM: finalize_bignum (v); break; @@ -2670,6 +2654,7 @@ finalize_vector (mps_addr_t v) #ifndef IN_MY_FORK case PVEC_OBARRAY: #endif + case PVEC_HASH_TABLE: case PVEC_SYMBOL_WITH_POS: case PVEC_PROCESS: case PVEC_RECORD: @@ -2746,7 +2731,6 @@ maybe_finalize (mps_addr_t client, enum pvec_type tag) mps_addr_t ref = client_to_base (client); switch (tag) { - case PVEC_HASH_TABLE: case PVEC_BIGNUM: case PVEC_FONT: case PVEC_THREAD: @@ -2765,6 +2749,7 @@ maybe_finalize (mps_addr_t client, enum pvec_type tag) #ifndef IN_MY_FORK case PVEC_OBARRAY: #endif + case PVEC_HASH_TABLE: case PVEC_NORMAL_VECTOR: case PVEC_FREE: case PVEC_MARKER: -- 2.39.2