[1/2] gdb, python: do minor modernization in execute_gdb_command
Commit Message
Use nullptr instead of NULL and boolify two local variables in
execute_gdb_command.
---
gdb/python/python.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
Comments
>>>>> "Tankut" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
Tankut> Use nullptr instead of NULL and boolify two local variables in
Tankut> execute_gdb_command.
Seems fine.
Approved-By: Tom Tromey <tom@tromey.com>
Tankut> + from_tty = ((cmp == 0) ? false : true);
I'd probably write '= cmp != 0' but this is alright.
Tom
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Tankut" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tankut> Use nullptr instead of NULL and boolify two local variables in
> Tankut> execute_gdb_command.
>
> Seems fine.
> Approved-By: Tom Tromey <tom@tromey.com>
>
> Tankut> + from_tty = ((cmp == 0) ? false : true);
>
> I'd probably write '= cmp != 0' but this is alright.
+1 from me. Please don't use: 'COND ? false : true'.
Thanks,
Andrew
On Saturday, February 25, 2023 12:08 PM, Andrew Burgess wrote:
> Tom Tromey <tom@tromey.com> writes:
>
> >>>>>> "Tankut" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
> >
> > Tankut> Use nullptr instead of NULL and boolify two local variables in
> > Tankut> execute_gdb_command.
> >
> > Seems fine.
> > Approved-By: Tom Tromey <tom@tromey.com>
> >
> > Tankut> + from_tty = ((cmp == 0) ? false : true);
> >
> > I'd probably write '= cmp != 0' but this is alright.
>
> +1 from me. Please don't use: 'COND ? false : true'.
I made this change (in two places) and pushed the patch.
Thank you.
-Baris
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
@@ -621,31 +621,32 @@ static PyObject *
execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
{
const char *arg;
- PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
- int from_tty, to_string;
- static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
+ PyObject *from_tty_obj = nullptr;
+ PyObject *to_string_obj = nullptr;
+ static const char *keywords[] = { "command", "from_tty", "to_string",
+ nullptr };
if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
&PyBool_Type, &from_tty_obj,
&PyBool_Type, &to_string_obj))
- return NULL;
+ return nullptr;
- from_tty = 0;
- if (from_tty_obj)
+ bool from_tty = false;
+ if (from_tty_obj != nullptr)
{
int cmp = PyObject_IsTrue (from_tty_obj);
if (cmp < 0)
- return NULL;
- from_tty = cmp;
+ return nullptr;
+ from_tty = ((cmp == 0) ? false : true);
}
- to_string = 0;
- if (to_string_obj)
+ bool to_string = false;
+ if (to_string_obj != nullptr)
{
int cmp = PyObject_IsTrue (to_string_obj);
if (cmp < 0)
- return NULL;
- to_string = cmp;
+ return nullptr;
+ to_string = ((cmp == 0) ? false : true);
}
std::string to_string_res;