This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch][python] Fix Python 3 long/int logic error when converting a value in GDB
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 18 Sep 2013 09:50:47 +0100
- Subject: [patch][python] Fix Python 3 long/int logic error when converting a value in GDB
- Authentication-results: sourceware.org; auth=none
This patch adjusts a logic error that crept in when we made the
conversion to support Python 3. In Python 3, all integer objects
internally are represented as "long integers". PyInt_Check and others
were aliased in an #ifdef to point to the PyLong equivalents. However
there is a distinction in Python 2.x, and this caused the logic error
when we convert a value from Python. In convert_value_from_python we
check PyInt_Check first. In Python 3, this equates to PyLong_Check
and we make an erroneous conversion using PyInt_AsLong instead of
using PyLong_AsLongLong.
This is obviously wrong as we lose information. The patch switches
the PyInt_Check to occur after the PyLong_Check. This fixes this
issue in Python 3, and conserves existing behavior in Python 2.x.
I audited the code for other checks like this and found these files
use PyInt_Check.
python/py-arch.c
python/py-type.c
python/py-value.c
python/py-param.c
python/py-cmd.c
python/py-breakpoint.c
python/py-breakpoint.c
python/py-breakpoint.c
Of those, the only check that makes a differentiation between a long
and an int is py-arch.c. The order for that check is already correct,
so no change is needed. The other files just do a simple number
check, and those work as intended.
OK?
Cheers,
Phil
2013-09-18 Phil Muldoon <pmuldoon@redhat.com>
* python/py-value.c (convert_value_from_python): Move PyInt_Check
conversion logic to occur after PyLong_Check.
--
PyLong_AsLongLong
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 0d87219..a296a77 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1265,13 +1265,6 @@ convert_value_from_python (PyObject *obj)
if (cmp >= 0)
value = value_from_longest (builtin_type_pybool, cmp);
}
- else if (PyInt_Check (obj))
- {
- long l = PyInt_AsLong (obj);
-
- if (! PyErr_Occurred ())
- value = value_from_longest (builtin_type_pyint, l);
- }
else if (PyLong_Check (obj))
{
LONGEST l = PyLong_AsLongLong (obj);
@@ -1306,6 +1299,13 @@ convert_value_from_python (PyObject *obj)
else
value = value_from_longest (builtin_type_pylong, l);
}
+ else if (PyInt_Check (obj))
+ {
+ long l = PyInt_AsLong (obj);
+
+ if (! PyErr_Occurred ())
+ value = value_from_longest (builtin_type_pyint, l);
+ }
else if (PyFloat_Check (obj))
{
double d = PyFloat_AsDouble (obj);