From 88b6faea9953505e9e8a7a77995c7db5dfb6ac19 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 11 Jan 2017 16:28:43 -0700 Subject: Use gdbpy_ref to simplify some logic This uses the new gdbpy_ref template to simplify logic in various parts of the Python layer; for example removing repeated error code or removing gotos. gdb/ChangeLog 2017-02-10 Tom Tromey * python/py-cmd.c (cmdpy_destroyer): Use gdbpy_ref. * python/py-breakpoint.c (gdbpy_breakpoint_deleted): Use gdbpy_ref. * python/py-type.c (field_new): Use gdbpy_ref. * python/py-symtab.c (symtab_and_line_to_sal_object): Use gdbpy_ref. * python/py-progspace.c (pspy_new): Use gdbpy_ref. (py_free_pspace): Likewise. (pspace_to_pspace_object): Likewise. * python/py-objfile.c (objfpy_new): Use gdbpy_ref. (py_free_objfile): Likewise. (objfile_to_objfile_object): Likewise. * python/py-inferior.c (delete_thread_object): Use gdbpy_ref. (infpy_read_memory): Likewise. (py_free_inferior): Likewise. * python/py-evtregistry.c (create_eventregistry_object): Use gdbpy_ref. * python/py-event.c (create_event_object): Use gdbpy_ref. --- gdb/python/py-symtab.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'gdb/python/py-symtab.c') diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 9fdb42f..09cab22 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -24,6 +24,7 @@ #include "python-internal.h" #include "objfiles.h" #include "block.h" +#include "py-ref.h" typedef struct stpy_symtab_object { PyObject_HEAD @@ -436,19 +437,14 @@ symtab_to_symtab_object (struct symtab *symtab) PyObject * symtab_and_line_to_sal_object (struct symtab_and_line sal) { - sal_object *sal_obj; - - sal_obj = PyObject_New (sal_object, &sal_object_type); - if (sal_obj) + gdbpy_ref sal_obj (PyObject_New (sal_object, &sal_object_type)); + if (sal_obj != NULL) { - if (set_sal (sal_obj, sal) < 0) - { - Py_DECREF (sal_obj); - return NULL; - } + if (set_sal (sal_obj.get (), sal) < 0) + return NULL; } - return (PyObject *) sal_obj; + return (PyObject *) sal_obj.release (); } /* Return struct symtab_and_line reference that is wrapped by this -- cgit v1.1