From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 4/4] Change Python code to use new_reference
Date: Mon, 30 Apr 2018 04:21:00 -0000 [thread overview]
Message-ID: <20180430042147.28337-5-tom@tromey.com> (raw)
In-Reply-To: <20180430042147.28337-1-tom@tromey.com>
This changes a few spots in the Python code to use new_reference
rather than the manual incref+constructor that was previously being
done.
2018-04-29 Tom Tromey <tom@tromey.com>
* varobj.c (varobj_set_visualizer): Use new_reference.
* python/python.c (gdbpy_decode_line): Use new_reference.
* python/py-cmd.c (cmdpy_function, cmdpy_completer_helper): Use
new_reference.
---
gdb/ChangeLog | 7 +++++++
gdb/python/py-cmd.c | 7 +++----
gdb/python/python.c | 10 ++--------
gdb/varobj.c | 5 ++---
4 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index bff445f62f..27c4689413 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -138,8 +138,8 @@ cmdpy_function (struct cmd_list_element *command,
error (_("Could not convert arguments to Python string."));
}
- gdbpy_ref<> ttyobj (from_tty ? Py_True : Py_False);
- Py_INCREF (ttyobj.get ());
+ gdbpy_ref<> ttyobj
+ = gdbpy_ref<>::new_reference (from_tty ? Py_True : Py_False);
gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
argobj.get (), ttyobj.get (),
NULL));
@@ -246,8 +246,7 @@ cmdpy_completer_helper (struct cmd_list_element *command,
if (word == NULL)
{
/* "brkchars" phase. */
- wordobj.reset (Py_None);
- Py_INCREF (Py_None);
+ wordobj = gdbpy_ref<>::new_reference (Py_None);
}
else
{
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9eae8a1aef..0dd7d6a6ad 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -876,10 +876,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
}
}
else
- {
- result.reset (Py_None);
- Py_INCREF (Py_None);
- }
+ result = gdbpy_ref<>::new_reference (Py_None);
gdbpy_ref<> return_result (PyTuple_New (2));
if (return_result == NULL)
@@ -892,10 +889,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
return NULL;
}
else
- {
- unparsed.reset (Py_None);
- Py_INCREF (Py_None);
- }
+ unparsed = gdbpy_ref<>::new_reference (Py_None);
PyTuple_SetItem (return_result.get (), 0, unparsed.release ());
PyTuple_SetItem (return_result.get (), 1, result.release ());
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 4656bfa6b9..a0df485ae9 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1455,9 +1455,8 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
gdbpy_enter_varobj enter_py (var);
mainmod = PyImport_AddModule ("__main__");
- gdbpy_ref<> globals (PyModule_GetDict (mainmod));
- Py_INCREF (globals.get ());
-
+ gdbpy_ref<> globals
+ = gdbpy_ref<>::new_reference (PyModule_GetDict (mainmod));
gdbpy_ref<> constructor (PyRun_String (visualizer, Py_eval_input,
globals.get (), globals.get ()));
--
2.13.6
next prev parent reply other threads:[~2018-04-30 4:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-30 4:21 [RFA 0/4] add ref_ptr::new_reference Tom Tromey
2018-04-30 4:21 ` [RFA 1/4] Introduce ref_ptr::new_reference Tom Tromey
2018-04-30 4:21 ` [RFA 2/4] Remove new_bfd_ref Tom Tromey
2018-04-30 4:21 ` Tom Tromey [this message]
2018-04-30 13:34 ` [RFA 4/4] Change Python code to use new_reference Phil Muldoon
2018-04-30 4:21 ` [RFA 3/4] Use new_reference for struct value Tom Tromey
2018-04-30 17:05 ` Pedro Alves
2018-04-30 17:32 ` Tom Tromey
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=20180430042147.28337-5-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).