From patchwork Sat Feb 7 14:45:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 4956 Received: (qmail 24967 invoked by alias); 7 Feb 2015 14:45:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24943 invoked by uid 89); 7 Feb 2015 14:45:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 07 Feb 2015 14:45:28 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t17EjRCn010996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sat, 7 Feb 2015 09:45:27 -0500 Received: from host1.jankratochvil.net (ovpn-116-113.ams2.redhat.com [10.36.116.113]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t17EjOCY005612; Sat, 7 Feb 2015 09:45:26 -0500 Subject: [PATCH 3/6] framefilter quit: Code cleanup: Avoid gotos From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Phil Muldoon Date: Sat, 07 Feb 2015 15:45:24 +0100 Message-ID: <20150207144523.14897.52407.stgit@host1.jankratochvil.net> In-Reply-To: <20150207144501.14897.90709.stgit@host1.jankratochvil.net> References: <20150207144501.14897.90709.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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 * 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