Use gdbpy_ref in invoke_match_method

Change invoke_match_method to use gdbpy_ref.
I neglected to convert this function in my earlier series.

2017-01-10  Tom Tromey  <tom@tromey.com>

	* python/py-xmethods.c (invoke_match_method): Use
	gdbpy_ref.
This commit is contained in:
Tom Tromey
2016-11-08 15:35:24 -07:00
parent 572a5524c1
commit bf1ca3b947
2 changed files with 17 additions and 38 deletions

@ -1,3 +1,8 @@
2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-xmethods.c (invoke_match_method): Use
gdbpy_ref.
2017-01-10 Tom Tromey <tom@tromey.com> 2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): use * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): use

@ -94,59 +94,33 @@ static PyObject *
invoke_match_method (PyObject *matcher, PyObject *py_obj_type, invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
const char *xmethod_name) const char *xmethod_name)
{ {
PyObject *py_xmethod_name;
PyObject *match_method, *enabled_field, *match_result;
struct cleanup *cleanups;
int enabled; int enabled;
cleanups = make_cleanup (null_cleanup, NULL); gdbpy_ref enabled_field (PyObject_GetAttrString (matcher,
enabled_field_name));
enabled_field = PyObject_GetAttrString (matcher, enabled_field_name);
if (enabled_field == NULL) if (enabled_field == NULL)
{ return NULL;
do_cleanups (cleanups);
return NULL;
}
make_cleanup_py_decref (enabled_field);
enabled = PyObject_IsTrue (enabled_field); enabled = PyObject_IsTrue (enabled_field.get ());
if (enabled == -1) if (enabled == -1)
{ return NULL;
do_cleanups (cleanups);
return NULL;
}
if (enabled == 0) if (enabled == 0)
{ {
/* Return 'None' if the matcher is not enabled. */ /* Return 'None' if the matcher is not enabled. */
do_cleanups (cleanups);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
match_method = PyObject_GetAttrString (matcher, match_method_name); gdbpy_ref match_method (PyObject_GetAttrString (matcher, match_method_name));
if (match_method == NULL) if (match_method == NULL)
{ return NULL;
do_cleanups (cleanups);
return NULL;
}
make_cleanup_py_decref (match_method);
py_xmethod_name = PyString_FromString (xmethod_name); gdbpy_ref py_xmethod_name (PyString_FromString (xmethod_name));
if (py_xmethod_name == NULL) if (py_xmethod_name == NULL)
{ return NULL;
do_cleanups (cleanups);
return NULL;
}
make_cleanup_py_decref (py_xmethod_name);
match_result = PyObject_CallMethodObjArgs (matcher, return PyObject_CallMethodObjArgs (matcher, py_match_method_name,
py_match_method_name, py_obj_type, py_xmethod_name.get (),
py_obj_type, NULL);
py_xmethod_name,
NULL);
do_cleanups (cleanups);
return match_result;
} }
/* Implementation of get_matching_xmethod_workers for Python. */ /* Implementation of get_matching_xmethod_workers for Python. */