This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: fix PR 10583
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 22 Sep 2009 15:14:25 -0600
- Subject: FYI: fix PR 10583
- Reply-to: Tom Tromey <tromey at redhat dot com>
This fixes PR 10583.
The bug is that the Python __int__ and __long__ methods for Value don't
work properly if the value overflows a C 'long'.
The fix is to use PyLong_FromLongLong when it is available. Two things
to notice here: first, HAVE_LONG_LONG is defined by some Python header
file (yuck) and a Python Long is actually a bigint, while a Python Int
is actually a C long.
Tom
2009-09-22 Tom Tromey <tromey@redhat.com>
PR gdb/10583:
* python/py-value.c (valpy_int): Use PyLong_FromLongLong.
(valpy_long): Likewise.
Index: python/py-value.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-value.c,v
retrieving revision 1.2
diff -u -r1.2 py-value.c
--- python/py-value.c 21 Sep 2009 09:32:27 -0000 1.2
+++ python/py-value.c 22 Sep 2009 21:08:53 -0000
@@ -784,6 +784,13 @@
}
GDB_PY_HANDLE_EXCEPTION (except);
+#ifdef HAVE_LONG_LONG /* Defined by Python. */
+ /* If we have 'long long', and the value overflows a 'long', use a
+ Python Long; otherwise use a Python Int. */
+ if (sizeof (l) > sizeof (long) && (l > PyInt_GetMax ()
+ || l < (- (LONGEST) PyInt_GetMax ()) - 1))
+ return PyLong_FromLongLong (l);
+#endif
return PyInt_FromLong (l);
}
@@ -808,7 +815,11 @@
}
GDB_PY_HANDLE_EXCEPTION (except);
+#ifdef HAVE_LONG_LONG /* Defined by Python. */
+ return PyLong_FromLongLong (l);
+#else
return PyLong_FromLong (l);
+#endif
}
/* Implements conversion to float. */