This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 12/12] Use cleanup_function in regcache.c
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Tue, 8 Jan 2019 20:34:26 -0700
- Subject: [PATCH 12/12] Use cleanup_function in regcache.c
- References: <20190109033426.16062-1-tom@tromey.com>
This removes the regcache_invalidator class in favor of a
cleanup_function. This seems like an improvement (albeit a minor one)
because regcache_invalidator is only used in a single spot.
gdb/ChangeLog
2019-01-08 Tom Tromey <tom@tromey.com>
* regcache.c (class regcache_invalidator): Remove.
(regcache::raw_write): Use cleanup_function.
---
gdb/ChangeLog | 5 +++++
gdb/regcache.c | 41 ++++++++---------------------------------
2 files changed, 13 insertions(+), 33 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index c51ef771be..47339a0bce 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -28,6 +28,7 @@
#include "reggroups.h"
#include "observable.h"
#include "regset.h"
+#include "common/cleanup-function.h"
#include <forward_list>
/*
@@ -219,37 +220,6 @@ reg_buffer::arch () const
return m_descr->gdbarch;
}
-/* Cleanup class for invalidating a register. */
-
-class regcache_invalidator
-{
-public:
-
- regcache_invalidator (struct regcache *regcache, int regnum)
- : m_regcache (regcache),
- m_regnum (regnum)
- {
- }
-
- ~regcache_invalidator ()
- {
- if (m_regcache != nullptr)
- m_regcache->invalidate (m_regnum);
- }
-
- DISABLE_COPY_AND_ASSIGN (regcache_invalidator);
-
- void release ()
- {
- m_regcache = nullptr;
- }
-
-private:
-
- struct regcache *m_regcache;
- int m_regnum;
-};
-
/* Return a pointer to register REGNUM's buffer cache. */
gdb_byte *
@@ -769,13 +739,18 @@ regcache::raw_write (int regnum, const gdb_byte *buf)
/* Invalidate the register after it is written, in case of a
failure. */
- regcache_invalidator invalidator (this, regnum);
+ auto do_invalidate
+ = [=] ()
+ {
+ this->invalidate (regnum);
+ };
+ cleanup_function invalidator (do_invalidate);
target_store_registers (this, regnum);
/* The target did not throw an error so we can discard invalidating
the register. */
- invalidator.release ();
+ invalidator.cancel ();
}
void
--
2.17.2