From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 5Dn0FXO4nGnPqwcAWB0awg (envelope-from ) for ; Mon, 23 Feb 2026 15:28:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1771878515; bh=LHno86J8sjd6MaTKmNP3F2typnmTN1CKCKsVaa0Gtoo=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XTz1GRgdrjOE7832kIReDl3p8ftRtVSiCDvkCF5iXxkNT76d+hwFLoEEQc7y8TRIw 4M1oyavKAITdvdqGbzOqsQf8epexN/+OeyEeMXNjMR1ugPobb+d22CV5IHZ/TlC/Va uWOgX22nDKp/euH/cfperDynoIxnURVt3xMD1Jdg= Received: by simark.ca (Postfix, from userid 112) id 2E0961E0BA; Mon, 23 Feb 2026 15:28:35 -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.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=jvy6ql9J; dkim-atps=neutral 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 6CC7B1E08D for ; Mon, 23 Feb 2026 15:28:34 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E70E84BA23DD for ; Mon, 23 Feb 2026 20:28:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E70E84BA23DD Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=jvy6ql9J Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 493EF4BA23DB for ; Mon, 23 Feb 2026 20:28:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 493EF4BA23DB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 493EF4BA23DB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771878488; cv=none; b=cfgR4q8xhd/iL+4n2r0AIXdcYTsQm93MlSCelsb44lxx+FzuX2Znn8Ma/gfiyX9yGTFJlkI6Ehh3kUFAy7br7th9dOM+W1AEu1f/bcpOEwRYqot86hREiGbfOErJD+5ku6bO0PYpX+Kexqmv9FXmGpc4upCTmMyN62tLCMruLmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771878488; c=relaxed/simple; bh=LHno86J8sjd6MaTKmNP3F2typnmTN1CKCKsVaa0Gtoo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=na+/RJJ90/H39Td+I/HQfQEspvhfDxyspqlNpqKXImlVRujJiId7xMhzaiBYB2M1D0R1LhEySRLQ4/lWSe6gWcxrLHXGO+S5S7yaXOxi2uSUADScKE7/sFcYzIYVpgz03Wg1c5jBpvST3ClUqoxpRb60p54BT7fjpy1/L4Axl7g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 493EF4BA23DB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1771878486; bh=LHno86J8sjd6MaTKmNP3F2typnmTN1CKCKsVaa0Gtoo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jvy6ql9Jry+lw3ib45cm//gfQlaHoNkBAWduzv3OMM+DFn2BtEmJayJ6qkEw6w5xo AoVPZ5rCZi8B5bgRYoRazEz+0rk3ssmlY8FK5jaa0OCC3TMJSO905mtD8n3U7/1W0+ Xp3LFqqjaiRprXaAoBm5cZDt6S8kxGK0UdNVFlNY= Received: by simark.ca (Postfix) id 5D2A61E08D; Mon, 23 Feb 2026 15:28:06 -0500 (EST) Message-ID: Date: Mon, 23 Feb 2026 15:28:05 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 0/4] Better Python safety To: Tom Tromey , gdb-patches@sourceware.org References: <20260222200759.1587070-1-tom@tromey.com> Content-Language: en-US From: Simon Marchi In-Reply-To: <20260222200759.1587070-1-tom@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 2026-02-22 14:49, Tom Tromey wrote: > 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 > The series doesn't seem to apply well, and it doesn't specify a base commit. What commit is this based on? Alternatively, can you share your branch directly? Thanks, Simon