This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Make gdb.selected_thread().inferior return a new reference
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Maksim Dzabraev <dzabraew at gmail dot com>
- Cc: gdb-patches at sourceware dot org, tom at tromey dot com
- Date: Sat, 28 Oct 2017 14:21:19 -0400
- Subject: Re: [PATCH] Make gdb.selected_thread().inferior return a new reference
- Authentication-results: sourceware.org; auth=none
- References: <e37eb1e38a23eef3c48a74f67f7ff3f5@polymtl.ca> <20171028181434.3825-1-dzabraew@gmail.com>
Thanks! I pushed the patch with the following changes:
On 2017-10-28 14:14, Maksim Dzabraev wrote:
thpy_get_inferior function should return a new reference to the
existing inferior object, and therefore should increment its refcount.
Fixed bug lokks like this.
lokks -> looks
If multiple time call gdb.selected_thread ().inferior, gdb throws
exception:
(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
Python Exception <type 'exceptions.AttributeError'> 'NoneType' object
has no attribute 'inferior':
Error while executing Python code.
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7f54f0474740 (LWP 584) "mc" 0x00007f54ef055c33 in
---
gdb/ChangeLog | 6 ++++++
gdb/python/py-infthread.c | 1 +
gdb/testsuite/ChangeLog | 6 ++++++
gdb/testsuite/gdb.python/py-infthread.exp | 9 +++++++++
4 files changed, 22 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9fe632985e..4583a78fe5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-28 Maksim Dzabraev <dzabraew@gmail.com>
+
+ PR python/21213
+ * python/py-infthread.c (thpy_get_inferior): Increment reference
+ of inferior before returning it.
+
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
* unittests/common-utils-selftests.c (format): Add
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 626c15cedb..31d576f7c7 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -162,6 +162,7 @@ thpy_get_inferior (PyObject *self, void *ignore)
thread_object *thread_obj = (thread_object *) self;
THPY_REQUIRE_VALID (thread_obj);
+ Py_INCREF (thread_obj->inf_obj);
return thread_obj->inf_obj;
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0254a28550..72334fd3e2 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-28 Maksim Dzabraev <dzabraew@gmail.com>
Used two spaces between fields.
Simon