From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YS0/GlQRmWnteQMAWB0awg (envelope-from ) for ; Fri, 20 Feb 2026 20:58:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1771639124; bh=KxWQrWhcxJGRdM2SID39txpERCkFH9+lGRkI6rXhG10=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AqPWekcLYMYCHFIuXkxHHzbI1ntxqck/GRc34fgfoTMlp6tjQi47UGISRS1ZKNCZU 6F4Z+bwWVclnkfLjXri2bjdECinHO/WuI9UaM5+yQ7wvZypiPZBOzOo5b0FfY01Vlk llt15K+SXDGXaAPi6oj9RmtxF2KVjcWDgf1baAlw= Received: by simark.ca (Postfix, from userid 112) id 65F261E0BA; Fri, 20 Feb 2026 20:58:44 -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=C9GpPbdC; 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 D47EE1E08D for ; Fri, 20 Feb 2026 20:58:43 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5DA794BAD159 for ; Sat, 21 Feb 2026 01:58:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DA794BAD159 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=C9GpPbdC Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id DB6B64B9DB66 for ; Sat, 21 Feb 2026 01:58:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB6B64B9DB66 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 DB6B64B9DB66 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=1771639097; cv=none; b=mlRjcLLFMMOH2TiIUARR/e+D0hhc9D5o074nC2p9U1E6wrfEdwYZq1l8RXcPVbMDGpIM9ixwQ0XGapMZjVVxNRyJFY9uSAC6mAi1V2l7wZaXQJKZ7JzliDqWPZ8MQr2qTosdUzOechCzaA8BzO+g1sPUnoqN8JdF/XrxfcNp7mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771639097; c=relaxed/simple; bh=KxWQrWhcxJGRdM2SID39txpERCkFH9+lGRkI6rXhG10=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=mNFKgY0hfEQIv6Sayg5vAjqEZtReQlhd0nhFlYh5WlEAU04g5mQzmPVD/OiSZmxZ08plQXgw2EyREjMPlsH/1ETObCKIv0nA0D2tcpBwOnMTFFXTPIav508gBmQn583XSmymRMjEL3olACSsVAnz1Gfj4CZP27UD3WhLRzLtMaQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB6B64B9DB66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1771639096; bh=KxWQrWhcxJGRdM2SID39txpERCkFH9+lGRkI6rXhG10=; h=Date:Subject:To:References:From:In-Reply-To:From; b=C9GpPbdCZC9U2rAdTzl2LHLoO3VvblWV/gy3BF0UcnTNEpihYmhJkTPAmI0QkuJU+ QVkENzNmm7/MP0aUFDUPXkZnn7I+ytCcVUC5rV04HytxB8qJ8dzrQeyPWQiFQyNakf IjeKdFWNF7NzC+g3MZR6Lq3mh+aVv4A3n82iiB2A= Received: by simark.ca (Postfix) id A5ACA1E08D; Fri, 20 Feb 2026 20:58:15 -0500 (EST) Message-ID: <9eed1009-8563-45cf-b9d2-e0ebb3005683@simark.ca> Date: Fri, 20 Feb 2026 20:58:15 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 01/10] Return gdbpy_ref<> from symtab_and_line_to_sal_object To: Tom Tromey , gdb-patches@sourceware.org References: <20260220-python-safety-minor-v1-0-4c4b12e445af@adacore.com> <20260220-python-safety-minor-v1-1-4c4b12e445af@adacore.com> Content-Language: en-US From: Simon Marchi In-Reply-To: <20260220-python-safety-minor-v1-1-4c4b12e445af@adacore.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-20 16:03, Tom Tromey wrote: > This changes symtab_and_line_to_sal_object to return a gdbpy_ref<>, > using the type system to convey that a new reference is always > returned. I noted some stylistic suggestions below. It's a bit subjective so it's up to you really. I suppose that the same patterns happen in all the patches. > @@ -560,7 +560,7 @@ pspy_find_pc_line (PyObject *o, PyObject *args) > return gdbpy_handle_gdb_exception (nullptr, except); > } > > - return result; > + return result.release (); In these cases I think I would return directly from the symtab_and_line_to_sal_object call: return symtab_and_line_to_sal_object (sal).release (); > diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c > index 2dca0083277..820542932ba 100644 > --- a/gdb/python/py-symtab.c > +++ b/gdb/python/py-symtab.c > @@ -390,7 +390,7 @@ symtab_to_symtab_object (struct symtab *symtab) > > /* Create a new symtab and line (gdb.Symtab_and_line) object > that encapsulates the symtab_and_line structure from GDB. */ > -PyObject * > +gdbpy_ref<> > symtab_and_line_to_sal_object (struct symtab_and_line sal) > { > sal_object *sal_obj; > @@ -399,7 +399,7 @@ symtab_and_line_to_sal_object (struct symtab_and_line sal) > if (sal_obj != nullptr) > set_sal (sal_obj, sal); > > - return (PyObject *) sal_obj; > + return gdbpy_ref<> (sal_obj); I think you could be even more pedantic and change sal_obj to be of type gdbpy_ref<>. This way, the ref is managed from the very edge of the Python API. Simon