This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v3 17/17] Use scope_exit in regcache.c
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>, Andrew Burgess <andrew dot burgess at embecosm dot com>
- Date: Wed, 23 Jan 2019 15:21:31 +0000
- Subject: [PATCH v3 17/17] Use scope_exit in regcache.c
- References: <20190123152131.29893-1-palves@redhat.com>
From: Tom Tromey <tom@tromey.com>
This removes the regcache_invalidator class in favor of a scope_exit.
This seems like an improvement (albeit a minor one) because
regcache_invalidator is only used in a single spot.
gdb/ChangeLog
2019-01-22 Tom Tromey <tom@tromey.com>
Pedro Alves <palves@redhat.com>
* regcache.c (class regcache_invalidator): Remove.
(regcache::raw_write): Use make_scope_exit.
---
gdb/regcache.c | 34 ++--------------------------------
1 file changed, 2 insertions(+), 32 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 4a68390c5f..a354e15d2d 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -219,37 +219,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,7 +738,8 @@ 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 invalidator
+ = make_scope_exit ([&] { this->invalidate (regnum); });
target_store_registers (this, regnum);
--
2.14.4