From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 01/13] Use gdbpy_ref in archpy_disassemble
Date: Sun, 20 Nov 2016 20:41:00 -0000 [thread overview]
Message-ID: <1479674496-14000-2-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1479674496-14000-1-git-send-email-tom@tromey.com>
This changes archpy_disassemble to use gdbpy_ref. It also fixes a
latent bug where archpy_disassemble was decref'ing the results of a
all to PyArg_ParseTupleAndKeywords. This is incorrect because
PyArg_ParseTupleAndKeywords returns borrowed references.
2016-11-20 Tom Tromey <tom@tromey.com>
* python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't
decref results of PyArg_ParseTupleAndKeywords.
---
gdb/ChangeLog | 5 +++++
gdb/python/py-arch.c | 29 +++++++++--------------------
2 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 49c226b..527053f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-20 Tom Tromey <tom@tromey.com>
+
+ * python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't
+ decref results of PyArg_ParseTupleAndKeywords.
+
2016-11-12 Tom Tromey <tom@tromey.com>
* python/python.c (python_run_simple_file): Use
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 60cc5a9..216a668 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -22,6 +22,7 @@
#include "arch-utils.h"
#include "disasm.h"
#include "python-internal.h"
+#include "py-ref.h"
typedef struct arch_object_type_object {
PyObject_HEAD
@@ -120,7 +121,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
CORE_ADDR pc;
gdb_py_ulongest start_temp;
long count = 0, i;
- PyObject *result_list, *end_obj = NULL, *count_obj = NULL;
+ PyObject *end_obj = NULL, *count_obj = NULL;
struct gdbarch *gdbarch = NULL;
ARCHPY_REQUIRE_VALID (self, gdbarch);
@@ -149,8 +150,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
#endif
else
{
- Py_DECREF (end_obj);
- Py_XDECREF (count_obj);
PyErr_SetString (PyExc_TypeError,
_("Argument 'end_pc' should be a (long) integer."));
@@ -159,8 +158,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
if (end < start)
{
- Py_DECREF (end_obj);
- Py_XDECREF (count_obj);
PyErr_SetString (PyExc_ValueError,
_("Argument 'end_pc' should be greater than or "
"equal to the argument 'start_pc'."));
@@ -173,8 +170,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
count = PyInt_AsLong (count_obj);
if (PyErr_Occurred () || count < 0)
{
- Py_DECREF (count_obj);
- Py_XDECREF (end_obj);
PyErr_SetString (PyExc_TypeError,
_("Argument 'count' should be an non-negative "
"integer."));
@@ -183,7 +178,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
}
}
- result_list = PyList_New (0);
+ gdbpy_ref result_list (PyList_New (0));
if (result_list == NULL)
return NULL;
@@ -199,19 +194,16 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
{
int insn_len = 0;
struct ui_file *memfile = mem_fileopen ();
- PyObject *insn_dict = PyDict_New ();
+ gdbpy_ref insn_dict (PyDict_New ());
if (insn_dict == NULL)
{
- Py_DECREF (result_list);
ui_file_delete (memfile);
return NULL;
}
- if (PyList_Append (result_list, insn_dict))
+ if (PyList_Append (result_list.get (), insn_dict.get ()))
{
- Py_DECREF (result_list);
- Py_DECREF (insn_dict);
ui_file_delete (memfile);
return NULL; /* PyList_Append Sets the exception. */
@@ -223,7 +215,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
}
CATCH (except, RETURN_MASK_ALL)
{
- Py_DECREF (result_list);
ui_file_delete (memfile);
gdbpy_convert_exception (except);
@@ -233,17 +224,15 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
std::string as = ui_file_as_string (memfile);
- if (PyDict_SetItemString (insn_dict, "addr",
+ if (PyDict_SetItemString (insn_dict.get (), "addr",
gdb_py_long_from_ulongest (pc))
- || PyDict_SetItemString (insn_dict, "asm",
+ || PyDict_SetItemString (insn_dict.get (), "asm",
PyString_FromString (!as.empty ()
? as.c_str ()
: "<unknown>"))
- || PyDict_SetItemString (insn_dict, "length",
+ || PyDict_SetItemString (insn_dict.get (), "length",
PyInt_FromLong (insn_len)))
{
- Py_DECREF (result_list);
-
ui_file_delete (memfile);
return NULL;
@@ -254,7 +243,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
ui_file_delete (memfile);
}
- return result_list;
+ return result_list.release ();
}
/* Initializes the Architecture class in the gdb module. */
--
2.7.4
next prev parent reply other threads:[~2016-11-20 20:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-20 20:42 [RFA 00/13] series #4 of c++ in python Tom Tromey
2016-11-20 20:41 ` [RFA 06/13] Use gdbpy_ref in py-inferior.c Tom Tromey
2016-11-20 20:41 ` Tom Tromey [this message]
2016-11-20 20:41 ` [RFA 02/13] Use gdbpy_ref in gdbpy_breakpoint_cond_says_stop Tom Tromey
2016-11-20 20:41 ` [RFA 05/13] Use gdbpy_ref in py_print_frame Tom Tromey
2016-11-20 20:42 ` [RFA 10/13] Use gdbpy_ref in py-utils.c Tom Tromey
2016-11-20 20:42 ` [RFA 03/13] Use gdbpy_ref in py-cmd.c Tom Tromey
2016-11-21 22:46 ` Tom Tromey
2016-11-20 20:42 ` [RFA 09/13] Use gdbpy_ref in pyuw_object_attribute_to_pointer Tom Tromey
2016-11-20 20:42 ` [RFA 12/13] Use gdbpy_ref rather than make_cleanup_py_decref Tom Tromey
2016-11-20 20:42 ` [RFA 13/13] Remove make_cleanup_py_decref and make_cleanup_py_xdecref Tom Tromey
2016-11-22 17:27 ` Pedro Alves
2016-11-20 20:42 ` [RFA 08/13] Use gdbpy_ref in python.c Tom Tromey
2016-11-22 17:21 ` Pedro Alves
2016-11-28 23:08 ` Tom Tromey
2016-11-20 20:42 ` [RFA 07/13] Use gdbpy_ref in py-param.c Tom Tromey
2016-11-20 20:42 ` [RFA 04/13] Use gdbpy_ref in bpfinishpy_out_of_scope Tom Tromey
2016-11-20 20:48 ` [RFA 11/13] Use gdbpy_ref in enumerate_args Tom Tromey
2016-11-21 22:44 ` [RFA 00/13] series #4 of c++ in python Tom Tromey
2016-11-22 17:28 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1479674496-14000-2-git-send-email-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox