Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Phil Muldoon <pmuldoon@redhat.com>
Subject: [PATCH 3/6] framefilter quit: Code cleanup: Avoid gotos
Date: Sat, 07 Feb 2015 14:45:00 -0000	[thread overview]
Message-ID: <20150207144523.14897.52407.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150207144501.14897.90709.stgit@host1.jankratochvil.net>

Hi,

goto error patters are sometimes AFAIK used in C for the cases like:
	int retval=-1;
	if (!(a=malloc())) goto error;
	if (!(b=malloc())) goto error_a;
	if (!(c=malloc())) goto error_b;
	retval=0;
	error_c: free(c);
	error_b: free(b);
	error_a: free(a);
	error: return retval;

But here there is single error label with one do_cleanups() which I do not find
it worth the goto complication.  Without goto one can then furher merge code in
the exit paths in the next patches and ... after all it is all the same, just
without a goto.


Jan


gdb/ChangeLog
2015-02-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* python/py-framefilter.c (py_print_frame): Substitute goto error.
	Remove the error label.
---
 gdb/python/py-framefilter.c |  103 +++++++++++++++++++++++++++++++------------
 1 file changed, 74 insertions(+), 29 deletions(-)

diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 896e2a8..ba1b237 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1033,14 +1033,20 @@ py_print_frame (PyObject *filter, int flags,
   read them if they returned filter object requires us to do so.  */
   py_inf_frame = PyObject_CallMethod (filter, "inferior_frame", NULL);
   if (py_inf_frame == NULL)
-    goto error;
+    {
+      do_cleanups (cleanup_stack);
+      return EXT_LANG_BT_ERROR;
+    }
 
   frame = frame_object_to_frame_info (py_inf_frame);;
 
   Py_DECREF (py_inf_frame);
 
   if (frame == NULL)
-    goto error;
+    {
+      do_cleanups (cleanup_stack);
+      return EXT_LANG_BT_ERROR;
+    }
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
@@ -1049,7 +1055,8 @@ py_print_frame (PyObject *filter, int flags,
   if (except.reason < 0)
     {
       gdbpy_convert_exception (except);
-      goto error;
+      do_cleanups (cleanup_stack);
+      return EXT_LANG_BT_ERROR;
     }
 
   /* stack-list-variables.  */
@@ -1057,7 +1064,10 @@ py_print_frame (PyObject *filter, int flags,
     {
       if (py_mi_print_variables (filter, out, &opts,
 				 args_type, frame) == EXT_LANG_BT_ERROR)
-	goto error;
+	{
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
+	}
       do_cleanups (cleanup_stack);
       return EXT_LANG_BT_COMPLETED;
     }
@@ -1080,7 +1090,8 @@ py_print_frame (PyObject *filter, int flags,
 	  if (except.reason < 0)
 	    {
 	      gdbpy_convert_exception (except);
-	      goto error;
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
 	    }
 	}
 
@@ -1091,7 +1102,10 @@ py_print_frame (PyObject *filter, int flags,
 	  PyObject *paddr = PyObject_CallMethod (filter, "address", NULL);
 
 	  if (paddr == NULL)
-	    goto error;
+	    {
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
+	    }
 
 	  if (paddr != Py_None)
 	    {
@@ -1135,7 +1149,8 @@ py_print_frame (PyObject *filter, int flags,
       if (except.reason < 0)
 	{
 	  gdbpy_convert_exception (except);
-	  goto error;
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
 	}
     }
 
@@ -1155,7 +1170,8 @@ py_print_frame (PyObject *filter, int flags,
 	  if (except.reason < 0)
 	    {
 	      gdbpy_convert_exception (except);
-	      goto error;
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
 	    }
 	}
 
@@ -1166,7 +1182,10 @@ py_print_frame (PyObject *filter, int flags,
 	  const char *function = NULL;
 
 	  if (py_func == NULL)
-	    goto error;
+	    {
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
+	    }
 
 	  if (gdbpy_is_string (py_func))
 	    {
@@ -1178,7 +1197,8 @@ py_print_frame (PyObject *filter, int flags,
 	      if (function == NULL)
 		{
 		  Py_DECREF (py_func);
-		  goto error;
+		  do_cleanups (cleanup_stack);
+		  return EXT_LANG_BT_ERROR;
 		}
 	      make_cleanup (xfree, function_to_free);
 	    }
@@ -1188,7 +1208,10 @@ py_print_frame (PyObject *filter, int flags,
 	      struct bound_minimal_symbol msymbol;
 
 	      if (PyErr_Occurred ())
-		goto error;
+		{
+		  do_cleanups (cleanup_stack);
+		  return EXT_LANG_BT_ERROR;
+		}
 
 	      msymbol = lookup_minimal_symbol_by_pc (addr);
 	      if (msymbol.minsym != NULL)
@@ -1200,7 +1223,8 @@ py_print_frame (PyObject *filter, int flags,
 			       _("FrameDecorator.function: expecting a " \
 				 "String, integer or None."));
 	      Py_DECREF (py_func);
-	      goto error;
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
 	    }
 
 	  TRY_CATCH (except, RETURN_MASK_ALL)
@@ -1215,7 +1239,8 @@ py_print_frame (PyObject *filter, int flags,
 	    {
 	      Py_DECREF (py_func);
 	      gdbpy_convert_exception (except);
-	      goto error;
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
 	    }
 	  Py_DECREF (py_func);
 	}
@@ -1227,7 +1252,10 @@ py_print_frame (PyObject *filter, int flags,
   if (print_args)
     {
       if (py_print_args (filter, out, args_type, frame) == EXT_LANG_BT_ERROR)
-	goto error;
+	{
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
+	}
     }
 
   /* File name/source/line number information.  */
@@ -1240,7 +1268,8 @@ py_print_frame (PyObject *filter, int flags,
       if (except.reason < 0)
 	{
 	  gdbpy_convert_exception (except);
-	  goto error;
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
 	}
 
       if (PyObject_HasAttrString (filter, "filename"))
@@ -1248,7 +1277,10 @@ py_print_frame (PyObject *filter, int flags,
 	  PyObject *py_fn = PyObject_CallMethod (filter, "filename", NULL);
 
 	  if (py_fn == NULL)
-	    goto error;
+	    {
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
+	    }
 
 	  if (py_fn != Py_None)
 	    {
@@ -1257,7 +1289,8 @@ py_print_frame (PyObject *filter, int flags,
 	      if (filename == NULL)
 		{
 		  Py_DECREF (py_fn);
-		  goto error;
+		  do_cleanups (cleanup_stack);
+		  return EXT_LANG_BT_ERROR;
 		}
 
 	      make_cleanup (xfree, filename);
@@ -1273,7 +1306,8 @@ py_print_frame (PyObject *filter, int flags,
 		{
 		  Py_DECREF (py_fn);
 		  gdbpy_convert_exception (except);
-		  goto error;
+		  do_cleanups (cleanup_stack);
+		  return EXT_LANG_BT_ERROR;
 		}
 	    }
 	  Py_DECREF (py_fn);
@@ -1285,7 +1319,10 @@ py_print_frame (PyObject *filter, int flags,
 	  int line;
 
 	  if (py_line == NULL)
-	    goto error;
+	    {
+	      do_cleanups (cleanup_stack);
+	      return EXT_LANG_BT_ERROR;
+	    }
 
 	  if (py_line != Py_None)
 	    {
@@ -1300,7 +1337,8 @@ py_print_frame (PyObject *filter, int flags,
 		{
 		  Py_DECREF (py_line);
 		  gdbpy_convert_exception (except);
-		  goto error;
+		  do_cleanups (cleanup_stack);
+		  return EXT_LANG_BT_ERROR;
 		}
 	    }
 	  Py_DECREF (py_line);
@@ -1319,7 +1357,8 @@ py_print_frame (PyObject *filter, int flags,
       if (except.reason < 0)
 	{
 	  gdbpy_convert_exception (except);
-	  goto error;
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
 	}
     }
 
@@ -1327,7 +1366,10 @@ py_print_frame (PyObject *filter, int flags,
     {
       if (py_print_locals (filter, out, args_type, indent,
 			   frame) == EXT_LANG_BT_ERROR)
-	goto error;
+	{
+	  do_cleanups (cleanup_stack);
+	  return EXT_LANG_BT_ERROR;
+	}
     }
 
   {
@@ -1336,7 +1378,10 @@ py_print_frame (PyObject *filter, int flags,
     /* Finally recursively print elided frames, if any.  */
     elided = get_py_iter_from_func (filter, "elided");
     if (elided == NULL)
-      goto error;
+      {
+	do_cleanups (cleanup_stack);
+	return EXT_LANG_BT_ERROR;
+      }
 
     make_cleanup_py_decref (elided);
     if (elided != Py_None)
@@ -1358,23 +1403,23 @@ py_print_frame (PyObject *filter, int flags,
 	    if (success == EXT_LANG_BT_ERROR)
 	      {
 		Py_DECREF (item);
-		goto error;
+		do_cleanups (cleanup_stack);
+		return EXT_LANG_BT_ERROR;
 	      }
 
 	    Py_DECREF (item);
 	  }
 	if (item == NULL && PyErr_Occurred ())
-	  goto error;
+	  {
+	    do_cleanups (cleanup_stack);
+	    return EXT_LANG_BT_ERROR;
+	  }
       }
     }
 
 
   do_cleanups (cleanup_stack);
   return EXT_LANG_BT_COMPLETED;
-
- error:
-  do_cleanups (cleanup_stack);
-  return EXT_LANG_BT_ERROR;
 }
 
 /* Helper function to initiate frame filter invocation at starting


  parent reply	other threads:[~2015-02-07 14:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-07 14:45 [PATCH 0/6] framefilter quit: PR cli/17716 Jan Kratochvil
2015-02-07 14:45 ` [PATCH 5/6] framefilter quit: Use RETURN_MASK_ERROR Jan Kratochvil
2015-02-11 13:52   ` [commit+7.9] " Jan Kratochvil
2015-02-07 14:45 ` [PATCH 2/6] framefilter quit: Code cleanup: Reindentation Jan Kratochvil
2015-02-11 13:39   ` [commit+7.9] " Jan Kratochvil
2015-02-07 14:45 ` [PATCH 6/6] framefilter quit: New test Jan Kratochvil
2015-02-11 13:56   ` [commit+7.9] " Jan Kratochvil
2015-02-07 14:45 ` [PATCH 1/6] framefilter quit: Obvious whitespacing fixes Jan Kratochvil
2015-02-11 13:37   ` [commit+7.9] " Jan Kratochvil
2015-02-07 14:45 ` [PATCH 4/6] framefilter quit: Make it exception safe Jan Kratochvil
2015-02-11 13:45   ` [commit+7.9] " Jan Kratochvil
2015-02-07 14:45 ` Jan Kratochvil [this message]
2015-02-11 13:43   ` [commit+7.9] [PATCH 3/6] framefilter quit: Code cleanup: Avoid gotos Jan Kratochvil
2015-02-10 17:40 ` [PATCH 0/6] framefilter quit: PR cli/17716 Pedro Alves
2015-02-10 19:19   ` Phil Muldoon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150207144523.14897.52407.stgit@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox