Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* FYI: fix buglet in Frame comparison function
@ 2009-04-13 20:52 Tom Tromey
  2009-04-13 20:54 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2009-04-13 20:52 UTC (permalink / raw)
  To: gdb-patches

I'm checking this in.

This fixes a bug in the gdb.Frame richcompare function.  The '!='
operator was not handled.  This also fixes the comparison function to
return Py_NotImplemented, as specified in the Python docs.

Built and regtested on x86-64 (compile farm).
A new test case is included.

Tom

2009-04-13  Tom Tromey  <tromey@redhat.com>

	* python/python-frame.c (frapy_richcompare): Return
	Py_NotImplemented, not an error.  Handle Py_NE as well.
	* python/lib/gdb/FrameIterator.py (FrameIterator.next): Use 'is'.

diff --git a/gdb/python/python-frame.c b/gdb/python/python-frame.c
index 8d6127e..a97009f 100644
--- a/gdb/python/python-frame.c
+++ b/gdb/python/python-frame.c
@@ -415,21 +415,23 @@ gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
 static PyObject *
 frapy_richcompare (PyObject *self, PyObject *other, int op)
 {
-  if (!PyObject_TypeCheck (other, &frame_object_type))
-    {
-      PyErr_SetString (PyExc_TypeError, "Frame object expected in comparison.");
-      return NULL;
-    }
-  else if (op != Py_EQ)
+  int result;
+
+  if (!PyObject_TypeCheck (other, &frame_object_type)
+      || (op != Py_EQ && op != Py_NE))
     {
-      PyErr_SetString (PyExc_TypeError, "Invalid comparison for gdb.Frame.");
-      return NULL;
+      Py_INCREF (Py_NotImplemented);
+      return Py_NotImplemented;
     }
 
   if (frame_id_eq (((frame_object *) self)->frame_id,
 		   ((frame_object *) other)->frame_id))
-    Py_RETURN_TRUE;
+    result = Py_EQ;
+  else
+    result = Py_NE;
 
+  if (op == result)
+    Py_RETURN_TRUE;
   Py_RETURN_FALSE;
 }
 
diff --git a/gdb/testsuite/gdb.python/python-frame.exp b/gdb/testsuite/gdb.python/python-frame.exp
index b1ee9be..82b526e 100644
--- a/gdb/testsuite/gdb.python/python-frame.exp
+++ b/gdb/testsuite/gdb.python/python-frame.exp
@@ -70,6 +70,8 @@ gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
 
 gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
 gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
+gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
+gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
 gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
 gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
 gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FYI: fix buglet in Frame comparison function
  2009-04-13 20:52 FYI: fix buglet in Frame comparison function Tom Tromey
@ 2009-04-13 20:54 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2009-04-13 20:54 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> 2009-04-13  Tom Tromey  <tromey@redhat.com>
Tom> 	* python/python-frame.c (frapy_richcompare): Return
Tom> 	Py_NotImplemented, not an error.  Handle Py_NE as well.
Tom> 	* python/lib/gdb/FrameIterator.py (FrameIterator.next): Use 'is'.

Oops, I included the wrong ChangeLog entry.
Here is the correct one.

2009-04-13  Tom Tromey  <tromey@redhat.com>

	* python/python-frame.c (frapy_richcompare): Return
	Py_NotImplemented, not an error.  Handle Py_NE as well.

2009-04-13  Tom Tromey  <tromey@redhat.com>

	* gdb.python/python-frame.exp (gdb_py_test_silent_cmd): Test !=
	operator on Frame.

Tom


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-13 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-13 20:52 FYI: fix buglet in Frame comparison function Tom Tromey
2009-04-13 20:54 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox