From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90344 invoked by alias); 16 Sep 2018 00:56:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 90333 invoked by uid 89); 16 Sep 2018 00:56:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=am, Hx-languages-length:1362, sk:pspace_ X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 16 Sep 2018 00:56:28 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 642811E175; Sat, 15 Sep 2018 20:56:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=simark.ca; s=mail; t=1537059386; bh=jl0O9hw+lqwZhNnybDm4QCO5yjSXpFPECA/Unz9szmg=; h=Subject:To:References:From:Date:In-Reply-To:From; b=Y2IY5msiq8EmtxpYYAxzkAw9jRS1jr7jrzENkxPCKtQdGFsryewwxdjItAYDKsX8y zBWx/yrCu67sAuGiyHEtL9kSjTmIteMd/87D448S+noIviShn9FlZKcpnEXrH46EdG wQsTCsvlWZIgAfPdaewc3m4xS4cJcoIT2cv5ouIQ= Subject: Re: [PATCH 0/4] Disallow the return of borrowed references To: Tom Tromey , gdb-patches@sourceware.org References: <20180913053007.11780-1-tom@tromey.com> From: Simon Marchi Message-ID: <62ef4b2b-13c2-c719-7f90-dc4c1ad79448@simark.ca> Date: Sun, 16 Sep 2018 00:56:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180913053007.11780-1-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-09/txt/msg00510.txt.bz2 On 2018-09-13 1:30 a.m., Tom Tromey wrote: > While working on a different Python patch, I misread > pspace_to_pspace_object and thought it was not handling reference > counts properly. > > It is -- but I found it difficult to reason about because it returns a > borrowed reference, but uses gdbpy_ref as well. > > This series changes gdb so that none of the Python functions will > return a borrowed reference. These functions are modified instead to > return a new reference using gdbpy_ref<>, which not only makes the > intent clear, but also makes it more difficult to have a buggy caller. > > This could go further and make all functions return gdbpy_ref<>. > (Even Python-facing ones could be done via template fuction wrappers.) > However I have not done this. > > I think now gdb should disallow Python functions returning borrowed > references. Accepting a borrowed reference is still ok, and I think > should continue to be. > > I think this series found at least one bug: > infpy_thread_from_thread_handle could return None without incref'ing > it. > > Let me know what you think. I tested this on x86-64 Fedora 28. I think it makes sense and simplifies the way to think about the code. The only difference is a little bit more increfing/decrefing, but it's probably not significant. Simon