From: Doug Evans <dje@google.com>
To: gdb-patches@sourceware.org
Subject: [RFA] fix ref counting of inferior_to_inferior_object
Date: Thu, 12 Sep 2013 22:27:00 -0000 [thread overview]
Message-ID: <yjt2zjrhekva.fsf@ruffy.mtv.corp.google.com> (raw)
Hi.
While adding an inferior attribute to the newobjfile event,
I noticed inferior_to_inferior_object sometimes returns (AFAICT)
a new reference and sometimes returns a borrowed reference.
This patch makes it consistently return a borrowed reference
(for consistency with obfile_to_objfile_object), and then
updates the rest of the code.
Regression tested on amd64-linux.
Ok to check in?
2013-09-12 Doug Evans <dje@google.com>
* python/py-exitedevent.c (create_exited_event_object): Add comment.
* python/py-inferior.c (inferior_to_inferior_object): Always return
a borrowed reference.
(find_inferior_object): Return a new reference to the inferior object.
(build_inferior_list): Update, inferior_to_inferior_object returns
a borrowed reference.
(gdbpy_selected_inferior): Ditto.
Index: python/py-exitedevent.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-exitedevent.c,v
retrieving revision 1.8
diff -u -p -r1.8 py-exitedevent.c
--- python/py-exitedevent.c 20 May 2013 20:09:01 -0000 1.8
+++ python/py-exitedevent.c 12 Sep 2013 22:19:49 -0000
@@ -49,6 +49,8 @@ create_exited_event_object (const LONGES
goto fail;
}
+ /* Note that inferior_to_inferior_object returns a borrowed reference,
+ so we don't need a decref here. */
inf_obj = inferior_to_inferior_object (inf);
if (!inf_obj || evpy_add_attribute (exited_event,
"inferior",
Index: python/py-inferior.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-inferior.c,v
retrieving revision 1.36
diff -u -p -r1.36 py-inferior.c
--- python/py-inferior.c 18 Jun 2013 18:43:27 -0000 1.36
+++ python/py-inferior.c 12 Sep 2013 22:19:50 -0000
@@ -161,8 +161,9 @@ python_new_objfile (struct objfile *objf
/* Return a reference to the Python object of type Inferior
representing INFERIOR. If the object has already been created,
- return it and increment the reference count, otherwise, create it.
+ return it, otherwise create it. The result is a borrowed reference.
Return NULL on failure. */
+
PyObject *
inferior_to_inferior_object (struct inferior *inferior)
{
@@ -180,15 +181,12 @@ inferior_to_inferior_object (struct infe
inf_obj->nthreads = 0;
set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
-
}
- else
- Py_INCREF ((PyObject *)inf_obj);
return (PyObject *) inf_obj;
}
-/* Finds the Python Inferior object for the given PID. Returns a
+/* Finds the Python Inferior object for the given PID. Returns a new
reference, or NULL if PID does not match any inferior object. */
PyObject *
@@ -197,7 +195,12 @@ find_inferior_object (int pid)
struct inferior *inf = find_inferior_pid (pid);
if (inf)
- return inferior_to_inferior_object (inf);
+ {
+ PyObject *inf_obj = inferior_to_inferior_object (inf);
+
+ Py_XINCREF (inf_obj);
+ return inf_obj;
+ }
return NULL;
}
@@ -384,7 +387,6 @@ build_inferior_list (struct inferior *in
return 0;
success = PyList_Append (list, inferior);
- Py_DECREF (inferior);
if (success)
return 1;
@@ -768,12 +770,16 @@ py_free_inferior (struct inferior *inf,
}
/* Implementation of gdb.selected_inferior() -> gdb.Inferior.
- Returns the current inferior object. */
+ Returns a new reference to the current inferior object. */
PyObject *
gdbpy_selected_inferior (PyObject *self, PyObject *args)
{
- return inferior_to_inferior_object (current_inferior ());
+ PyObject *inf_obj;
+
+ inf_obj = inferior_to_inferior_object (current_inferior ());
+ Py_XINCREF (inf_obj);
+ return inf_obj;
}
int
next reply other threads:[~2013-09-12 22:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 22:27 Doug Evans [this message]
2013-09-23 20:41 ` Tom Tromey
2013-09-25 18:18 ` Doug Evans
2013-09-25 18:32 ` Tom Tromey
2013-09-25 19:29 ` Doug Evans
2013-09-25 20:11 ` Tom Tromey
2013-09-25 21:11 ` Doug Evans
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=yjt2zjrhekva.fsf@ruffy.mtv.corp.google.com \
--to=dje@google.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