[1/2] gdb, python: do minor modernization in execute_gdb_command

Message ID 20230224140410.2647437-1-tankut.baris.aktemur@intel.com
State New
Headers
Series [1/2] gdb, python: do minor modernization in execute_gdb_command |

Commit Message

Tankut Baris Aktemur Feb. 24, 2023, 2:04 p.m. UTC
  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

Tom Tromey Feb. 24, 2023, 7:37 p.m. UTC | #1
>>>>> "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
  
Andrew Burgess Feb. 25, 2023, 11:08 a.m. UTC | #2
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
  
Terekhov, Mikhail via Gdb-patches Feb. 27, 2023, 9:34 a.m. UTC | #3
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
  

Patch

diff --git a/gdb/python/python.c b/gdb/python/python.c
index ed466cc4511..5719f351528 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -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;