From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20704 invoked by alias); 16 Oct 2008 03:55:15 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 20678 invoked by uid 9723); 16 Oct 2008 03:55:14 -0000 Date: Thu, 16 Oct 2008 03:55:00 -0000 Message-ID: <20081016035514.20663.qmail@sourceware.org> From: bauermann@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: Fixes from Daniel\'s review of the gdb.Value patch. X-Git-Refname: refs/heads/archer-tromey-python X-Git-Reftype: branch X-Git-Oldrev: e88aa252e2fc7d031aa0b331de4bd89ed8f35932 X-Git-Newrev: 47283acef2d3db522e74f305e750d66f4eea15f6 X-SW-Source: 2008-q4/txt/msg00003.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via 47283acef2d3db522e74f305e750d66f4eea15f6 (commit) from e88aa252e2fc7d031aa0b331de4bd89ed8f35932 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 47283acef2d3db522e74f305e750d66f4eea15f6 Author: Thiago Jung Bauermann Date: Thu Oct 16 00:29:57 2008 -0300 Fixes from Daniel\'s review of the gdb.Value patch. ----------------------------------------------------------------------- Summary of changes: gdb/doc/gdb.texinfo | 2 +- gdb/python/python-value.c | 89 +++++++++-------------------- gdb/testsuite/gdb.python/python-value.exp | 8 +- 3 files changed, 33 insertions(+), 66 deletions(-) First 500 lines of diff: diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f881b0a..d01f4e7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17815,7 +17815,7 @@ for its internal bookkeeping of the inferior's values, and for fetching values when necessary. Inferior values that are simple scalars can be used directly in -Python expressions that are valid for the value's data type Here's +Python expressions that are valid for the value's data type. Here's an example for an integer or floating-point value @code{some_val}: @smallexample diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index 02c3fec..e78a4b6 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -369,113 +369,80 @@ enum valpy_opcode #define STRIP_REFERENCE(TYPE) \ ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE)) -/* Returns a value object which is the sum of this value with the given - integer argument. */ +/* Returns a value object which is the result of applying the operation + specified by OPCODE to the given arguments. */ static PyObject * valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other) { - long l; - double d; struct value *res_val = NULL; /* Initialize to appease gcc warning. */ - struct value *other_val; - value_object *self_value; volatile struct gdb_exception except; - /* If the gdb.Value object is the second operand, then it will be passed - to us as the OTHER argument, and SELF will be an entirely different - kind of object, altogether. Swap them to avoid surprises. */ - if (!PyObject_TypeCheck (self, &value_object_type)) - { - PyObject *tmp; - - tmp = self; - self = other; - other = tmp; - } - - self_value = (value_object *) self; - - if (PyObject_TypeCheck (other, &value_object_type)) - other_val = ((value_object *) other)->value; - else if (PyInt_Check (other)) - { - l = PyInt_AsLong (other); - if (PyErr_Occurred ()) - return Py_NotImplemented; - - other_val = value_from_longest (builtin_type_pyint, l); - } - else if (PyFloat_Check (other)) + TRY_CATCH (except, RETURN_MASK_ALL) { - d = PyFloat_AsDouble (other); - if (PyErr_Occurred ()) - return Py_NotImplemented; + struct value *arg1, *arg2; - other_val = value_from_double (builtin_type_pyfloat, d); - } - else - /* If the types cannot be added, Python documentation says to return - NotImplemented (http://docs.python.org/ref/numeric-types.html). */ - return Py_NotImplemented; + /* If the gdb.Value object is the second operand, then it will be passed + to us as the OTHER argument, and SELF will be an entirely different + kind of object, altogether. Because of this, we can't assume self is + a gdb.Value object and need to convert it from python as well. */ + arg1 = convert_value_from_python (self); + arg2 = convert_value_from_python (other); - TRY_CATCH (except, RETURN_MASK_ALL) - { switch (opcode) { case VALPY_ADD: { - struct type *ltype = value_type (self_value->value); - struct type *rtype = value_type (other_val); + struct type *ltype = value_type (arg1); + struct type *rtype = value_type (arg2); + CHECK_TYPEDEF (ltype); ltype = STRIP_REFERENCE (ltype); CHECK_TYPEDEF (rtype); rtype = STRIP_REFERENCE (rtype); if (TYPE_CODE (ltype) == TYPE_CODE_PTR) - res_val = value_ptradd (self_value->value, other_val); + res_val = value_ptradd (arg1, arg2); else if (TYPE_CODE (rtype) == TYPE_CODE_PTR) - res_val = value_ptradd (other_val, self_value->value); + res_val = value_ptradd (arg2, arg1); else - res_val = value_binop (self_value->value, other_val, BINOP_ADD); + res_val = value_binop (arg1, arg2, BINOP_ADD); } break; case VALPY_SUB: { - struct type *ltype = value_type (self_value->value); - struct type *rtype = value_type (other_val); + struct type *ltype = value_type (arg1); + struct type *rtype = value_type (arg2); + CHECK_TYPEDEF (ltype); ltype = STRIP_REFERENCE (ltype); CHECK_TYPEDEF (rtype); rtype = STRIP_REFERENCE (rtype); + if (TYPE_CODE (ltype) == TYPE_CODE_PTR) { if (TYPE_CODE (rtype) == TYPE_CODE_PTR) - { /* A ptrdiff_t for the target would be preferable here. */ - res_val - = value_from_longest (builtin_type_pyint, - value_ptrdiff (self_value->value, - other_val)); - } + res_val = value_from_longest (builtin_type_pyint, + value_ptrdiff (arg1, arg2)); else - res_val = value_ptrsub (self_value->value, other_val); + res_val = value_ptrsub (arg1, arg2); } else - res_val = value_binop (self_value->value, other_val, BINOP_SUB); + res_val = value_binop (arg1, arg2, BINOP_SUB); } break; case VALPY_MUL: - res_val = value_binop (self_value->value, other_val, BINOP_MUL); + res_val = value_binop (arg1, arg2, BINOP_MUL); break; case VALPY_DIV: - res_val = value_binop (self_value->value, other_val, BINOP_DIV); + res_val = value_binop (arg1, arg2, BINOP_DIV); break; case VALPY_REM: - res_val = value_binop (self_value->value, other_val, BINOP_REM); + res_val = value_binop (arg1, arg2, BINOP_REM); break; case VALPY_POW: - res_val = value_binop (self_value->value, other_val, BINOP_EXP); + res_val = value_binop (arg1, arg2, BINOP_EXP); break; } } diff --git a/gdb/testsuite/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp index b723b9d..7515ab7 100644 --- a/gdb/testsuite/gdb.python/python-value.exp +++ b/gdb/testsuite/gdb.python/python-value.exp @@ -104,11 +104,11 @@ proc test_value_numeric_ops {} { # Test gdb.Value mixed with Python types. - gdb_test "python print 'result = ' + str(i+1)" " = 6" "add integer value with python integer" - gdb_test "python print (i+1).__class__" "" "verify type of mixed integer add result" + gdb_test "python print 'result = ' + str(i-1)" " = 4" "subtract integer value from python integer" + gdb_test "python print (i-1).__class__" "" "verify type of mixed integer subtraction result" gdb_test "python print 'result = ' + str(f+1.5)" " = 2.75" "add double value with python float" - gdb_test "python print 'result = ' + str(1+i)" " = 6" "add python integer with integer value" + gdb_test "python print 'result = ' + str(1-i)" " = -4" "subtract python integer from integer value" gdb_test "python print 'result = ' + str(1.5+f)" " = 2.75" "add python float with double value" # Test pointer arithmethic @@ -126,7 +126,7 @@ proc test_value_numeric_ops {} { # Test some invalid operations. gdb_test_multiple "python print 'result = ' + str(i+'foo')" "catch error in python type conversion" { - -re "unsupported operand type.*$gdb_prompt $" {pass "catch error in python type conversion"} + -re "Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {pass "catch error in python type conversion"} -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"} -re "$gdb_prompt $" {fail "catch error in python type conversion"} } hooks/post-receive -- Repository for Project Archer.