Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [committed][gdb/symtab] Use lambda function instead of addrmap_foreach_check
Date: Wed, 4 Aug 2021 14:30:07 +0200	[thread overview]
Message-ID: <20210804123006.GA32185@delia> (raw)

Hi,

Use a lambda function instead of addrmap_foreach_check,
which removes the need for static variables.

Also remove unnecessary static on local var temp_obstack in test_addrmap.

Committed to trunk.

Thanks,
- Tom

[gdb/symtab] Use lambda function instead of addrmap_foreach_check

gdb/ChangeLog:

2021-08-04  Tom de Vries  <tdevries@suse.de>

	* addrmap.c (addrmap_foreach_check): Remove.
	(array, val1, val2): Move ...
	(test_addrmap): ... here.  Remove static on temp_obstack.  Use lambda
	function instead of addrmap_foreach_check.

---
 gdb/addrmap.c | 51 +++++++++++++++++++++------------------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 2cb472604f4..22817824cdc 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -611,41 +611,20 @@ core_addr (void *p)
     }									\
   while (0)
 
-/* We'll verify using the addresses of the elements of this array.  */
-static char *array;
-/* We'll verify using these values stored into the map.  */
-static void *val1;
-static void *val2;
-
-/* Callback for addrmap_foreach to check transitions.  */
-
-static int
-addrmap_foreach_check (CORE_ADDR start_addr, void *obj)
-{
-  if (start_addr == core_addr (nullptr))
-    SELF_CHECK (obj == nullptr);
-  else if (start_addr == core_addr (&array[10]))
-    SELF_CHECK (obj == val1);
-  else if (start_addr == core_addr (&array[13]))
-    SELF_CHECK (obj == nullptr);
-  else
-    SELF_CHECK (false);
-  return 0;
-}
-
 /* Entry point for addrmap unit tests.  */
 
 static void
 test_addrmap ()
 {
-  /* Initialize static variables.  */
-  char local_array[20];
-  array = local_array;
-  val1 = &array[1];
-  val2 = &array[2];
+  /* We'll verify using the addresses of the elements of this array.  */
+  char array[20];
+
+  /* We'll verify using these values stored into the map.  */
+  void *val1 = &array[1];
+  void *val2 = &array[2];
 
   /* Create mutable addrmap.  */
-  static struct obstack temp_obstack;
+  struct obstack temp_obstack;
   obstack_init (&temp_obstack);
   struct addrmap *map = addrmap_create_mutable (&temp_obstack);
   SELF_CHECK (map != nullptr);
@@ -668,8 +647,20 @@ test_addrmap ()
   CHECK_ADDRMAP_FIND (map2, array, 13, 19, nullptr);
 
   /* Iterate over both addrmaps.  */
-  SELF_CHECK (addrmap_foreach (map, addrmap_foreach_check) == 0);
-  SELF_CHECK (addrmap_foreach (map2, addrmap_foreach_check) == 0);
+  auto callback = [&] (CORE_ADDR start_addr, void *obj)
+    {
+      if (start_addr == core_addr (nullptr))
+	SELF_CHECK (obj == nullptr);
+      else if (start_addr == core_addr (&array[10]))
+	SELF_CHECK (obj == val1);
+      else if (start_addr == core_addr (&array[13]))
+	SELF_CHECK (obj == nullptr);
+      else
+	SELF_CHECK (false);
+      return 0;
+    };
+  SELF_CHECK (addrmap_foreach (map, callback) == 0);
+  SELF_CHECK (addrmap_foreach (map2, callback) == 0);
 
   /* Relocate fixed addrmap.  */
   addrmap_relocate (map2, 1);

                 reply	other threads:[~2021-08-04 12:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210804123006.GA32185@delia \
    --to=tdevries@suse.de \
    --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