+2019-01-03 Tom Tromey <tom@tromey.com>
+
+ * python/py-value.c (valpy_dealloc): Use Py_XDECREF.
+ * python/py-type.c (typy_fields_items): Use gdbpy_ref.
+ * python/py-progspace.c (pspy_set_printers): Use gdbpy_ref.
+ (pspy_set_frame_filters, pspy_set_frame_unwinders)
+ (pspy_set_type_printers): Likewise.
+ * python/py-function.c (fnpy_init): Use gdbpy_ref.
+ * python/py-cmd.c (cmdpy_init): Use gdbpy_ref.
+ * python/py-objfile.c (objfpy_set_printers): Use gdbpy_ref.
+ (objfpy_set_frame_filters, objfpy_set_frame_unwinders)
+ (objfpy_set_type_printers): Likewise.
+
2019-01-03 Tom Tromey <tom@tromey.com>
* python/python.c (gdbpy_enter, ~gdbpy_enter): Update.
if (! docstring)
docstring = xstrdup (_("This command is not documented."));
- Py_INCREF (self);
+ gdbpy_ref<> self_ref = gdbpy_ref<>::new_reference (self);
TRY
{
cmd->destroyer = cmdpy_destroyer;
obj->command = cmd;
- set_cmd_context (cmd, self);
+ set_cmd_context (cmd, self_ref.release ());
set_cmd_completer (cmd, ((completetype == -1) ? cmdpy_completer
: completers[completetype].completer));
if (completetype == -1)
xfree (cmd_name);
xfree (docstring);
xfree (pfx_name);
- Py_DECREF (self);
gdbpy_convert_exception (except);
return -1;
}
if (! PyArg_ParseTuple (args, "s", &name))
return -1;
- Py_INCREF (self);
+
+ gdbpy_ref<> self_ref = gdbpy_ref<>::new_reference (self);
if (PyObject_HasAttrString (self, "__doc__"))
{
{
docstring = python_string_to_host_string (ds_obj.get ());
if (docstring == NULL)
- {
- Py_DECREF (self);
- return -1;
- }
+ return -1;
}
}
}
if (! docstring)
docstring.reset (xstrdup (_("This function is not documented.")));
- add_internal_function (name, docstring.release (), fnpy_call, self);
+ add_internal_function (name, docstring.release (), fnpy_call,
+ self_ref.release ());
return 0;
}
static int
objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
{
- PyObject *tmp;
objfile_object *self = (objfile_object *) o;
if (! value)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->printers;
+ gdbpy_ref<> tmp (self->printers);
Py_INCREF (value);
self->printers = value;
- Py_XDECREF (tmp);
return 0;
}
static int
objfpy_set_frame_filters (PyObject *o, PyObject *filters, void *ignore)
{
- PyObject *tmp;
objfile_object *self = (objfile_object *) o;
if (! filters)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->frame_filters;
+ gdbpy_ref<> tmp (self->frame_filters);
Py_INCREF (filters);
self->frame_filters = filters;
- Py_XDECREF (tmp);
return 0;
}
static int
objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
{
- PyObject *tmp;
objfile_object *self = (objfile_object *) o;
if (!unwinders)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->frame_unwinders;
+ gdbpy_ref<> tmp (self->frame_unwinders);
Py_INCREF (unwinders);
self->frame_unwinders = unwinders;
- Py_XDECREF (tmp);
return 0;
}
static int
objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
{
- PyObject *tmp;
objfile_object *self = (objfile_object *) o;
if (! value)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->type_printers;
+ gdbpy_ref<> tmp (self->type_printers);
Py_INCREF (value);
self->type_printers = value;
- Py_XDECREF (tmp);
return 0;
}
static int
pspy_set_printers (PyObject *o, PyObject *value, void *ignore)
{
- PyObject *tmp;
pspace_object *self = (pspace_object *) o;
if (! value)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->printers;
+ gdbpy_ref<> tmp (self->printers);
Py_INCREF (value);
self->printers = value;
- Py_XDECREF (tmp);
return 0;
}
static int
pspy_set_frame_filters (PyObject *o, PyObject *frame, void *ignore)
{
- PyObject *tmp;
pspace_object *self = (pspace_object *) o;
if (! frame)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->frame_filters;
+ gdbpy_ref<> tmp (self->frame_filters);
Py_INCREF (frame);
self->frame_filters = frame;
- Py_XDECREF (tmp);
return 0;
}
static int
pspy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
{
- PyObject *tmp;
pspace_object *self = (pspace_object *) o;
if (!unwinders)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->frame_unwinders;
+ gdbpy_ref<> tmp (self->frame_unwinders);
Py_INCREF (unwinders);
self->frame_unwinders = unwinders;
- Py_XDECREF (tmp);
return 0;
}
static int
pspy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
{
- PyObject *tmp;
pspace_object *self = (pspace_object *) o;
if (! value)
}
/* Take care in case the LHS and RHS are related somehow. */
- tmp = self->type_printers;
+ gdbpy_ref<> tmp (self->type_printers);
Py_INCREF (value);
self->type_printers = value;
- Py_XDECREF (tmp);
return 0;
}
typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
{
PyObject *py_type = self;
- PyObject *result = NULL, *iter = NULL;
struct type *type = ((type_object *) py_type)->type;
struct type *checked_type = type;
}
END_CATCH
+ gdbpy_ref<> type_holder;
if (checked_type != type)
- py_type = type_to_type_object (checked_type);
- iter = typy_make_iter (py_type, kind);
- if (checked_type != type)
- {
- /* Need to wrap this in braces because Py_DECREF isn't wrapped
- in a do{}while(0). */
- Py_DECREF (py_type);
- }
- if (iter != NULL)
{
- result = PySequence_List (iter);
- Py_DECREF (iter);
+ type_holder.reset (type_to_type_object (checked_type));
+ if (type_holder == nullptr)
+ return nullptr;
+ py_type = type_holder.get ();
}
+ gdbpy_ref<> iter (typy_make_iter (py_type, kind));
+ if (iter == nullptr)
+ return nullptr;
- return result;
+ return PySequence_List (iter.get ());
}
/* Return a sequence of all fields. Each field is a gdb.Field object. */
value_decref (self->value);
- if (self->address)
- /* Use braces to appease gcc warning. *sigh* */
- {
- Py_DECREF (self->address);
- }
-
- if (self->type)
- {
- Py_DECREF (self->type);
- }
-
+ Py_XDECREF (self->address);
+ Py_XDECREF (self->type);
Py_XDECREF (self->dynamic_type);
Py_TYPE (self)->tp_free (self);