Turn gdbpy_ref into a template

This turns gdbpy_ref into a template class, so that it can be used to
wrap subclasses of PyObject.  The default argument remains PyObject;
and this necessitated renaming uses of "gdbpy_ref" to "gdbpy_ref<>".

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

	* python/py-ref.h (gdbpy_ref_policy): Now a template.
	(gdbpy_ref): Now a template; allow subclasses of PyObject to be
	used.
	* python/py-arch.c, python/py-bpevent.c, python/py-breakpoint.c,
	python/py-cmd.c, python/py-continueevent.c, python/py-event.c,
	python/py-exitedevent.c, python/py-finishbreakpoint.c,
	python/py-framefilter.c, python/py-function.c,
	python/py-inferior.c, python/py-infevents.c,
	python/py-linetable.c, python/py-newobjfileevent.c,
	python/py-param.c, python/py-prettyprint.c, python/py-ref.h,
	python/py-signalevent.c, python/py-stopevent.c,
	python/py-symbol.c, python/py-threadevent.c, python/py-type.c,
	python/py-unwind.c, python/py-utils.c, python/py-value.c,
	python/py-varobj.c, python/py-xmethods.c, python/python.c,
	varobj.c: Change gdbpy_ref to gdbpy_ref<>.
This commit is contained in:
Tom Tromey 2017-02-09 13:16:36 -07:00
parent d4b0bb186e
commit 7780f18678
30 changed files with 260 additions and 234 deletions

View file

@ -1,3 +1,21 @@
2017-02-10 Tom Tromey <tom@tromey.com>
* python/py-ref.h (gdbpy_ref_policy): Now a template.
(gdbpy_ref): Now a template; allow subclasses of PyObject to be
used.
* python/py-arch.c, python/py-bpevent.c, python/py-breakpoint.c,
python/py-cmd.c, python/py-continueevent.c, python/py-event.c,
python/py-exitedevent.c, python/py-finishbreakpoint.c,
python/py-framefilter.c, python/py-function.c,
python/py-inferior.c, python/py-infevents.c,
python/py-linetable.c, python/py-newobjfileevent.c,
python/py-param.c, python/py-prettyprint.c, python/py-ref.h,
python/py-signalevent.c, python/py-stopevent.c,
python/py-symbol.c, python/py-threadevent.c, python/py-type.c,
python/py-unwind.c, python/py-utils.c, python/py-value.c,
python/py-varobj.c, python/py-xmethods.c, python/python.c,
varobj.c: Change gdbpy_ref to gdbpy_ref<>.
2017-02-10 Tom Tromey <tom@tromey.com> 2017-02-10 Tom Tromey <tom@tromey.com>
* ui-out.h (ui_out_emit_type): New class. * ui-out.h (ui_out_emit_type): New class.

View file

