fix bug PR 21213 and add test case

Message ID 20170808195554.15778-1-dzabraew@gmail.com
State New, archived
Headers

Commit Message

Максим Дзабраев Aug. 8, 2017, 7:55 p.m. UTC
  ---
 gdb/ChangeLog                             | 5 +++++
 gdb/python/py-infthread.c                 | 1 +
 gdb/testsuite/ChangeLog                   | 5 +++++
 gdb/testsuite/gdb.python/py-infthread.exp | 9 +++++++++
 4 files changed, 20 insertions(+)
  

Comments

Tom Tromey Aug. 9, 2017, 6:33 p.m. UTC | #1
>>>>> "Maksim" == Maksim Dzabraev <dzabraew@gmail.com> writes:

Maksim> +2017-08-09 Maksim Dzabraev <dzabraew@gmail.com>
Maksim> +
Maksim> +	* python/py-infthread.c (thpy_get_inferior): Increment reference
Maksim> +	of inferior before returning it.

If you mention "PR python/21213" in the ChangeLog entry, the commit will
show up in the bug in bugzilla as well.  See the ChangeLog for plenty of
examples of this.

Tom
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c4ad2bf1eb..7c04d4a50e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2017-08-09 Maksim Dzabraev <dzabraew@gmail.com>
+
+	* python/py-infthread.c (thpy_get_inferior): Increment reference
+	of inferior before returning it.
+
 2017-08-07  Maciej W. Rozycki  <macro@imgtec.com>
 
 	PR breakpoints/21886
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 31f419faf5..e8107c39cf 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2017-08-09 Maksim Dzabraev <dzabraew@gmail.com>
+
+	* gdb.python/py-infthread.exp: Test calling
+	InferiorThread.inferior () multiple times in a row.
+
 2017-08-05  Tom Tromey  <tom@tromey.com>
 
 	* gdb.rust/simple.exp: Allow String to appear in a different
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index a5fed8d893..4120ff1ce8 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -39,6 +39,15 @@  if ![runto_main] then {
 
 # Test basic gdb.Inferior attributes and methods.
 
+# Make sure that InferiorThread.inferior returns a new reference (see PR 21213).
+
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 1" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 2" 1
+gdb_test_no_output "python import gc; gc.collect()" "call Python garbage collection"
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 3" 1
+gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 4" 1
+
+
 gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
 gdb_test "python print (t0)" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
 gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num"