This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA/Python] Fix int() builtin with range type gdb.Value objects.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 20 Nov 2013 06:47:52 +0400
- Subject: Re: [RFA/Python] Fix int() builtin with range type gdb.Value objects.
- Authentication-results: sourceware.org; auth=none
- References: <1384773267-4883-1-git-send-email-brobecker at adacore dot com> <87r4adpupf dot fsf at fleche dot redhat dot com> <20131119030458 dot GE3481 at adacore dot com> <87zjp0mnuv dot fsf at fleche dot redhat dot com>
> >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
>
> Joel> * python/py-value.c (is_intlike): Delete.
> Joel> (valpy_int): Replace use of CHECK_TYPEDEF and is_intlike
> Joel> by use of is_integral_type.
> Joel> (valpy_long): Replace use of CHECK_TYPEDEF and is_intlike
> Joel> by use of is_integral_type and check for TYPE_CODE_PTR.
>
> Thanks, Joel.
>
> Joel> TRY_CATCH (except, RETURN_MASK_ALL)
> Joel> {
> Joel> - CHECK_TYPEDEF (type);
> Joel> -
> Joel> - if (!is_intlike (type, 1))
> Joel> + if (!is_integral_type (type)
> Joel> + && TYPE_CODE (type) != TYPE_CODE_PTR)
> Joel> error (_("Cannot convert value to long."));
>
> I think the CHECK_TYPEDEF is still needed in this hunk (but not the
> other one), since we examine the TYPE_CODE of the type.
I missed that, you're right! New patch attached.
gdb/ChangeLog:
* python/py-value.c (is_intlike): Delete.
(valpy_int): Replace use of CHECK_TYPEDEF and is_intlike
by use of is_integral_type.
(valpy_long): Replace use of CHECK_TYPEDEF and is_intlike
by use of is_integral_type and check for TYPE_CODE_PTR.
Re-tested on x86_64-linux, JIC.
Thanks!
--
Joel
>From 4ac78121f75057f3e4ccbbd22c57d373ae60bd05 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Tue, 19 Nov 2013 06:56:00 +0400
Subject: [PATCH] get rid of py-value.c:is_intlike (use is_integral_type
instead)
is_intlike was mostly duplicating is_integral_type, with the exception
of the handling of TYPE_CODE_PTR when parameter PTR_OK is nonzero.
This patches deletes the is_intlike function, using is_integral_type
instead, and adjusting the two locations where this function gets
called.
The code should remain strictly equivalent.
gdb/ChangeLog:
* python/py-value.c (is_intlike): Delete.
(valpy_int): Replace use of CHECK_TYPEDEF and is_intlike
by use of is_integral_type.
(valpy_long): Replace use of CHECK_TYPEDEF and is_intlike
by use of is_integral_type and check for TYPE_CODE_PTR.
---
gdb/python/py-value.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 451bfaf..4054808 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1129,18 +1129,6 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
Py_RETURN_FALSE;
}
-/* Helper function to determine if a type is "int-like". */
-static int
-is_intlike (struct type *type, int ptr_ok)
-{
- return (TYPE_CODE (type) == TYPE_CODE_INT
- || TYPE_CODE (type) == TYPE_CODE_ENUM
- || TYPE_CODE (type) == TYPE_CODE_BOOL
- || TYPE_CODE (type) == TYPE_CODE_CHAR
- || TYPE_CODE (type) == TYPE_CODE_RANGE
- || (ptr_ok && TYPE_CODE (type) == TYPE_CODE_PTR));
-}
-
#ifndef IS_PY3K
/* Implements conversion to int. */
static PyObject *
@@ -1153,8 +1141,7 @@ valpy_int (PyObject *self)
TRY_CATCH (except, RETURN_MASK_ALL)
{
- CHECK_TYPEDEF (type);
- if (!is_intlike (type, 0))
+ if (!is_integral_type (type))
error (_("Cannot convert value to int."));
l = value_as_long (value);
@@ -1178,7 +1165,8 @@ valpy_long (PyObject *self)
{
CHECK_TYPEDEF (type);
- if (!is_intlike (type, 1))
+ if (!is_integral_type (type)
+ && TYPE_CODE (type) != TYPE_CODE_PTR)
error (_("Cannot convert value to long."));
l = value_as_long (value);
--
1.8.1.2