From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 851093858438; Tue, 23 May 2023 19:47:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 851093858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684871247; bh=ovm7/XeBf4zeHyiD2haGYnoO5ZUASQC5qZpAxoBpahc=; h=From:To:Subject:Date:From; b=NzgMwzZXHoQnLBVrBymu/BDvtdIiB1Rjl1OxI2feUjyzX/57aCNAlZmnIPnpMpEMt B9tYkVQzzfJ9gifxO26Ud5us1ToNHGBLTSnQf2c8aD7VVI+r0zXw21tPTDHX/kaQSd 7P/0DIWPvwuEO83yXWBuu/ydgkP0ohXSqYFCnnPQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use field_signed from Python MI commands X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 6aebb6e100fb3c5e2acf19f8b0432b3b4fd750e0 X-Git-Newrev: d5ad08d77c92e50f24798f357dd688b9060c6f68 Message-Id: <20230523194727.851093858438@sourceware.org> Date: Tue, 23 May 2023 19:47:27 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd5ad08d77c92= e50f24798f357dd688b9060c6f68 commit d5ad08d77c92e50f24798f357dd688b9060c6f68 Author: Tom Tromey Date: Thu Mar 23 11:54:46 2023 -0600 Use field_signed from Python MI commands =20 If an MI command written in Python includes a number in its output, currently that is simply emitted as a string. However, it's convenient for a later patch if these are emitted using field_signed. This does not make a difference to ordinary MI clients. Diff: --- gdb/python/py-micmd.c | 15 +++++++++++++++ gdb/python/python-internal.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index e86807d049f..d7d95918cb4 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -293,6 +293,21 @@ serialize_mi_result_1 (PyObject *result, const char *f= ield_name) } else { + if (PyLong_Check (result)) + { + int overflow =3D 0; + gdb_py_longest val =3D gdb_py_long_as_long_and_overflow (result, + &overflow); + if (PyErr_Occurred () !=3D nullptr) + gdbpy_handle_exception (); + if (overflow =3D=3D 0) + { + uiout->field_signed (field_name, val); + return; + } + /* Fall through to the string case on overflow. */ + } + gdb::unique_xmalloc_ptr string (gdbpy_obj_to_string (result)); if (string =3D=3D nullptr) gdbpy_handle_exception (); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index dbd33570a78..1142e0e739d 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -110,6 +110,7 @@ typedef PY_LONG_LONG gdb_py_longest; typedef unsigned PY_LONG_LONG gdb_py_ulongest; #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong +#define gdb_py_long_as_long_and_overflow PyLong_AsLongLongAndOverflow =20 #else /* HAVE_LONG_LONG */ =20 @@ -118,6 +119,7 @@ typedef unsigned PY_LONG_LONG gdb_py_ulongest; typedef long gdb_py_longest; typedef unsigned long gdb_py_ulongest; #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong +#define gdb_py_long_as_long_and_overflow PyLong_AsLongAndOverflow =20 #endif /* HAVE_LONG_LONG */