From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6270 invoked by alias); 28 Jun 2011 20:30:12 -0000 Received: (qmail 6258 invoked by uid 22791); 28 Jun 2011 20:30:11 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 28 Jun 2011 20:29:54 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5SKTseM022865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 28 Jun 2011 16:29:54 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5SKTrhO030049; Tue, 28 Jun 2011 16:29:54 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p5SKTqps029102; Tue, 28 Jun 2011 16:29:53 -0400 From: Tom Tromey To: pmuldoon@redhat.com Cc: gdb-patches@sourceware.org Subject: Re: [patch] [python] Implement Inferior.current_inferior References: Date: Tue, 28 Jun 2011 20:30:00 -0000 In-Reply-To: (Phil Muldoon's message of "Mon, 27 Jun 2011 15:10:37 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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 X-SW-Source: 2011-06/txt/msg00429.txt.bz2 >>>>> "Phil" == Phil Muldoon writes: Phil> -/* Return a borrowed reference to the Python object of type Inferior Phil> +/* Return a reference to the Python object of type Inferior Phil> representing INFERIOR. If the object has already been created, Phil> - return it, otherwise, create it. Return NULL on failure. */ Phil> + return it and increment the reference count, otherwise, create it. Phil> + Return NULL on failure. */ Phil> PyObject * Phil> inferior_to_inferior_object (struct inferior *inferior) Phil> { Phil> @@ -154,13 +155,14 @@ inferior_to_inferior_object (struct inferior *inferior) Phil> do_cleanups (cleanup); Phil> } Phil> + else Phil> + Py_INCREF ((PyObject *)inf_obj); I don't really follow this. I think the best model would be that the 'struct inferior' owns a reference to the gdb.Inferior object, and then inferior_to_inferior_object is consistent: it either always returns a new reference or a borrowed reference. For a borrowed reference, I think you can leave this function as-is. For a new reference, I think you need to remove the 'else' from your patch, and update infpy_dealloc to decref. Tom