Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 6/6] Remove some unneeded checks in Guile code
Date: Mon, 30 May 2022 11:59:34 -0600	[thread overview]
Message-ID: <20220530175934.3872892-7-tom@tromey.com> (raw)
In-Reply-To: <20220530175934.3872892-1-tom@tromey.com>

The Guile code generally checks to see if an htab is non-null before
destroying it.  However, the registry code already ensures this, so we
can change these checks to asserts and simplify the code a little.
---
 gdb/guile/scm-block.c  | 8 +++-----
 gdb/guile/scm-frame.c  | 8 +++-----
 gdb/guile/scm-symbol.c | 8 +++-----
 gdb/guile/scm-symtab.c | 8 +++-----
 gdb/guile/scm-type.c   | 9 +++------
 5 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index a29c2db58f1..07c6a2bd5e5 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -97,11 +97,9 @@ struct bkscm_deleter
 
   void operator() (htab_t htab)
   {
-    if (htab != NULL)
-      {
-	htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
-	htab_delete (htab);
-      }
+    gdb_assert (htab != nullptr);
+    htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
+    htab_delete (htab);
   }
 };
 
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 4132bb246d8..159603b8008 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -95,11 +95,9 @@ struct frscm_deleter
 
   void operator() (htab_t htab)
   {
-    if (htab != NULL)
-      {
-	htab_traverse_noresize (htab, frscm_mark_frame_invalid, NULL);
-	htab_delete (htab);
-      }
+    gdb_assert (htab != nullptr);
+    htab_traverse_noresize (htab, frscm_mark_frame_invalid, NULL);
+    htab_delete (htab);
   }
 };
 
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index 0b96e5a02c1..78917bdbed0 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -70,11 +70,9 @@ struct syscm_deleter
 
   void operator() (htab_t htab)
   {
-    if (htab != NULL)
-      {
-	htab_traverse_noresize (htab, syscm_mark_symbol_invalid, NULL);
-	htab_delete (htab);
-      }
+    gdb_assert (htab != nullptr);
+    htab_traverse_noresize (htab, syscm_mark_symbol_invalid, NULL);
+    htab_delete (htab);
   }
 };
 
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index 940823147bf..2ff66c49d51 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -98,11 +98,9 @@ struct stscm_deleter
 
   void operator() (htab_t htab)
   {
-    if (htab != NULL)
-      {
-	htab_traverse_noresize (htab, stscm_mark_symtab_invalid, NULL);
-	htab_delete (htab);
-      }
+    gdb_assert (htab != nullptr);
+    htab_traverse_noresize (htab, stscm_mark_symtab_invalid, NULL);
+    htab_delete (htab);
   }
 };
 
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 2dadbefb3a4..5cb1cabe14d 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -93,13 +93,10 @@ struct tyscm_deleter
     if (!gdb_scheme_initialized)
       return;
 
+    gdb_assert (htab != nullptr);
     htab_up copied_types = create_copied_types_hash ();
-
-    if (htab != NULL)
-      {
-	htab_traverse_noresize (htab, tyscm_copy_type_recursive, copied_types.get ());
-	htab_delete (htab);
-      }
+    htab_traverse_noresize (htab, tyscm_copy_type_recursive, copied_types.get ());
+    htab_delete (htab);
   }
 };
 
-- 
2.34.1


  parent reply	other threads:[~2022-05-30 18:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 17:59 [PATCH 0/6] Rewrite registry.h Tom Tromey
2022-05-30 17:59 ` [PATCH 1/6] Change address_space to use new and delete Tom Tromey
2022-05-30 17:59 ` [PATCH 2/6] Change allocation of type-copying hash table Tom Tromey
2022-05-30 17:59 ` [PATCH 3/6] Remove some unused functions from guile code Tom Tromey
2022-05-30 17:59 ` [PATCH 4/6] Rewrite registry.h Tom Tromey
2022-06-07 10:55   ` Lancelot SIX via Gdb-patches
2022-06-08  1:33     ` Tom Tromey
2022-06-08 18:51       ` Tom Tromey
2022-05-30 17:59 ` [PATCH 5/6] Change registry to use less memory Tom Tromey
2022-05-30 17:59 ` Tom Tromey [this message]
2022-07-28 20:13 ` [PATCH 0/6] Rewrite registry.h Tom Tromey
2022-07-29  2:33   ` Simon Marchi via Gdb-patches
2022-08-02  2:46     ` Tom Tromey

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530175934.3872892-7-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox