From a67a1c41fe4ab9bd8b1dcb7d5f68e080a0e96dfe Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Wed, 22 Jul 2020 14:57:55 +0100 Subject: [PATCH] gdb/python: Use reference not pointer in py-registers.c Pedro's review comments arrived after I'd already committed this change: commit f7306dac19c502232f766c3881313857915f330d Date: Tue Jul 7 15:00:30 2020 +0100 gdb/python: Reuse gdb.RegisterDescriptor objects where possible See: https://sourceware.org/pipermail/gdb-patches/2020-July/170726.html There should be no user visible changes after this commit. gdb/ChangeLog: * python/py-registers.c (gdbpy_register_object_data_init): Remove redundant local variable. (gdbpy_get_register_descriptor): Extract descriptor vector as a reference, not pointer, update code accordingly. --- gdb/ChangeLog | 7 +++++++ gdb/python/py-registers.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a768df0d76c..1cef37dea6c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-07-22 Andrew Burgess + + * python/py-registers.c (gdbpy_register_object_data_init): Remove + redundant local variable. + (gdbpy_get_register_descriptor): Extract descriptor vector as a + reference, not pointer, update code accordingly. + 2020-07-22 Simon Marchi Tankut Baris Aktemur diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c index 9396498cc34..f64ca3c401b 100644 --- a/gdb/python/py-registers.c +++ b/gdb/python/py-registers.c @@ -92,8 +92,7 @@ extern PyTypeObject reggroup_object_type static void * gdbpy_register_object_data_init (struct gdbarch *gdbarch) { - std::vector> *vec = new (std::vector>); - return (void *) vec; + return new std::vector>; } /* Return a gdb.RegisterGroup object wrapping REGGROUP. The register @@ -158,16 +157,17 @@ static gdbpy_ref<> gdbpy_get_register_descriptor (struct gdbarch *gdbarch, int regnum) { - auto vec = (std::vector> *) gdbarch_data - (gdbarch, gdbpy_register_object_data); + auto &vec + = *(std::vector> *) gdbarch_data (gdbarch, + gdbpy_register_object_data); /* Ensure that we have enough entries in the vector. */ - if (vec->size () <= regnum) - vec->resize ((regnum + 1), nullptr); + if (vec.size () <= regnum) + vec.resize ((regnum + 1), nullptr); /* If we don't already have a descriptor for REGNUM in GDBARCH then create one now. */ - if (vec->at (regnum) == nullptr) + if (vec[regnum] == nullptr) { gdbpy_ref reg (PyObject_New (register_descriptor_object, @@ -176,12 +176,12 @@ gdbpy_get_register_descriptor (struct gdbarch *gdbarch, return NULL; reg->regnum = regnum; reg->gdbarch = gdbarch; - vec->at (regnum) = gdbpy_ref<> ((PyObject *) reg.release ()); + vec[regnum] = gdbpy_ref<> ((PyObject *) reg.release ()); } /* Grab the register descriptor from the vector, the reference count is automatically incremented thanks to gdbpy_ref. */ - return vec->at (regnum); + return vec[regnum]; } /* Convert the register descriptor to a string. */ -- 2.30.2