From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mSDTI5Wy22p10xAAWB0awg (envelope-from ) for ; Fri, 23 Oct 2026 15:16:37 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=ocVrno3/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8DFCE1E033; Fri, 23 Oct 2026 15:16:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 126DE1E007 for ; Fri, 23 Oct 2026 15:16:37 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A7484BA2E15 for ; Fri, 23 Oct 2026 19:16:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A7484BA2E15 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=ocVrno3/ Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 27B384BA2E0B for ; Fri, 23 Oct 2026 19:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27B384BA2E0B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27B384BA2E0B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792782952; cv=none; b=wVWHFDAJvfSWOgczuLugcsCWVSu28AVo0BYY+hxwdv/LWlcJMIwcpqGkD2rBUam/R+LOSQ08fImlTNdpL+RodVWRXP4QtoeShaf9JsEF4CQ3/UIAgczpW1KeST6PF1Oq+C+9iY03sdnayixbgqlktbx936mc20Sq+O8AuI2wAO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792782952; c=relaxed/simple; bh=RhLGFE+g9p8VnjvRiFY+I+Vr5NE2jAm0b3D/HsC++jw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=oOoWoJH4gPT4zNiQ71tMjLPs7mFIylsTUdSE5T4kd8i7kBRzqJrq3+/PNp6hX5p9qhattRgGF0eEtpwMd7GZ1p1HxCY+eJTX0oUxfouBDgdHL27u52O1pyh0Gw/yhy+C3soFwh/36bKlLgAHqzKhyxrk4zfuiRRaZmUdyGXZSZ4= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=ocVrno3/ reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27B384BA2E0B Received: from eig-obgw-6003b.ext.cloudfilter.net ([10.0.30.175]) by cmsmtp with ESMTPS id K4GLxxg6Rc3XsKKk2xEU7b; Fri, 23 Oct 2026 19:15:50 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id KKk2x4GCozvPGKKk2xPsd0; Fri, 23 Oct 2026 19:15:50 +0000 X-Authority-Analysis: v=2.4 cv=Y5f4sgeN c=1 sm=1 tr=0 ts=6adbb266 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=ItBw4LHWJt0A:10 a=Z7ibalmSL9ILCV4CCxIA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WAhGYe2LP2KOoHpGUbWKj30dFuN8AGAKxeIYUm3juqY=; b=ocVrno3/HKzeulBvb5F+zivZFW ES46NRh+xVjIJu1/RCoCVKT3xQJRGdIzbbkbHCWAtEP50xFtrlqu7eTg5MkIYmCmT1meXIIBmscQw 9HMwQIYa7aapH37yfMlqRj2Xr; Received: from 97-122-110-129.hlrn.qwest.net ([97.122.110.129]:59452 helo=[192.168.0.17]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xKKk2-00000000DHL-006g; Fri, 23 Oct 2026 13:15:50 -0600 From: Tom Tromey Date: Fri, 23 Oct 2026 13:15:47 -0600 Subject: [PATCH 2/6] Add safety wrappers for from_{longest,ulongest} MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261023-python-safety-fixmes-v1-2-055b9e1d237b@tromey.com> References: <20261023-python-safety-fixmes-v1-0-055b9e1d237b@tromey.com> In-Reply-To: <20261023-python-safety-fixmes-v1-0-055b9e1d237b@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.110.129 X-Source-L: No X-Exim-ID: 1xKKk2-00000000DHL-006g X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-129.hlrn.qwest.net ([192.168.0.17]) [97.122.110.129]:59452 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfF6cLp0ny65u08glEqDkOOMzgdOPopxDIljMMo9n6yKXC0SuPv2r8g7Ufc/T05wd28LHOa8p7/N12MeBg94x3kEuUR7zOpl5V5l0Kb0ncoxEUYqOmZ2K aGsbxg0OfuqWuCIJO+1r7tT4FBT2CkbbnEQSnaA/ExK9jPvQcKspAbVy6wes4VTTDo5wE/x8yQTY7oyglOzEfvnPNPXb6AgZro4= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This adds a couple of safety wrappers for the APIs that convert from a LONGEST or ULONGEST to Python. This allows the removal of some FIXMEs. --- gdb/python/py-arch.c | 14 ++------------ gdb/python/py-wrappers.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index a6fd12b5ce5..3de1b3c4533 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -198,21 +198,11 @@ arch_object::disassemble (gdbpy_borrowed_ref<> args, string_file stb (styling_p); int insn_len = gdb_print_insn (gdbarch, pc, &stb, NULL); - /* FIXME: Python safety. Eventually gdb_py_object_from_ulongest - should throw. */ - gdbpy_ref<> pc_obj = gdb_py_object_from_ulongest (pc); - if (pc_obj == nullptr) - throw gdb_python_exception (); - + gdbpy_ref<> pc_obj = gdbpy_safe_from_ulongest (pc); gdbpy_ref<> asm_obj = gdbpy_unicode_from_string (!stb.empty () ? stb.c_str () : ""); - - /* FIXME: Python safety. Eventually gdb_py_object_from_longest - should throw. */ - gdbpy_ref<> len_obj = gdb_py_object_from_longest (insn_len); - if (len_obj == nullptr) - throw gdb_python_exception (); + gdbpy_ref<> len_obj = gdbpy_safe_from_longest (insn_len); gdbpy_dict_set_item_string (insn_dict, "addr", pc_obj); gdbpy_dict_set_item_string (insn_dict, "asm", asm_obj); diff --git a/gdb/python/py-wrappers.h b/gdb/python/py-wrappers.h index 2e2d451167a..69295fa6af3 100644 --- a/gdb/python/py-wrappers.h +++ b/gdb/python/py-wrappers.h @@ -384,4 +384,23 @@ gdbpy_get_address (gdbpy_borrowed_ref<> obj) return result; } +/* A wrapper for gdb_py_object_from_longest that throws on error. */ +static inline gdbpy_ref<> +gdbpy_safe_from_longest (LONGEST l) +{ + gdbpy_ref<> result = gdb_py_object_from_longest (l); + if (result == nullptr) + throw gdb_python_exception (); + return result; +} + +/* A wrapper for gdb_py_object_from_ulongest that throws on error. */ +static inline gdbpy_ref<> +gdbpy_safe_from_ulongest (ULONGEST l) +{ + gdbpy_ref<> result = gdb_py_object_from_ulongest (l); + if (result == nullptr) + throw gdb_python_exception (); + return result; +} #endif /* GDB_PYTHON_PY_WRAPPERS_H */ -- 2.49.0