From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16419 invoked by alias); 13 Apr 2009 20:52:29 -0000 Received: (qmail 16410 invoked by uid 22791); 13 Apr 2009 20:52:27 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 13 Apr 2009 20:52:22 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3DKqKPc031564 for ; Mon, 13 Apr 2009 16:52:20 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3DKqJEd024744; Mon, 13 Apr 2009 16:52:19 -0400 Received: from opsy.redhat.com (vpn-13-0.rdu.redhat.com [10.11.13.0]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3DKqIEd030852; Mon, 13 Apr 2009 16:52:18 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 93DF350830B; Mon, 13 Apr 2009 14:52:17 -0600 (MDT) To: gdb-patches@sourceware.org Subject: FYI: fix buglet in Frame comparison function From: Tom Tromey Reply-To: Tom Tromey Date: Mon, 13 Apr 2009 20:52:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00241.txt.bz2 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 * 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"