@ -178,7 +178,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
} }
} }
gdbpy_ref result_list (PyList_New (0)); gdbpy_ref<> result_list (PyList_New (0));
if (result_list == NULL) if (result_list == NULL)
return NULL; return NULL;
@ -193,7 +193,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
|| (end_obj == NULL && count_obj == NULL && pc == start);) || (end_obj == NULL && count_obj == NULL && pc == start);)
{ {
int insn_len = 0; int insn_len = 0;
gdbpy_ref insn_dict (PyDict_New ()); gdbpy_ref<> insn_dict (PyDict_New ());
if (insn_dict == NULL) if (insn_dict == NULL)
return NULL; return NULL;

View file

@ -30,7 +30,7 @@ extern PyTypeObject breakpoint_event_object_type
PyObject * PyObject *
create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp) create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
{ {
gdbpy_ref breakpoint_event_obj gdbpy_ref<> breakpoint_event_obj
(create_stop_event_object (&breakpoint_event_object_type)); (create_stop_event_object (&breakpoint_event_object_type));
if (breakpoint_event_obj == NULL) if (breakpoint_event_obj == NULL)

View file

@ -758,7 +758,7 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
if (bppy_live == 0) if (bppy_live == 0)
return PyTuple_New (0); return PyTuple_New (0);
gdbpy_ref list (PyList_New (0)); gdbpy_ref<> list (PyList_New (0));
if (list == NULL) if (list == NULL)
return NULL; return NULL;
@ -798,7 +798,7 @@ gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
if (PyObject_HasAttrString (py_bp, stop_func)) if (PyObject_HasAttrString (py_bp, stop_func))
{ {
gdbpy_ref result (PyObject_CallMethod (py_bp, stop_func, NULL)); gdbpy_ref<> result (PyObject_CallMethod (py_bp, stop_func, NULL));
stop = 1; stop = 1;
if (result != NULL) if (result != NULL)

View file

@ -134,7 +134,7 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
if (! args) if (! args)
args = ""; args = "";
gdbpy_ref argobj (PyUnicode_Decode (args, strlen (args), host_charset (), gdbpy_ref<> argobj (PyUnicode_Decode (args, strlen (args), host_charset (),
NULL)); NULL));
if (argobj == NULL) if (argobj == NULL)
{ {
@ -142,9 +142,9 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
error (_("Could not convert arguments to Python string.")); error (_("Could not convert arguments to Python string."));
} }
gdbpy_ref ttyobj (from_tty ? Py_True : Py_False); gdbpy_ref<> ttyobj (from_tty ? Py_True : Py_False);
Py_INCREF (ttyobj.get ()); Py_INCREF (ttyobj.get ());
gdbpy_ref result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
argobj.get (), ttyobj.get (), argobj.get (), ttyobj.get (),
NULL)); NULL));
@ -241,16 +241,16 @@ cmdpy_completer_helper (struct cmd_list_element *command,
return NULL; return NULL;
} }
gdbpy_ref textobj (PyUnicode_Decode (text, strlen (text), host_charset (), gdbpy_ref<> textobj (PyUnicode_Decode (text, strlen (text), host_charset (),
NULL)); NULL));
if (textobj == NULL) if (textobj == NULL)
error (_("Could not convert argument to Python string.")); error (_("Could not convert argument to Python string."));
gdbpy_ref wordobj (PyUnicode_Decode (word, strlen (word), host_charset (), gdbpy_ref<> wordobj (PyUnicode_Decode (word, strlen (word), host_charset (),
NULL)); NULL));
if (wordobj == NULL) if (wordobj == NULL)
error (_("Could not convert argument to Python string.")); error (_("Could not convert argument to Python string."));
gdbpy_ref resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj, gdbpy_ref<> resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj,
complete_cst, complete_cst,
textobj.get (), textobj.get (),
wordobj.get (), NULL)); wordobj.get (), NULL));
@ -276,7 +276,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command,
/* Calling our helper to obtain the PyObject of the Python /* Calling our helper to obtain the PyObject of the Python
function. */ function. */
gdbpy_ref resultobj (cmdpy_completer_helper (command, text, word)); gdbpy_ref<> resultobj (cmdpy_completer_helper (command, text, word));
/* Check if there was an error. */ /* Check if there was an error. */
if (resultobj == NULL) if (resultobj == NULL)
@ -317,7 +317,7 @@ cmdpy_completer (struct cmd_list_element *command,
/* Calling our helper to obtain the PyObject of the Python /* Calling our helper to obtain the PyObject of the Python
function. */ function. */
gdbpy_ref resultobj (cmdpy_completer_helper (command, text, word)); gdbpy_ref<> resultobj (cmdpy_completer_helper (command, text, word));
/* If the result object of calling the Python function is NULL, it /* If the result object of calling the Python function is NULL, it
means that there was an error. In this case, just give up and means that there was an error. In this case, just give up and
@ -342,14 +342,14 @@ cmdpy_completer (struct cmd_list_element *command,
} }
else else
{ {
gdbpy_ref iter (PyObject_GetIter (resultobj.get ())); gdbpy_ref<> iter (PyObject_GetIter (resultobj.get ()));
if (iter == NULL) if (iter == NULL)
return NULL; return NULL;
while (true) while (true)
{ {
gdbpy_ref elt (PyIter_Next (iter.get ())); gdbpy_ref<> elt (PyIter_Next (iter.get ()));
if (elt == NULL) if (elt == NULL)
break; break;
@ -569,7 +569,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
} }
if (PyObject_HasAttr (self, gdbpy_doc_cst)) if (PyObject_HasAttr (self, gdbpy_doc_cst))
{ {
gdbpy_ref ds_obj (PyObject_GetAttr (self, gdbpy_doc_cst)); gdbpy_ref<> ds_obj (PyObject_GetAttr (self, gdbpy_doc_cst));
if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ())) if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
{ {
@ -756,7 +756,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "s", &input)) if (!PyArg_ParseTuple (args, "s", &input))
return NULL; return NULL;
gdbpy_ref py_argv (PyList_New (0)); gdbpy_ref<> py_argv (PyList_New (0));
if (py_argv == NULL) if (py_argv == NULL)
return NULL; return NULL;
@ -771,7 +771,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
for (i = 0; c_argv[i] != NULL; ++i) for (i = 0; c_argv[i] != NULL; ++i)
{ {
gdbpy_ref argp (PyString_FromString (c_argv[i])); gdbpy_ref<> argp (PyString_FromString (c_argv[i]));
if (argp == NULL if (argp == NULL
|| PyList_Append (py_argv.get (), argp.get ()) < 0) || PyList_Append (py_argv.get (), argp.get ()) < 0)

View file

@ -40,7 +40,7 @@ emit_continue_event (ptid_t ptid)
if (evregpy_no_listeners_p (gdb_py_events.cont)) if (evregpy_no_listeners_p (gdb_py_events.cont))
return 0; return 0;
gdbpy_ref event (create_continue_event_object ()); gdbpy_ref<> event (create_continue_event_object ());
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.cont); return evpy_emit_event (event.get (), gdb_py_events.cont);
return -1; return -1;

View file

@ -95,7 +95,7 @@ evpy_emit_event (PyObject *event,
notifying listeners to avoid skipping callbacks notifying listeners to avoid skipping callbacks
in the case of a callback being disconnected during in the case of a callback being disconnected during
a notification. */ a notification. */
gdbpy_ref callback_list_copy (PySequence_List (registry->callbacks)); gdbpy_ref<> callback_list_copy (PySequence_List (registry->callbacks));
if (callback_list_copy == NULL) if (callback_list_copy == NULL)
return -1; return -1;
@ -106,7 +106,8 @@ evpy_emit_event (PyObject *event,
if (func == NULL) if (func == NULL)
return -1; return -1;
gdbpy_ref func_result (PyObject_CallFunctionObjArgs (func, event, NULL)); gdbpy_ref<> func_result (PyObject_CallFunctionObjArgs (func, event,
NULL));
if (func_result == NULL) if (func_result == NULL)
{ {

View file

@ -26,14 +26,14 @@ extern PyTypeObject exited_event_object_type
static PyObject * static PyObject *
create_exited_event_object (const LONGEST *exit_code, struct inferior *inf) create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
{ {
gdbpy_ref exited_event (create_event_object (&exited_event_object_type)); gdbpy_ref<> exited_event (create_event_object (&exited_event_object_type));
if (exited_event == NULL) if (exited_event == NULL)
return NULL; return NULL;
if (exit_code) if (exit_code)
{ {
gdbpy_ref exit_code_obj (PyLong_FromLongLong (*exit_code)); gdbpy_ref<> exit_code_obj (PyLong_FromLongLong (*exit_code));
if (exit_code_obj == NULL) if (exit_code_obj == NULL)
return NULL; return NULL;
@ -42,7 +42,7 @@ create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
return NULL; return NULL;
} }
gdbpy_ref inf_obj (inferior_to_inferior_object (inf)); gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
if (inf_obj == NULL || evpy_add_attribute (exited_event.get (), if (inf_obj == NULL || evpy_add_attribute (exited_event.get (),
"inferior", "inferior",
inf_obj.get ()) < 0) inf_obj.get ()) < 0)
@ -60,7 +60,7 @@ emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
if (evregpy_no_listeners_p (gdb_py_events.exited)) if (evregpy_no_listeners_p (gdb_py_events.exited))
return 0; return 0;
gdbpy_ref event (create_exited_event_object (exit_code, inf)); gdbpy_ref<> event (create_exited_event_object (exit_code, inf));
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.exited); return evpy_emit_event (event.get (), gdb_py_events.exited);

View file

@ -338,7 +338,7 @@ bpfinishpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj)
if (bpfinish_obj->py_bp.bp->enable_state == bp_enabled if (bpfinish_obj->py_bp.bp->enable_state == bp_enabled
&& PyObject_HasAttrString (py_obj, outofscope_func)) && PyObject_HasAttrString (py_obj, outofscope_func))
{ {
gdbpy_ref meth_result (PyObject_CallMethod (py_obj, outofscope_func, gdbpy_ref<> meth_result (PyObject_CallMethod (py_obj, outofscope_func,
NULL)); NULL));
if (meth_result == NULL) if (meth_result == NULL)
gdbpy_print_stack (); gdbpy_print_stack ();

View file

@ -58,7 +58,7 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
struct symbol **sym, struct block **sym_block, struct symbol **sym, struct block **sym_block,
const struct language_defn **language) const struct language_defn **language)
{ {
gdbpy_ref result (PyObject_CallMethod (obj, "symbol", NULL)); gdbpy_ref<> result (PyObject_CallMethod (obj, "symbol", NULL));
if (result == NULL) if (result == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -129,7 +129,7 @@ extract_value (PyObject *obj, struct value **value)
{ {
if (PyObject_HasAttrString (obj, "value")) if (PyObject_HasAttrString (obj, "value"))
{ {
gdbpy_ref vresult (PyObject_CallMethod (obj, "value", NULL)); gdbpy_ref<> vresult (PyObject_CallMethod (obj, "value", NULL));
if (vresult == NULL) if (vresult == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -305,7 +305,7 @@ get_py_iter_from_func (PyObject *filter, char *func)
{ {
if (PyObject_HasAttrString (filter, func)) if (PyObject_HasAttrString (filter, func))
{ {
gdbpy_ref result (PyObject_CallMethod (filter, func, NULL)); gdbpy_ref<> result (PyObject_CallMethod (filter, func, NULL));
if (result != NULL) if (result != NULL)
{ {
@ -508,7 +508,7 @@ enumerate_args (PyObject *iter,
commas in the argument output is correct. At the end of the commas in the argument output is correct. At the end of the
loop block collect another item from the iterator, and, if it is loop block collect another item from the iterator, and, if it is
not null emit a comma. */ not null emit a comma. */
gdbpy_ref item (PyIter_Next (iter)); gdbpy_ref<> item (PyIter_Next (iter));
if (item == NULL && PyErr_Occurred ()) if (item == NULL && PyErr_Occurred ())
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -693,7 +693,7 @@ enumerate_locals (PyObject *iter,
int local_indent = 8 + (8 * indent); int local_indent = 8 + (8 * indent);
gdb::optional<ui_out_emit_tuple> tuple; gdb::optional<ui_out_emit_tuple> tuple;
gdbpy_ref item (PyIter_Next (iter)); gdbpy_ref<> item (PyIter_Next (iter));
if (item == NULL) if (item == NULL)
break; break;
@ -806,11 +806,11 @@ py_mi_print_variables (PyObject *filter, struct ui_out *out,
enum ext_lang_frame_args args_type, enum ext_lang_frame_args args_type,
struct frame_info *frame) struct frame_info *frame)
{ {
gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args")); gdbpy_ref<> args_iter (get_py_iter_from_func (filter, "frame_args"));
if (args_iter == NULL) if (args_iter == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals")); gdbpy_ref<> locals_iter (get_py_iter_from_func (filter, "frame_locals"));
if (locals_iter == NULL) if (locals_iter == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -840,7 +840,7 @@ py_print_locals (PyObject *filter,
int indent, int indent,
struct frame_info *frame) struct frame_info *frame)
{ {
gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals")); gdbpy_ref<> locals_iter (get_py_iter_from_func (filter, "frame_locals"));
if (locals_iter == NULL) if (locals_iter == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -865,7 +865,7 @@ py_print_args (PyObject *filter,
enum ext_lang_frame_args args_type, enum ext_lang_frame_args args_type,
struct frame_info *frame) struct frame_info *frame)
{ {
gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args")); gdbpy_ref<> args_iter (get_py_iter_from_func (filter, "frame_args"));
if (args_iter == NULL) if (args_iter == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -943,7 +943,8 @@ py_print_frame (PyObject *filter, int flags,
/* Get the underlying frame. This is needed to determine GDB /* Get the underlying frame. This is needed to determine GDB
architecture, and also, in the cases of frame variables/arguments to architecture, and also, in the cases of frame variables/arguments to
read them if they returned filter object requires us to do so. */ read them if they returned filter object requires us to do so. */
gdbpy_ref py_inf_frame (PyObject_CallMethod (filter, "inferior_frame", NULL)); gdbpy_ref<> py_inf_frame (PyObject_CallMethod (filter, "inferior_frame",
NULL));
if (py_inf_frame == NULL) if (py_inf_frame == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -1000,7 +1001,7 @@ py_print_frame (PyObject *filter, int flags,
address printing. */ address printing. */
if (PyObject_HasAttrString (filter, "address")) if (PyObject_HasAttrString (filter, "address"))
{ {
gdbpy_ref paddr (PyObject_CallMethod (filter, "address", NULL)); gdbpy_ref<> paddr (PyObject_CallMethod (filter, "address", NULL));
if (paddr == NULL) if (paddr == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -1076,7 +1077,7 @@ py_print_frame (PyObject *filter, int flags,
/* Print frame function name. */ /* Print frame function name. */
if (PyObject_HasAttrString (filter, "function")) if (PyObject_HasAttrString (filter, "function"))
{ {
gdbpy_ref py_func (PyObject_CallMethod (filter, "function", NULL)); gdbpy_ref<> py_func (PyObject_CallMethod (filter, "function", NULL));
const char *function = NULL; const char *function = NULL;
if (py_func == NULL) if (py_func == NULL)
@ -1153,7 +1154,7 @@ py_print_frame (PyObject *filter, int flags,
if (PyObject_HasAttrString (filter, "filename")) if (PyObject_HasAttrString (filter, "filename"))
{ {
gdbpy_ref py_fn (PyObject_CallMethod (filter, "filename", NULL)); gdbpy_ref<> py_fn (PyObject_CallMethod (filter, "filename", NULL));
if (py_fn == NULL) if (py_fn == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -1185,7 +1186,7 @@ py_print_frame (PyObject *filter, int flags,
if (PyObject_HasAttrString (filter, "line")) if (PyObject_HasAttrString (filter, "line"))
{ {
gdbpy_ref py_line (PyObject_CallMethod (filter, "line", NULL)); gdbpy_ref<> py_line (PyObject_CallMethod (filter, "line", NULL));
int line; int line;
if (py_line == NULL) if (py_line == NULL)
@ -1239,7 +1240,7 @@ py_print_frame (PyObject *filter, int flags,
{ {
/* Finally recursively print elided frames, if any. */ /* Finally recursively print elided frames, if any. */
gdbpy_ref elided (get_py_iter_from_func (filter, "elided")); gdbpy_ref<> elided (get_py_iter_from_func (filter, "elided"));
if (elided == NULL) if (elided == NULL)
return EXT_LANG_BT_ERROR; return EXT_LANG_BT_ERROR;
@ -1254,7 +1255,7 @@ py_print_frame (PyObject *filter, int flags,
while ((item = PyIter_Next (elided.get ()))) while ((item = PyIter_Next (elided.get ())))
{ {
gdbpy_ref item_ref (item); gdbpy_ref<> item_ref (item);
enum ext_lang_bt_status success = py_print_frame (item, flags, enum ext_lang_bt_status success = py_print_frame (item, flags,
args_type, out, args_type, out,
@ -1279,28 +1280,28 @@ static PyObject *
bootstrap_python_frame_filters (struct frame_info *frame, bootstrap_python_frame_filters (struct frame_info *frame,
int frame_low, int frame_high) int frame_low, int frame_high)
{ {
gdbpy_ref frame_obj (frame_info_to_frame_object (frame)); gdbpy_ref<> frame_obj (frame_info_to_frame_object (frame));
if (frame_obj == NULL) if (frame_obj == NULL)
return NULL; return NULL;
gdbpy_ref module (PyImport_ImportModule ("gdb.frames")); gdbpy_ref<> module (PyImport_ImportModule ("gdb.frames"));
if (module == NULL) if (module == NULL)
return NULL; return NULL;
gdbpy_ref sort_func (PyObject_GetAttrString (module.get (), gdbpy_ref<> sort_func (PyObject_GetAttrString (module.get (),
"execute_frame_filters")); "execute_frame_filters"));
if (sort_func == NULL) if (sort_func == NULL)
return NULL; return NULL;
gdbpy_ref py_frame_low (PyInt_FromLong (frame_low)); gdbpy_ref<> py_frame_low (PyInt_FromLong (frame_low));
if (py_frame_low == NULL) if (py_frame_low == NULL)
return NULL; return NULL;
gdbpy_ref py_frame_high (PyInt_FromLong (frame_high)); gdbpy_ref<> py_frame_high (PyInt_FromLong (frame_high));
if (py_frame_high == NULL) if (py_frame_high == NULL)
return NULL; return NULL;
gdbpy_ref iterable (PyObject_CallFunctionObjArgs (sort_func.get (), gdbpy_ref<> iterable (PyObject_CallFunctionObjArgs (sort_func.get (),
frame_obj.get (), frame_obj.get (),
py_frame_low.get (), py_frame_low.get (),
py_frame_high.get (), py_frame_high.get (),
@ -1354,7 +1355,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
gdbpy_enter enter_py (gdbarch, current_language); gdbpy_enter enter_py (gdbarch, current_language);
gdbpy_ref iterable (bootstrap_python_frame_filters (frame, frame_low, gdbpy_ref<> iterable (bootstrap_python_frame_filters (frame, frame_low,
frame_high)); frame_high));
if (iterable == NULL) if (iterable == NULL)
@ -1389,7 +1390,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
while (true) while (true)
{ {
gdbpy_ref item (PyIter_Next (iterable.get ())); gdbpy_ref<> item (PyIter_Next (iterable.get ()));
if (item == NULL) if (item == NULL)
{ {

View file

@ -38,14 +38,14 @@ static PyObject *
convert_values_to_python (int argc, struct value **argv) convert_values_to_python (int argc, struct value **argv)
{ {
int i; int i;
gdbpy_ref result (PyTuple_New (argc)); gdbpy_ref<> result (PyTuple_New (argc));
if (result == NULL) if (result == NULL)
return NULL; return NULL;
for (i = 0; i < argc; ++i) for (i = 0; i < argc; ++i)
{ {
gdbpy_ref elt (value_to_value_object (argv[i])); gdbpy_ref<> elt (value_to_value_object (argv[i]));
if (elt == NULL) if (elt == NULL)
return NULL; return NULL;
PyTuple_SetItem (result.get (), i, elt.release ()); PyTuple_SetItem (result.get (), i, elt.release ());
@ -63,8 +63,8 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language,
be destroyed. */ be destroyed. */
gdbpy_enter enter_py (gdbarch, language); gdbpy_enter enter_py (gdbarch, language);
struct value *value; struct value *value;
gdbpy_ref result; gdbpy_ref<> result;
gdbpy_ref args (convert_values_to_python (argc, argv)); gdbpy_ref<> args (convert_values_to_python (argc, argv));
/* convert_values_to_python can return NULL on error. If we /* convert_values_to_python can return NULL on error. If we
encounter this, do not call the function, but allow the Python -> encounter this, do not call the function, but allow the Python ->
@ -74,7 +74,7 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language,
if (args != NULL) if (args != NULL)
{ {
gdbpy_ref callable (PyObject_GetAttrString ((PyObject *) cookie, gdbpy_ref<> callable (PyObject_GetAttrString ((PyObject *) cookie,
"invoke")); "invoke"));
if (callable == NULL) if (callable == NULL)
error (_("No method named 'invoke' in object.")); error (_("No method named 'invoke' in object."));
@ -159,7 +159,7 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
if (PyObject_HasAttrString (self, "__doc__")) if (PyObject_HasAttrString (self, "__doc__"))
{ {
gdbpy_ref ds_obj (PyObject_GetAttrString (self, "__doc__")); gdbpy_ref<> ds_obj (PyObject_GetAttrString (self, "__doc__"));
if (ds_obj != NULL) if (ds_obj != NULL)
{ {
if (gdbpy_is_string (ds_obj.get ())) if (gdbpy_is_string (ds_obj.get ()))

View file

@ -256,7 +256,7 @@ find_thread_object (ptid_t ptid)
if (pid == 0) if (pid == 0)
return NULL; return NULL;
gdbpy_ref inf_obj (find_inferior_object (pid)); gdbpy_ref<> inf_obj (find_inferior_object (pid));
if (inf_obj == NULL) if (inf_obj == NULL)
return NULL; return NULL;
@ -405,7 +405,7 @@ static int
build_inferior_list (struct inferior *inf, void *arg) build_inferior_list (struct inferior *inf, void *arg)
{ {
PyObject *list = (PyObject *) arg; PyObject *list = (PyObject *) arg;
gdbpy_ref inferior (inferior_to_inferior_object (inf)); gdbpy_ref<> inferior (inferior_to_inferior_object (inf));
if (inferior == NULL) if (inferior == NULL)
return 0; return 0;
@ -418,7 +418,7 @@ build_inferior_list (struct inferior *inf, void *arg)
PyObject * PyObject *
gdbpy_inferiors (PyObject *unused, PyObject *unused2) gdbpy_inferiors (PyObject *unused, PyObject *unused2)
{ {
gdbpy_ref list (PyList_New (0)); gdbpy_ref<> list (PyList_New (0));
if (list == NULL) if (list == NULL)
return NULL; return NULL;

View file

@ -37,7 +37,7 @@ static PyObject *
create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid, create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
CORE_ADDR addr) CORE_ADDR addr)
{ {
gdbpy_ref event; gdbpy_ref<> event;
int failed; int failed;
switch (flag) switch (flag)
@ -52,14 +52,14 @@ create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
gdb_assert_not_reached ("invalid inferior_call_kind"); gdb_assert_not_reached ("invalid inferior_call_kind");
} }
gdbpy_ref ptid_obj (gdbpy_create_ptid_object (ptid)); gdbpy_ref<> ptid_obj (gdbpy_create_ptid_object (ptid));
if (ptid_obj == NULL) if (ptid_obj == NULL)
return NULL; return NULL;
if (evpy_add_attribute (event.get (), "ptid", ptid_obj.get ()) < 0) if (evpy_add_attribute (event.get (), "ptid", ptid_obj.get ()) < 0)
return NULL; return NULL;
gdbpy_ref addr_obj (PyLong_FromLongLong (addr)); gdbpy_ref<> addr_obj (PyLong_FromLongLong (addr));
if (addr_obj == NULL) if (addr_obj == NULL)
return NULL; return NULL;
@ -76,18 +76,18 @@ static PyObject *
create_register_changed_event_object (struct frame_info *frame, create_register_changed_event_object (struct frame_info *frame,
int regnum) int regnum)
{ {
gdbpy_ref event (create_event_object (&register_changed_event_object_type)); gdbpy_ref<> event (create_event_object (&register_changed_event_object_type));
if (event == NULL) if (event == NULL)
return NULL; return NULL;
gdbpy_ref frame_obj (frame_info_to_frame_object (frame)); gdbpy_ref<> frame_obj (frame_info_to_frame_object (frame));
if (frame_obj == NULL) if (frame_obj == NULL)
return NULL; return NULL;
if (evpy_add_attribute (event.get (), "frame", frame_obj.get ()) < 0) if (evpy_add_attribute (event.get (), "frame", frame_obj.get ()) < 0)
return NULL; return NULL;
gdbpy_ref regnum_obj (PyLong_FromLongLong (regnum)); gdbpy_ref<> regnum_obj (PyLong_FromLongLong (regnum));
if (regnum_obj == NULL) if (regnum_obj == NULL)
return NULL; return NULL;
@ -103,19 +103,19 @@ create_register_changed_event_object (struct frame_info *frame,
static PyObject * static PyObject *
create_memory_changed_event_object (CORE_ADDR addr, ssize_t len) create_memory_changed_event_object (CORE_ADDR addr, ssize_t len)
{ {
gdbpy_ref event (create_event_object (&memory_changed_event_object_type)); gdbpy_ref<> event (create_event_object (&memory_changed_event_object_type));
if (event == NULL) if (event == NULL)
return NULL; return NULL;
gdbpy_ref addr_obj (PyLong_FromLongLong (addr)); gdbpy_ref<> addr_obj (PyLong_FromLongLong (addr));
if (addr_obj == NULL) if (addr_obj == NULL)
return NULL; return NULL;
if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0) if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0)
return NULL; return NULL;
gdbpy_ref len_obj (PyLong_FromLong (len)); gdbpy_ref<> len_obj (PyLong_FromLong (len));
if (len_obj == NULL) if (len_obj == NULL)
return NULL; return NULL;
@ -137,7 +137,7 @@ emit_inferior_call_event (inferior_call_kind flag, ptid_t thread,
if (evregpy_no_listeners_p (gdb_py_events.inferior_call)) if (evregpy_no_listeners_p (gdb_py_events.inferior_call))
return 0; return 0;
gdbpy_ref event (create_inferior_call_event_object (flag, thread, addr)); gdbpy_ref<> event (create_inferior_call_event_object (flag, thread, addr));
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.inferior_call); return evpy_emit_event (event.get (), gdb_py_events.inferior_call);
return -1; return -1;
@ -152,7 +152,7 @@ emit_memory_changed_event (CORE_ADDR addr, ssize_t len)
if (evregpy_no_listeners_p (gdb_py_events.memory_changed)) if (evregpy_no_listeners_p (gdb_py_events.memory_changed))
return 0; return 0;
gdbpy_ref event (create_memory_changed_event_object (addr, len)); gdbpy_ref<> event (create_memory_changed_event_object (addr, len));
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.memory_changed); return evpy_emit_event (event.get (), gdb_py_events.memory_changed);
return -1; return -1;
@ -167,7 +167,7 @@ emit_register_changed_event (struct frame_info* frame, int regnum)
if (evregpy_no_listeners_p (gdb_py_events.register_changed)) if (evregpy_no_listeners_p (gdb_py_events.register_changed))
return 0; return 0;
gdbpy_ref event (create_register_changed_event_object (frame, regnum)); gdbpy_ref<> event (create_register_changed_event_object (frame, regnum));
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.register_changed); return evpy_emit_event (event.get (), gdb_py_events.register_changed);
return -1; return -1;

View file

@ -132,14 +132,14 @@ build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec)
if (vec_len < 1) if (vec_len < 1)
Py_RETURN_NONE; Py_RETURN_NONE;
gdbpy_ref tuple (PyTuple_New (vec_len)); gdbpy_ref<> tuple (PyTuple_New (vec_len));
if (tuple == NULL) if (tuple == NULL)
return NULL; return NULL;
for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i) for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i)
{ {
gdbpy_ref obj (build_linetable_entry (line, pc)); gdbpy_ref<> obj (build_linetable_entry (line, pc));
if (obj == NULL) if (obj == NULL)
return NULL; return NULL;
@ -238,7 +238,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
return NULL; return NULL;
} }
gdbpy_ref source_dict (PyDict_New ()); gdbpy_ref<> source_dict (PyDict_New ());
if (source_dict == NULL) if (source_dict == NULL)
return NULL; return NULL;
@ -250,7 +250,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
include in the source set. */ include in the source set. */
if (item->line > 0) if (item->line > 0)
{ {
gdbpy_ref line (gdb_py_object_from_longest (item->line)); gdbpy_ref<> line (gdb_py_object_from_longest (item->line));
if (line == NULL) if (line == NULL)
return NULL; return NULL;

View file

@ -30,7 +30,7 @@ create_new_objfile_event_object (struct objfile *objfile)
{ {
PyObject *py_objfile; PyObject *py_objfile;
gdbpy_ref objfile_event gdbpy_ref<> objfile_event
(create_event_object (&new_objfile_event_object_type)); (create_event_object (&new_objfile_event_object_type));
if (objfile_event == NULL) if (objfile_event == NULL)
return NULL; return NULL;
@ -56,7 +56,7 @@ emit_new_objfile_event (struct objfile *objfile)
if (evregpy_no_listeners_p (gdb_py_events.new_objfile)) if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
return 0; return 0;
gdbpy_ref event (create_new_objfile_event_object (objfile)); gdbpy_ref<> event (create_new_objfile_event_object (objfile));
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.new_objfile); return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
return -1; return -1;
@ -75,7 +75,7 @@ create_clear_objfiles_event_object (void)
{ {
PyObject *py_progspace; PyObject *py_progspace;
gdbpy_ref objfile_event gdbpy_ref<> objfile_event
(create_event_object (&clear_objfiles_event_object_type)); (create_event_object (&clear_objfiles_event_object_type));
if (objfile_event == NULL) if (objfile_event == NULL)
return NULL; return NULL;
@ -102,7 +102,7 @@ emit_clear_objfiles_event (void)
if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles)) if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
return 0; return 0;
gdbpy_ref event (create_clear_objfiles_event_object ()); gdbpy_ref<> event (create_clear_objfiles_event_object ());
if (event != NULL) if (event != NULL)
return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles); return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
return -1; return -1;

View file

@ -307,7 +307,7 @@ get_doc_string (PyObject *object, PyObject *attr)
if (PyObject_HasAttr (object, attr)) if (PyObject_HasAttr (object, attr))
{ {
gdbpy_ref ds_obj (PyObject_GetAttr (object, attr)); gdbpy_ref<> ds_obj (PyObject_GetAttr (object, attr));
if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ())) if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
{ {
@ -329,7 +329,7 @@ static gdb::unique_xmalloc_ptr<char>
call_doc_function (PyObject *obj, PyObject *method, PyObject *arg) call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
{ {
gdb::unique_xmalloc_ptr<char> data; gdb::unique_xmalloc_ptr<char> data;
gdbpy_ref result (PyObject_CallMethodObjArgs (obj, method, arg, NULL)); gdbpy_ref<> result (PyObject_CallMethodObjArgs (obj, method, arg, NULL));
if (result == NULL) if (result == NULL)
return NULL; return NULL;
@ -364,7 +364,7 @@ get_set_value (char *args, int from_tty,
gdb::unique_xmalloc_ptr<char> set_doc_string; gdb::unique_xmalloc_ptr<char> set_doc_string;
gdbpy_enter enter_py (get_current_arch (), current_language); gdbpy_enter enter_py (get_current_arch (), current_language);
gdbpy_ref set_doc_func (PyString_FromString ("get_set_string")); gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
if (set_doc_func == NULL) if (set_doc_func == NULL)
{ {
@ -407,7 +407,7 @@ get_show_value (struct ui_file *file, int from_tty,
gdb::unique_xmalloc_ptr<char> show_doc_string; gdb::unique_xmalloc_ptr<char> show_doc_string;
gdbpy_enter enter_py (get_current_arch (), current_language); gdbpy_enter enter_py (get_current_arch (), current_language);
gdbpy_ref show_doc_func (PyString_FromString ("get_show_string")); gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
if (show_doc_func == NULL) if (show_doc_func == NULL)
{ {
@ -417,7 +417,7 @@ get_show_value (struct ui_file *file, int from_tty,
if (PyObject_HasAttr (obj, show_doc_func.get ())) if (PyObject_HasAttr (obj, show_doc_func.get ()))
{ {
gdbpy_ref val_obj (PyString_FromString (value)); gdbpy_ref<> val_obj (PyString_FromString (value));
if (val_obj == NULL) if (val_obj == NULL)
{ {
@ -586,7 +586,7 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
for (i = 0; i < size; ++i) for (i = 0; i < size; ++i)
{ {
gdbpy_ref item (PySequence_GetItem (enum_values, i)); gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
if (item == NULL) if (item == NULL)
{ {

View file

@ -60,7 +60,7 @@ search_pp_list (PyObject *list, PyObject *value)
/* Skip if disabled. */ /* Skip if disabled. */
if (PyObject_HasAttr (function, gdbpy_enabled_cst)) if (PyObject_HasAttr (function, gdbpy_enabled_cst))
{ {
gdbpy_ref attr (PyObject_GetAttr (function, gdbpy_enabled_cst)); gdbpy_ref<> attr (PyObject_GetAttr (function, gdbpy_enabled_cst));
int cmp; int cmp;
if (attr == NULL) if (attr == NULL)
@ -73,7 +73,8 @@ search_pp_list (PyObject *list, PyObject *value)
continue; continue;
} }
gdbpy_ref printer (PyObject_CallFunctionObjArgs (function, value, NULL)); gdbpy_ref<> printer (PyObject_CallFunctionObjArgs (function, value,
NULL));
if (printer == NULL) if (printer == NULL)
return NULL; return NULL;
else if (printer != Py_None) else if (printer != Py_None)
@ -104,8 +105,8 @@ find_pretty_printer_from_objfiles (PyObject *value)
continue; continue;
} }
gdbpy_ref pp_list (objfpy_get_printers (objf, NULL)); gdbpy_ref<> pp_list (objfpy_get_printers (objf, NULL));
gdbpy_ref function (search_pp_list (pp_list.get (), value)); gdbpy_ref<> function (search_pp_list (pp_list.get (), value));
/* If there is an error in any objfile list, abort the search and exit. */ /* If there is an error in any objfile list, abort the search and exit. */
if (function == NULL) if (function == NULL)
@ -131,7 +132,7 @@ find_pretty_printer_from_progspace (PyObject *value)
if (!obj) if (!obj)
return NULL; return NULL;
gdbpy_ref pp_list (pspy_get_printers (obj, NULL)); gdbpy_ref<> pp_list (pspy_get_printers (obj, NULL));
return search_pp_list (pp_list.get (), value); return search_pp_list (pp_list.get (), value);
} }
@ -148,7 +149,7 @@ find_pretty_printer_from_gdb (PyObject *value)
if (gdb_python_module == NULL if (gdb_python_module == NULL
|| ! PyObject_HasAttrString (gdb_python_module, "pretty_printers")) || ! PyObject_HasAttrString (gdb_python_module, "pretty_printers"))
Py_RETURN_NONE; Py_RETURN_NONE;
gdbpy_ref pp_list (PyObject_GetAttrString (gdb_python_module, gdbpy_ref<> pp_list (PyObject_GetAttrString (gdb_python_module,
"pretty_printers")); "pretty_printers"));
if (pp_list == NULL || ! PyList_Check (pp_list.get ())) if (pp_list == NULL || ! PyList_Check (pp_list.get ()))
Py_RETURN_NONE; Py_RETURN_NONE;
@ -165,7 +166,7 @@ find_pretty_printer (PyObject *value)
{ {
/* Look at the pretty-printer list for each objfile /* Look at the pretty-printer list for each objfile
in the current program-space. */ in the current program-space. */
gdbpy_ref function (find_pretty_printer_from_objfiles (value)); gdbpy_ref<> function (find_pretty_printer_from_objfiles (value));
if (function == NULL || function != Py_None) if (function == NULL || function != Py_None)
return function.release (); return function.release ();
@ -228,7 +229,7 @@ gdbpy_get_display_hint (PyObject *printer)
if (! PyObject_HasAttr (printer, gdbpy_display_hint_cst)) if (! PyObject_HasAttr (printer, gdbpy_display_hint_cst))
return NULL; return NULL;
gdbpy_ref hint (PyObject_CallMethodObjArgs (printer, gdbpy_display_hint_cst, gdbpy_ref<> hint (PyObject_CallMethodObjArgs (printer, gdbpy_display_hint_cst,
NULL)); NULL));
if (hint != NULL) if (hint != NULL)
{ {
@ -256,9 +257,9 @@ print_stack_unless_memory_error (struct ui_file *stream)
PyErr_Fetch (&type, &value, &trace); PyErr_Fetch (&type, &value, &trace);
gdbpy_ref type_ref (type); gdbpy_ref<> type_ref (type);
gdbpy_ref value_ref (value); gdbpy_ref<> value_ref (value);
gdbpy_ref trace_ref (trace); gdbpy_ref<> trace_ref (trace);
gdb::unique_xmalloc_ptr<char> gdb::unique_xmalloc_ptr<char>
msg (gdbpy_exception_to_string (type, value)); msg (gdbpy_exception_to_string (type, value));
@ -286,7 +287,7 @@ print_string_repr (PyObject *printer, const char *hint,
struct value *replacement = NULL; struct value *replacement = NULL;
enum string_repr_result result = string_repr_ok; enum string_repr_result result = string_repr_ok;
gdbpy_ref py_str (pretty_print_one_value (printer, &replacement)); gdbpy_ref<> py_str (pretty_print_one_value (printer, &replacement));
if (py_str != NULL) if (py_str != NULL)
{ {
if (py_str == Py_None) if (py_str == Py_None)
@ -308,7 +309,7 @@ print_string_repr (PyObject *printer, const char *hint,
} }
else else
{ {
gdbpy_ref string gdbpy_ref<> string
(python_string_to_target_python_string (py_str.get ())); (python_string_to_target_python_string (py_str.get ()));
if (string != NULL) if (string != NULL)
{ {
@ -379,7 +380,7 @@ class dummy_python_frame
bool m_valid; bool m_valid;
PyFrameObject *m_saved_frame; PyFrameObject *m_saved_frame;
gdbpy_ref m_frame; gdbpy_ref<> m_frame;
PyThreadState *m_tstate; PyThreadState *m_tstate;
}; };
@ -391,11 +392,11 @@ dummy_python_frame::dummy_python_frame ()
PyCodeObject *code; PyCodeObject *code;
PyFrameObject *frame; PyFrameObject *frame;
gdbpy_ref empty_string (PyString_FromString ("")); gdbpy_ref<> empty_string (PyString_FromString (""));
if (empty_string == NULL) if (empty_string == NULL)
return; return;
gdbpy_ref null_tuple (PyTuple_New (0)); gdbpy_ref<> null_tuple (PyTuple_New (0));
if (null_tuple == NULL) if (null_tuple == NULL)
return; return;
@ -418,9 +419,9 @@ dummy_python_frame::dummy_python_frame ()
); );
if (code == NULL) if (code == NULL)
return; return;
gdbpy_ref code_holder ((PyObject *) code); gdbpy_ref<> code_holder ((PyObject *) code);
gdbpy_ref globals (PyDict_New ()); gdbpy_ref<> globals (PyDict_New ());
if (globals == NULL) if (globals == NULL)
return; return;
@ -457,7 +458,7 @@ print_children (PyObject *printer, const char *hint,
is_map = hint && ! strcmp (hint, "map"); is_map = hint && ! strcmp (hint, "map");
is_array = hint && ! strcmp (hint, "array"); is_array = hint && ! strcmp (hint, "array");
gdbpy_ref children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, gdbpy_ref<> children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
NULL)); NULL));
if (children == NULL) if (children == NULL)
{ {
@ -465,7 +466,7 @@ print_children (PyObject *printer, const char *hint,
return; return;
} }
gdbpy_ref iter (PyObject_GetIter (children.get ())); gdbpy_ref<> iter (PyObject_GetIter (children.get ()));
if (iter == NULL) if (iter == NULL)
{ {
print_stack_unless_memory_error (stream); print_stack_unless_memory_error (stream);
@ -502,7 +503,7 @@ print_children (PyObject *printer, const char *hint,
PyObject *py_v; PyObject *py_v;
const char *name; const char *name;
gdbpy_ref item (PyIter_Next (iter.get ())); gdbpy_ref<> item (PyIter_Next (iter.get ()));
if (item == NULL) if (item == NULL)
{ {
if (PyErr_Occurred ()) if (PyErr_Occurred ())
@ -674,7 +675,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
/* Instantiate the printer. */ /* Instantiate the printer. */
value = value_from_component (val, type, embedded_offset); value = value_from_component (val, type, embedded_offset);
gdbpy_ref val_obj (value_to_value_object (value)); gdbpy_ref<> val_obj (value_to_value_object (value));
if (val_obj == NULL) if (val_obj == NULL)
{ {
print_stack_unless_memory_error (stream); print_stack_unless_memory_error (stream);
@ -682,7 +683,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
} }
/* Find the constructor. */ /* Find the constructor. */
gdbpy_ref printer (find_pretty_printer (val_obj.get ())); gdbpy_ref<> printer (find_pretty_printer (val_obj.get ()));
if (printer == NULL) if (printer == NULL)
{ {
print_stack_unless_memory_error (stream); print_stack_unless_memory_error (stream);
@ -750,7 +751,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
} }
END_CATCH END_CATCH
gdbpy_ref val_obj (value_to_value_object (value)); gdbpy_ref<> val_obj (value_to_value_object (value));
if (val_obj == NULL) if (val_obj == NULL)
return NULL; return NULL;

View file

@ -1,6 +1,6 @@
/* Python reference-holding class /* Python reference-holding class
Copyright (C) 2016 Free Software Foundation, Inc. Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of GDB. This file is part of GDB.
@ -23,20 +23,23 @@
#include "common/gdb_ref_ptr.h" #include "common/gdb_ref_ptr.h"
/* A policy class for gdb::ref_ptr for Python reference counting. */ /* A policy class for gdb::ref_ptr for Python reference counting. */
template<typename T>
struct gdbpy_ref_policy struct gdbpy_ref_policy
{ {
static void incref (PyObject *ptr) static void incref (T *ptr)
{ {
Py_INCREF (ptr); Py_INCREF (ptr);
} }
static void decref (PyObject *ptr) static void decref (T *ptr)
{ {
Py_DECREF (ptr); Py_DECREF (ptr);
} }
}; };
/* A gdb::ref_ptr that has been specialized for Python objects. */ /* A gdb::ref_ptr that has been specialized for Python objects or
typedef gdb::ref_ptr<PyObject, gdbpy_ref_policy> gdbpy_ref; their "subclasses". */
template<typename T = PyObject> using gdbpy_ref
= gdb::ref_ptr<T, gdbpy_ref_policy<T>>;
#endif /* GDB_PYTHON_REF_H */ #endif /* GDB_PYTHON_REF_H */

View file

@ -27,7 +27,7 @@ PyObject *
create_signal_event_object (enum gdb_signal stop_signal) create_signal_event_object (enum gdb_signal stop_signal)
{ {
const char *signal_name; const char *signal_name;
gdbpy_ref signal_event_obj gdbpy_ref<> signal_event_obj
(create_stop_event_object (&signal_event_object_type)); (create_stop_event_object (&signal_event_object_type));
if (signal_event_obj == NULL) if (signal_event_obj == NULL)
@ -35,7 +35,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
signal_name = gdb_signal_to_name (stop_signal); signal_name = gdb_signal_to_name (stop_signal);
gdbpy_ref signal_name_obj (PyString_FromString (signal_name)); gdbpy_ref<> signal_name_obj (PyString_FromString (signal_name));
if (signal_name_obj == NULL) if (signal_name_obj == NULL)
return NULL; return NULL;
if (evpy_add_attribute (signal_event_obj.get (), if (evpy_add_attribute (signal_event_obj.get (),

View file

@ -36,8 +36,8 @@ create_stop_event_object (PyTypeObject *py_type)
int int
emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal) emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
{ {
gdbpy_ref stop_event_obj; gdbpy_ref<> stop_event_obj;
gdbpy_ref list; gdbpy_ref<> list;
PyObject *first_bp = NULL; PyObject *first_bp = NULL;
struct bpstats *current_bs; struct bpstats *current_bs;

View file

@ -411,7 +411,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
} }
END_CATCH END_CATCH
gdbpy_ref ret_tuple (PyTuple_New (2)); gdbpy_ref<> ret_tuple (PyTuple_New (2));
if (ret_tuple == NULL) if (ret_tuple == NULL)
return NULL; return NULL;

View file

@ -52,7 +52,7 @@ create_thread_event_object (PyTypeObject *py_type)
{ {
PyObject *thread = NULL; PyObject *thread = NULL;
gdbpy_ref thread_event_obj (create_event_object (py_type)); gdbpy_ref<> thread_event_obj (create_event_object (py_type));
if (thread_event_obj == NULL) if (thread_event_obj == NULL)
return NULL; return NULL;

View file

@ -169,12 +169,12 @@ typy_get_code (PyObject *self, void *closure)
static PyObject * static PyObject *
convert_field (struct type *type, int field) convert_field (struct type *type, int field)
{ {
gdbpy_ref result (field_new ()); gdbpy_ref<> result (field_new ());
if (result == NULL) if (result == NULL)
return NULL; return NULL;
gdbpy_ref arg (type_to_type_object (type)); gdbpy_ref<> arg (type_to_type_object (type));
if (arg == NULL) if (arg == NULL)
return NULL; return NULL;
if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0) if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0)
@ -292,13 +292,13 @@ make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind)
{ {
case iter_items: case iter_items:
{ {
gdbpy_ref key (field_name (type, i)); gdbpy_ref<> key (field_name (type, i));
if (key == NULL) if (key == NULL)
return NULL; return NULL;
gdbpy_ref value (convert_field (type, i)); gdbpy_ref<> value (convert_field (type, i));
if (value == NULL) if (value == NULL)
return NULL; return NULL;
gdbpy_ref item (PyTuple_New (2)); gdbpy_ref<> item (PyTuple_New (2));
if (item == NULL) if (item == NULL)
return NULL; return NULL;
PyTuple_SET_ITEM (item.get (), 0, key.release ()); PyTuple_SET_ITEM (item.get (), 0, key.release ());
@ -376,7 +376,7 @@ typy_fields (PyObject *self, PyObject *args)
/* Array type. Handle this as a special case because the common /* Array type. Handle this as a special case because the common
machinery wants struct or union or enum types. Build a list of machinery wants struct or union or enum types. Build a list of
one entry which is the range for the array. */ one entry which is the range for the array. */
gdbpy_ref r (convert_field (type, 0)); gdbpy_ref<> r (convert_field (type, 0));
if (r == NULL) if (r == NULL)
return NULL; return NULL;
@ -602,15 +602,15 @@ typy_range (PyObject *self, PyObject *args)
break; break;
} }
gdbpy_ref low_bound (PyLong_FromLong (low)); gdbpy_ref<> low_bound (PyLong_FromLong (low));
if (low_bound == NULL) if (low_bound == NULL)
return NULL; return NULL;
gdbpy_ref high_bound (PyLong_FromLong (high)); gdbpy_ref<> high_bound (PyLong_FromLong (high));
if (high_bound == NULL) if (high_bound == NULL)
return NULL; return NULL;
gdbpy_ref result (PyTuple_New (2)); gdbpy_ref<> result (PyTuple_New (2));
if (result == NULL) if (result == NULL)
return NULL; return NULL;

View file

@ -177,7 +177,7 @@ pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
if (PyObject_HasAttrString (pyo, attr_name)) if (PyObject_HasAttrString (pyo, attr_name))
{ {
gdbpy_ref pyo_value (PyObject_GetAttrString (pyo, attr_name)); gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
if (pyo_value != NULL && pyo_value != Py_None) if (pyo_value != NULL && pyo_value != Py_None)
{ {
@ -515,7 +515,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
/* Create PendingFrame instance to pass to sniffers. */ /* Create PendingFrame instance to pass to sniffers. */
pending_frame_object *pfo = PyObject_New (pending_frame_object, pending_frame_object *pfo = PyObject_New (pending_frame_object,
&pending_frame_object_type); &pending_frame_object_type);
gdbpy_ref pyo_pending_frame ((PyObject *) pfo); gdbpy_ref<> pyo_pending_frame ((PyObject *) pfo);
if (pyo_pending_frame == NULL) if (pyo_pending_frame == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -535,7 +535,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
gdbpy_print_stack (); gdbpy_print_stack ();
return 0; return 0;
} }
gdbpy_ref pyo_execute (PyObject_GetAttrString (gdb_python_module, gdbpy_ref<> pyo_execute (PyObject_GetAttrString (gdb_python_module,
"execute_unwinders")); "execute_unwinders"));
if (pyo_execute == NULL) if (pyo_execute == NULL)
{ {
@ -543,7 +543,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
return 0; return 0;
} }
gdbpy_ref pyo_unwind_info gdbpy_ref<> pyo_unwind_info
(PyObject_CallFunctionObjArgs (pyo_execute.get (), (PyObject_CallFunctionObjArgs (pyo_execute.get (),
pyo_pending_frame.get (), NULL)); pyo_pending_frame.get (), NULL));
if (pyo_unwind_info == NULL) if (pyo_unwind_info == NULL)

View file

@ -71,7 +71,7 @@ unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
gdb::unique_xmalloc_ptr<char> result; gdb::unique_xmalloc_ptr<char> result;
/* Translate string to named charset. */ /* Translate string to named charset. */
gdbpy_ref string (PyUnicode_AsEncodedString (unicode_str, charset, NULL)); gdbpy_ref<> string (PyUnicode_AsEncodedString (unicode_str, charset, NULL));
if (string == NULL) if (string == NULL)
return NULL; return NULL;
@ -123,7 +123,7 @@ unicode_to_target_python_string (PyObject *unicode_str)
gdb::unique_xmalloc_ptr<char> gdb::unique_xmalloc_ptr<char>
python_string_to_target_string (PyObject *obj) python_string_to_target_string (PyObject *obj)
{ {
gdbpy_ref str (python_string_to_unicode (obj)); gdbpy_ref<> str (python_string_to_unicode (obj));
if (str == NULL) if (str == NULL)
return NULL; return NULL;
@ -138,7 +138,7 @@ python_string_to_target_string (PyObject *obj)
PyObject * PyObject *
python_string_to_target_python_string (PyObject *obj) python_string_to_target_python_string (PyObject *obj)
{ {
gdbpy_ref str (python_string_to_unicode (obj)); gdbpy_ref<> str (python_string_to_unicode (obj));
if (str == NULL) if (str == NULL)
return NULL; return NULL;
@ -151,7 +151,7 @@ python_string_to_target_python_string (PyObject *obj)
gdb::unique_xmalloc_ptr<char> gdb::unique_xmalloc_ptr<char>
python_string_to_host_string (PyObject *obj) python_string_to_host_string (PyObject *obj)
{ {
gdbpy_ref str (python_string_to_unicode (obj)); gdbpy_ref<> str (python_string_to_unicode (obj));
if (str == NULL) if (str == NULL)
return NULL; return NULL;
@ -185,7 +185,7 @@ gdbpy_is_string (PyObject *obj)
gdb::unique_xmalloc_ptr<char> gdb::unique_xmalloc_ptr<char>
gdbpy_obj_to_string (PyObject *obj) gdbpy_obj_to_string (PyObject *obj)
{ {
gdbpy_ref str_obj (PyObject_Str (obj)); gdbpy_ref<> str_obj (PyObject_Str (obj));
if (str_obj != NULL) if (str_obj != NULL)
{ {
@ -269,7 +269,7 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
} }
else else
{ {
gdbpy_ref num (PyNumber_Long (obj)); gdbpy_ref<> num (PyNumber_Long (obj));
gdb_py_ulongest val; gdb_py_ulongest val;
if (num == NULL) if (num == NULL)

View file

@ -566,7 +566,7 @@ value_has_field (struct value *v, PyObject *field)
{ {
struct type *parent_type, *val_type; struct type *parent_type, *val_type;
enum type_code type_code; enum type_code type_code;
gdbpy_ref type_object (PyObject_GetAttrString (field, "parent_type")); gdbpy_ref<> type_object (PyObject_GetAttrString (field, "parent_type"));
int has_field = 0; int has_field = 0;
if (type_object == NULL) if (type_object == NULL)
@ -612,7 +612,7 @@ value_has_field (struct value *v, PyObject *field)
static int static int
get_field_flag (PyObject *field, const char *flag_name) get_field_flag (PyObject *field, const char *flag_name)
{ {
gdbpy_ref flag_object (PyObject_GetAttrString (field, flag_name)); gdbpy_ref<> flag_object (PyObject_GetAttrString (field, flag_name));
if (flag_object == NULL) if (flag_object == NULL)
return -1; return -1;
@ -626,7 +626,7 @@ get_field_flag (PyObject *field, const char *flag_name)
static struct type * static struct type *
get_field_type (PyObject *field) get_field_type (PyObject *field)
{ {
gdbpy_ref ftype_obj (PyObject_GetAttrString (field, "type")); gdbpy_ref<> ftype_obj (PyObject_GetAttrString (field, "type"));
struct type *ftype; struct type *ftype;
if (ftype_obj == NULL) if (ftype_obj == NULL)
@ -687,7 +687,7 @@ valpy_getitem (PyObject *self, PyObject *key)
} }
else else
{ {
gdbpy_ref name_obj (PyObject_GetAttrString (key, "name")); gdbpy_ref<> name_obj (PyObject_GetAttrString (key, "name"));
if (name_obj == NULL) if (name_obj == NULL)
return NULL; return NULL;
@ -708,7 +708,7 @@ valpy_getitem (PyObject *self, PyObject *key)
return NULL; return NULL;
} }
gdbpy_ref bitpos_obj (PyObject_GetAttrString (key, "bitpos")); gdbpy_ref<> bitpos_obj (PyObject_GetAttrString (key, "bitpos"));
if (bitpos_obj == NULL) if (bitpos_obj == NULL)
return NULL; return NULL;
if (!gdb_py_int_as_long (bitpos_obj.get (), &bitpos)) if (!gdb_py_int_as_long (bitpos_obj.get (), &bitpos))
@ -1576,7 +1576,7 @@ convert_value_from_python (PyObject *obj)
PyObject *etype, *evalue, *etraceback; PyObject *etype, *evalue, *etraceback;
PyErr_Fetch (&etype, &evalue, &etraceback); PyErr_Fetch (&etype, &evalue, &etraceback);
gdbpy_ref zero (PyInt_FromLong (0)); gdbpy_ref<> zero (PyInt_FromLong (0));
/* Check whether obj is positive. */ /* Check whether obj is positive. */
if (PyObject_RichCompareBool (obj, zero.get (), Py_GT) > 0) if (PyObject_RichCompareBool (obj, zero.get (), Py_GT) > 0)

View file

@ -59,7 +59,7 @@ py_varobj_iter_next (struct varobj_iter *self)
gdbpy_enter_varobj enter_py (self->var); gdbpy_enter_varobj enter_py (self->var);
gdbpy_ref item (PyIter_Next (t->iter)); gdbpy_ref<> item (PyIter_Next (t->iter));
if (item == NULL) if (item == NULL)
{ {
@ -170,7 +170,7 @@ py_varobj_get_iterator (struct varobj *var, PyObject *printer)
if (!PyObject_HasAttr (printer, gdbpy_children_cst)) if (!PyObject_HasAttr (printer, gdbpy_children_cst))
return NULL; return NULL;
gdbpy_ref children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, gdbpy_ref<> children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
NULL)); NULL));
if (children == NULL) if (children == NULL)
{ {

View file

@ -96,7 +96,7 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
{ {
int enabled; int enabled;
gdbpy_ref enabled_field (PyObject_GetAttrString (matcher, gdbpy_ref<> enabled_field (PyObject_GetAttrString (matcher,
enabled_field_name)); enabled_field_name));
if (enabled_field == NULL) if (enabled_field == NULL)
return NULL; return NULL;
@ -110,11 +110,12 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
Py_RETURN_NONE; Py_RETURN_NONE;
} }
gdbpy_ref 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; return NULL;
gdbpy_ref 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; return NULL;
@ -139,7 +140,7 @@ gdbpy_get_matching_xmethod_workers
gdbpy_enter enter_py (get_current_arch (), current_language); gdbpy_enter enter_py (get_current_arch (), current_language);
gdbpy_ref py_type (type_to_type_object (obj_type)); gdbpy_ref<> py_type (type_to_type_object (obj_type));
if (py_type == NULL) if (py_type == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -147,7 +148,7 @@ gdbpy_get_matching_xmethod_workers
} }
/* Create an empty list of debug methods. */ /* Create an empty list of debug methods. */
gdbpy_ref py_xmethod_matcher_list (PyList_New (0)); gdbpy_ref<> py_xmethod_matcher_list (PyList_New (0));
if (py_xmethod_matcher_list == NULL) if (py_xmethod_matcher_list == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -167,8 +168,8 @@ gdbpy_get_matching_xmethod_workers
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref objfile_matchers (objfpy_get_xmethods (py_objfile, NULL)); gdbpy_ref<> objfile_matchers (objfpy_get_xmethods (py_objfile, NULL));
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (), gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
objfile_matchers.get ())); objfile_matchers.get ()));
if (temp == NULL) if (temp == NULL)
{ {
@ -184,9 +185,9 @@ gdbpy_get_matching_xmethod_workers
py_progspace = pspace_to_pspace_object (current_program_space); py_progspace = pspace_to_pspace_object (current_program_space);
if (py_progspace != NULL) if (py_progspace != NULL)
{ {
gdbpy_ref pspace_matchers (pspy_get_xmethods (py_progspace, NULL)); gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace, NULL));
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (), gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
pspace_matchers.get ())); pspace_matchers.get ()));
if (temp == NULL) if (temp == NULL)
{ {
@ -206,11 +207,11 @@ gdbpy_get_matching_xmethod_workers
if (gdb_python_module != NULL if (gdb_python_module != NULL
&& PyObject_HasAttrString (gdb_python_module, matchers_attr_str)) && PyObject_HasAttrString (gdb_python_module, matchers_attr_str))
{ {
gdbpy_ref gdb_matchers (PyObject_GetAttrString (gdb_python_module, gdbpy_ref<> gdb_matchers (PyObject_GetAttrString (gdb_python_module,
matchers_attr_str)); matchers_attr_str));
if (gdb_matchers != NULL) if (gdb_matchers != NULL)
{ {
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (), gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
gdb_matchers.get ())); gdb_matchers.get ()));
if (temp == NULL) if (temp == NULL)
{ {
@ -227,7 +228,7 @@ gdbpy_get_matching_xmethod_workers
} }
} }
gdbpy_ref list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ())); gdbpy_ref<> list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ()));
if (list_iter == NULL) if (list_iter == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -235,7 +236,7 @@ gdbpy_get_matching_xmethod_workers
} }
while (true) while (true)
{ {
gdbpy_ref matcher (PyIter_Next (list_iter.get ())); gdbpy_ref<> matcher (PyIter_Next (list_iter.get ()));
if (matcher == NULL) if (matcher == NULL)
{ {
if (PyErr_Occurred ()) if (PyErr_Occurred ())
@ -246,7 +247,7 @@ gdbpy_get_matching_xmethod_workers
break; break;
} }
gdbpy_ref match_result (invoke_match_method (matcher.get (), gdbpy_ref<> match_result (invoke_match_method (matcher.get (),
py_type.get (), py_type.get (),
method_name)); method_name));
@ -259,7 +260,7 @@ gdbpy_get_matching_xmethod_workers
; /* This means there was no match. */ ; /* This means there was no match. */
else if (PySequence_Check (match_result.get ())) else if (PySequence_Check (match_result.get ()))
{ {
gdbpy_ref iter (PyObject_GetIter (match_result.get ())); gdbpy_ref<> iter (PyObject_GetIter (match_result.get ()));
if (iter == NULL) if (iter == NULL)
{ {
@ -270,7 +271,7 @@ gdbpy_get_matching_xmethod_workers
{ {
struct xmethod_worker *worker; struct xmethod_worker *worker;
gdbpy_ref py_worker (PyIter_Next (iter.get ())); gdbpy_ref<> py_worker (PyIter_Next (iter.get ()));
if (py_worker == NULL) if (py_worker == NULL)
{ {
if (PyErr_Occurred ()) if (PyErr_Occurred ())
@ -316,13 +317,13 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
PyObject *py_worker = worker_data->worker; PyObject *py_worker = worker_data->worker;
struct type *obj_type; struct type *obj_type;
int i = 1, arg_count; int i = 1, arg_count;
gdbpy_ref list_iter; gdbpy_ref<> list_iter;
/* Set nargs to -1 so that any premature return from this function returns /* Set nargs to -1 so that any premature return from this function returns
an invalid/unusable number of arg types. */ an invalid/unusable number of arg types. */
*nargs = -1; *nargs = -1;
gdbpy_ref get_arg_types_method gdbpy_ref<> get_arg_types_method
(PyObject_GetAttrString (py_worker, get_arg_types_method_name)); (PyObject_GetAttrString (py_worker, get_arg_types_method_name));
if (get_arg_types_method == NULL) if (get_arg_types_method == NULL)
{ {
@ -330,7 +331,7 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref py_argtype_list gdbpy_ref<> py_argtype_list
(PyObject_CallMethodObjArgs (py_worker, py_get_arg_types_method_name, (PyObject_CallMethodObjArgs (py_worker, py_get_arg_types_method_name,
NULL)); NULL));
if (py_argtype_list == NULL) if (py_argtype_list == NULL)
@ -368,7 +369,7 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
{ {
while (true) while (true)
{ {
gdbpy_ref item (PyIter_Next (list_iter.get ())); gdbpy_ref<> item (PyIter_Next (list_iter.get ()));
if (item == NULL) if (item == NULL)
{ {
if (PyErr_Occurred ()) if (PyErr_Occurred ())
@ -445,7 +446,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
/* First see if there is a get_result_type method. /* First see if there is a get_result_type method.
If not this could be an old xmethod (pre 7.9.1). */ If not this could be an old xmethod (pre 7.9.1). */
gdbpy_ref get_result_type_method gdbpy_ref<> get_result_type_method
(PyObject_GetAttrString (py_worker, get_result_type_method_name)); (PyObject_GetAttrString (py_worker, get_result_type_method_name));
if (get_result_type_method == NULL) if (get_result_type_method == NULL)
{ {
@ -475,14 +476,14 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
if (!types_equal (obj_type, this_type)) if (!types_equal (obj_type, this_type))
obj = value_cast (this_type, obj); obj = value_cast (this_type, obj);
} }
gdbpy_ref py_value_obj (value_to_value_object (obj)); gdbpy_ref<> py_value_obj (value_to_value_object (obj));
if (py_value_obj == NULL) if (py_value_obj == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref py_arg_tuple (PyTuple_New (nargs + 1)); gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
if (py_arg_tuple == NULL) if (py_arg_tuple == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -505,7 +506,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg); PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
} }
gdbpy_ref py_result_type gdbpy_ref<> py_result_type
(PyObject_CallObject (get_result_type_method.get (), py_arg_tuple.get ())); (PyObject_CallObject (get_result_type_method.get (), py_arg_tuple.get ()));
if (py_result_type == NULL) if (py_result_type == NULL)
{ {
@ -563,14 +564,14 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
if (!types_equal (obj_type, this_type)) if (!types_equal (obj_type, this_type))
obj = value_cast (this_type, obj); obj = value_cast (this_type, obj);
} }
gdbpy_ref py_value_obj (value_to_value_object (obj)); gdbpy_ref<> py_value_obj (value_to_value_object (obj));
if (py_value_obj == NULL) if (py_value_obj == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
error (_("Error while executing Python code.")); error (_("Error while executing Python code."));
} }
gdbpy_ref py_arg_tuple (PyTuple_New (nargs + 1)); gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
if (py_arg_tuple == NULL) if (py_arg_tuple == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -594,7 +595,7 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg); PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
} }
gdbpy_ref py_result (PyObject_CallObject (xmethod_worker, gdbpy_ref<> py_result (PyObject_CallObject (xmethod_worker,
py_arg_tuple.get ())); py_arg_tuple.get ()));
if (py_result == NULL) if (py_result == NULL)
{ {

View file

@ -273,7 +273,7 @@ eval_python_command (const char *command)
d = PyModule_GetDict (m); d = PyModule_GetDict (m);
if (d == NULL) if (d == NULL)
return -1; return -1;
gdbpy_ref v (PyRun_StringFlags (command, Py_single_input, d, d, NULL)); gdbpy_ref<> v (PyRun_StringFlags (command, Py_single_input, d, d, NULL));
if (v == NULL) if (v == NULL)
return -1; return -1;
@ -351,7 +351,7 @@ python_run_simple_file (FILE *file, const char *filename)
/* Because we have a string for a filename, and are using Python to /* Because we have a string for a filename, and are using Python to
open the file, we need to expand any tilde in the path first. */ open the file, we need to expand any tilde in the path first. */
gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename)); gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
gdbpy_ref python_file (PyFile_FromString (full_path.get (), "r")); gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), "r"));
if (python_file == NULL) if (python_file == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
@ -669,8 +669,8 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
struct symtab_and_line sal; struct symtab_and_line sal;
char *arg = NULL; char *arg = NULL;
struct cleanup *cleanups; struct cleanup *cleanups;
gdbpy_ref result; gdbpy_ref<> result;
gdbpy_ref unparsed; gdbpy_ref<> unparsed;
struct event_location *location = NULL; struct event_location *location = NULL;
if (! PyArg_ParseTuple (args, "|s", &arg)) if (! PyArg_ParseTuple (args, "|s", &arg))
@ -745,7 +745,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
Py_INCREF (Py_None); Py_INCREF (Py_None);
} }
gdbpy_ref return_result (PyTuple_New (2)); gdbpy_ref<> return_result (PyTuple_New (2));
if (return_result == NULL) if (return_result == NULL)
{ {
do_cleanups (cleanups); do_cleanups (cleanups);
@ -897,7 +897,7 @@ gdbpy_run_events (int error, gdb_client_data client_data)
gdbpy_event_list_end = &gdbpy_event_list; gdbpy_event_list_end = &gdbpy_event_list;
/* Ignore errors. */ /* Ignore errors. */
gdbpy_ref call_result (PyObject_CallObject (item->event, NULL)); gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL));
if (call_result == NULL) if (call_result == NULL)
PyErr_Clear (); PyErr_Clear ();
@ -972,7 +972,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
if (gdb_python_module if (gdb_python_module
&& PyObject_HasAttrString (gdb_python_module, "prompt_hook")) && PyObject_HasAttrString (gdb_python_module, "prompt_hook"))
{ {
gdbpy_ref hook (PyObject_GetAttrString (gdb_python_module, gdbpy_ref<> hook (PyObject_GetAttrString (gdb_python_module,
"prompt_hook")); "prompt_hook"));
if (hook == NULL) if (hook == NULL)
{ {
@ -982,15 +982,15 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
if (PyCallable_Check (hook.get ())) if (PyCallable_Check (hook.get ()))
{ {
gdbpy_ref current_prompt (PyString_FromString (current_gdb_prompt)); gdbpy_ref<> current_prompt (PyString_FromString (current_gdb_prompt));
if (current_prompt == NULL) if (current_prompt == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref result (PyObject_CallFunctionObjArgs (hook.get (), gdbpy_ref<> result
current_prompt.get (), (PyObject_CallFunctionObjArgs (hook.get (), current_prompt.get (),
NULL)); NULL));
if (result == NULL) if (result == NULL)
{ {
@ -1206,7 +1206,7 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
{ {
struct program_space *ps; struct program_space *ps;
gdbpy_ref list (PyList_New (0)); gdbpy_ref<> list (PyList_New (0));
if (list == NULL) if (list == NULL)
return NULL; return NULL;
@ -1296,7 +1296,7 @@ gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
{ {
struct objfile *objf; struct objfile *objf;
gdbpy_ref list (PyList_New (0)); gdbpy_ref<> list (PyList_New (0));
if (list == NULL) if (list == NULL)
return NULL; return NULL;
@ -1327,14 +1327,14 @@ gdbpy_start_type_printers (const struct extension_language_defn *extlang,
gdbpy_enter enter_py (get_current_arch (), current_language); gdbpy_enter enter_py (get_current_arch (), current_language);
gdbpy_ref type_module (PyImport_ImportModule ("gdb.types")); gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
if (type_module == NULL) if (type_module == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
return; return;
} }
gdbpy_ref func (PyObject_GetAttrString (type_module.get (), gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
"get_type_recognizers")); "get_type_recognizers"));
if (func == NULL) if (func == NULL)
{ {
@ -1372,21 +1372,21 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang,
gdbpy_enter enter_py (get_current_arch (), current_language); gdbpy_enter enter_py (get_current_arch (), current_language);
gdbpy_ref type_obj (type_to_type_object (type)); gdbpy_ref<> type_obj (type_to_type_object (type));
if (type_obj == NULL) if (type_obj == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref type_module (PyImport_ImportModule ("gdb.types")); gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
if (type_module == NULL) if (type_module == NULL)
{ {
gdbpy_print_stack (); gdbpy_print_stack ();
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref func (PyObject_GetAttrString (type_module.get (), gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
"apply_type_recognizers")); "apply_type_recognizers"));
if (func == NULL) if (func == NULL)
{ {
@ -1394,7 +1394,8 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang,
return EXT_LANG_RC_ERROR; return EXT_LANG_RC_ERROR;
} }
gdbpy_ref result_obj (PyObject_CallFunctionObjArgs (func.get (), printers_obj, gdbpy_ref<> result_obj (PyObject_CallFunctionObjArgs (func.get (),
printers_obj,
type_obj.get (), type_obj.get (),
(char *) NULL)); (char *) NULL));
if (result_obj == NULL) if (result_obj == NULL)
@ -1798,7 +1799,7 @@ do_finish_initialization (const struct extension_language_defn *extlang)
} }
if (sys_path && PyList_Check (sys_path)) if (sys_path && PyList_Check (sys_path))
{ {
gdbpy_ref pythondir (PyString_FromString (gdb_pythondir.c_str ())); gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ()));
if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ())) if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
return false; return false;
} }

View file

@ -1478,10 +1478,10 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
gdbpy_enter_varobj enter_py (var); gdbpy_enter_varobj enter_py (var);
mainmod = PyImport_AddModule ("__main__"); mainmod = PyImport_AddModule ("__main__");
gdbpy_ref globals (PyModule_GetDict (mainmod)); gdbpy_ref<> globals (PyModule_GetDict (mainmod));
Py_INCREF (globals.get ()); Py_INCREF (globals.get ());
gdbpy_ref constructor (PyRun_String (visualizer, Py_eval_input, gdbpy_ref<> constructor (PyRun_String (visualizer, Py_eval_input,
globals.get (), globals.get ())); globals.get (), globals.get ()));
if (constructor == NULL) if (constructor == NULL)
@ -2432,7 +2432,7 @@ varobj_value_get_print_value (struct value *value,
{ {
struct value *replacement; struct value *replacement;
gdbpy_ref output (apply_varobj_pretty_printer (value_formatter, gdbpy_ref<> output (apply_varobj_pretty_printer (value_formatter,
&replacement, &replacement,
&stb)); &stb));