From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cRKYDetim2lpsgUAWB0awg (envelope-from ) for ; Sun, 22 Feb 2026 15:11:23 -0500 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=OTLSa5bU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 30D4E1E0BA; Sun, 22 Feb 2026 15:11:23 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 57C7E1E08D for ; Sun, 22 Feb 2026 15:11:22 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E8BC84BA2E15 for ; Sun, 22 Feb 2026 20:11:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8BC84BA2E15 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=OTLSa5bU Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id BF12A4BA23CD for ; Sun, 22 Feb 2026 20:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF12A4BA23CD 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 BF12A4BA23CD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771790906; cv=none; b=DDi92AbF6cK3Vj9elZarSuLdJt9/cwLV8JyLoOR/qHtHtiz1G2NKS7c1poqyOtFr7i0XPntJq39DBbK7TG+up6x5ZNITNOECkx0Da1iPCTD52rrHk7LTrj1AnXfUsLKhS6H/GS9uTCsJaYZYLNG0KZFMdpN4ipyU+gUuqiROcIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771790906; c=relaxed/simple; bh=ThpKPJVm/WNxWwb8+rxbs0+Eh6uQHTjQtPgD3i2W4+I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QMB3OXXKOx/q7ml3XZ7tE62LltUm3mn8eXNS/Hxr5riksP5RyUmp34BNjdQLYog/eyxNNzr7D55A5dAG06xqXp08QhTtE16CoYVjXuRleM4DuRJ3HaPKApi9cpmCSTEsA8AdD/VM1b5/SfY5ErtysauYjO8zfh+HutR7/sKB/2Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF12A4BA23CD Received: from eig-obgw-5006b.ext.cloudfilter.net ([10.0.29.217]) by cmsmtp with ESMTPS id uA0Bv612YipkCuFkTvK23w; Sun, 22 Feb 2026 20:08:13 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id uFkSvgKi5Os9RuFkTvvaaK; Sun, 22 Feb 2026 20:08:13 +0000 X-Authority-Analysis: v=2.4 cv=HPPDFptv c=1 sm=1 tr=0 ts=699b622d a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=HzLeVaNsDn8A:10 a=ItBw4LHWJt0A:10 a=sDm5xJ4nc7WHEI-ys3gA:9 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: To:From:Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CU6nrAeCrYFb0GBgIv+MpFiVCcV4LH++03rPPtOrx4Y=; b=OTLSa5bUyXS4qi9Oc0wP1zRaVO GhvKrO3L4mh0169OmzDALNGHkyG6BNZ2kz5a++FFOs3SBuoMAVVVr9XnIMD0M+jiCstHgLnEwaNaC 8xJmGHwFBdAAGDwJyZ7yFvwg9; Received: from 97-122-122-234.hlrn.qwest.net ([97.122.122.234]:37760 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vuFkS-00000003hGc-2Jo8 for gdb-patches@sourceware.org; Sun, 22 Feb 2026 13:08:12 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [RFC 0/4] Better Python safety Date: Sun, 22 Feb 2026 12:49:33 -0700 Message-ID: <20260222200759.1587070-1-tom@tromey.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.122.234 X-Source-L: No X-Exim-ID: 1vuFkS-00000003hGc-2Jo8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-122-234.hlrn.qwest.net (localhost.localdomain) [97.122.122.234]:37760 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfFj243DgRhsYP8b3JruQMLyTnfZlyFv/SDFFDWw3W96QgC3wY692N4Bj2/EMzv7os1t3NfPgh3RR1fdxnbnpk2gdyNGPacAEMsyh6TxltVH3d6mBDtnA HNxFzHxZy80r8ccOHwx9BvodbZP+LNlHpSC4sMe3kF4QVbC2iRF0vx+n2UoM/EqEeL+GV+YLWRLKTZopuwwMtt2D0GiXUMelAfY= 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 series is a rough draft showing how I think Python safety could be improved. The basic idea is to use C++ features: more fully use gdbpy_ref<> to avoid reference-counting bugs, introduce a new gdbpy_borrowed_ref to manage borrowed references; throw exceptions on failure rather than explicit error checks; and finally wrap Python C APIs to enforce these rules. This approach also lets us implement Python methods in a more natural style. Explicit try/catch when calling gdb APIs is no longer needed, and methods can simply return the appropriate type. This series is nowhere near complete, but I did mostly convert py-arch.c and py-frame.c. (Discussion of some holes below.) A nice example of the simplification is shown by gdbpy_all_architecture_names, which is now just: gdbpy_ref<> gdbpy_all_architecture_names (gdbpy_borrowed_ref self) { gdbpy_ref<> list = gdbpy_new_list (0); std::vector name_list = gdbarch_printable_names (); for (const char *name : name_list) gdbpy_list_append (list, gdbpy_unicode_from_string (name)); return list; } This shows pretty much all the features: no more error checking and it returns a gdbpy_ref<> since that is convenient. I think a few more features could still be added: * I didn't handle single-argument methods in patch 3. It's tempting to use METH_O but we have at least one that accepts "|s". * I didn't write wrappers for tp_str / tp_repr ... or the methods in PyNumberMethods or PyMappingMethods. This isn't difficult. * I think the approach to handling subclasses of PyObject could be greatly improved. In particular I think we could use real C++ classes by judicious use of placement new and explicit destructor calls. The "corresponding_object_type" stuff you'll see in here is sort of a gesture in this direction (though that code also helps with some type-safety elsewhere as well). Essentially I think we could end up making new instances with just 'new'. I didn't want to really touch this until the stable ABI work related to type-instantiation is done. * Finally gdb is using PyObject_New a lot but my reading while researching this series indicates that this is wrong. However the wrongness is still (I guess temporarily) preserved in a wrapper in this series. * There are some comments in the code where I didn't fully convert something. This would just be a temporary state. Let me know what you think. Tom