From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26566 invoked by alias); 12 Sep 2013 22:27:42 -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 26548 invoked by uid 89); 12 Sep 2013 22:27:42 -0000 Received: from mail-vb0-f74.google.com (HELO mail-vb0-f74.google.com) (209.85.212.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 12 Sep 2013 22:27:41 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_SOFTFAIL autolearn=ham version=3.3.2 X-HELO: mail-vb0-f74.google.com Received: by mail-vb0-f74.google.com with SMTP id w16so60720vbf.5 for ; Thu, 12 Sep 2013 15:27:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=DyFZ28ImQwPQAG1C667+Z8cy13QILQ8EGkqS88ia0Zg=; b=nJf52B+iHgIgdTP9Hxwd+Moget0eOM8vcrKsK675W4RyZiG0jtqS9rqO7R9gl9hVkq zFXjBa5JenwT0QLv6h3pq2FRnYBVeAsSlIRAVKAKScHHDSLPCPJjaHrg36Cefth3qzo6 OQH+N7E/CKST7ePPEnF5mkb+K9yuOn64HfBNyBDn66mEMUdRAyW8C5L8Nrcwps0NMmcP mnFLQE8DFkoGmCdk4anQ4O7Fb/sofUuT7HYRH5aYDv8oTnAvfY/ZXWvL7a+fyKqfPr02 sFUkvuATL3TEPIdC6sSTDlBnb4zroFe+OzOsHOJaHIkKq+G99ZqHIfwqAXzW3vO94Otv cetw== X-Gm-Message-State: ALoCoQnIIZGh9HXGc3SZHxOR11jXWzjvIS8OLqjuzI8IZK1iWUy6RY4UWEoxPqnWDDgBJ/BTBALHQkxW+JeQcWCvaNRLoxRnuK5c5wGp8wsBCYhucMHJYS7ATl8gHZsERMIj1jRfd9QPFwDXJJNYirFe1GScoofxhZixTc1hBDwwol8RmSmLPfd5oCNI7i4ooOljyYxCpiTe/YPe1AOsIXqJDaGjgLaBRqYzcNEcDVIibO3P21b4prA= X-Received: by 10.236.66.244 with SMTP id h80mr3853090yhd.30.1379024858551; Thu, 12 Sep 2013 15:27:38 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id s21si462787yhc.1.1969.12.31.16.00.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Thu, 12 Sep 2013 15:27:38 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 27F865A4174 for ; Thu, 12 Sep 2013 15:27:38 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [RFA] fix ref counting of inferior_to_inferior_object Date: Thu, 12 Sep 2013 22:27:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00387.txt.bz2 Hi. While adding an inferior attribute to the newobjfile event, I noticed inferior_to_inferior_object sometimes returns (AFAICT) a new reference and sometimes returns a borrowed reference. This patch makes it consistently return a borrowed reference (for consistency with obfile_to_objfile_object), and then updates the rest of the code. Regression tested on amd64-linux. Ok to check in? 2013-09-12 Doug Evans * python/py-exitedevent.c (create_exited_event_object): Add comment. * python/py-inferior.c (inferior_to_inferior_object): Always return a borrowed reference. (find_inferior_object): Return a new reference to the inferior object. (build_inferior_list): Update, inferior_to_inferior_object returns a borrowed reference. (gdbpy_selected_inferior): Ditto. Index: python/py-exitedevent.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-exitedevent.c,v retrieving revision 1.8 diff -u -p -r1.8 py-exitedevent.c --- python/py-exitedevent.c 20 May 2013 20:09:01 -0000 1.8 +++ python/py-exitedevent.c 12 Sep 2013 22:19:49 -0000 @@ -49,6 +49,8 @@ create_exited_event_object (const LONGES goto fail; } + /* Note that inferior_to_inferior_object returns a borrowed reference, + so we don't need a decref here. */ inf_obj = inferior_to_inferior_object (inf); if (!inf_obj || evpy_add_attribute (exited_event, "inferior", Index: python/py-inferior.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-inferior.c,v retrieving revision 1.36 diff -u -p -r1.36 py-inferior.c --- python/py-inferior.c 18 Jun 2013 18:43:27 -0000 1.36 +++ python/py-inferior.c 12 Sep 2013 22:19:50 -0000 @@ -161,8 +161,9 @@ python_new_objfile (struct objfile *objf /* Return a reference to the Python object of type Inferior representing INFERIOR. If the object has already been created, - return it and increment the reference count, otherwise, create it. + return it, otherwise create it. The result is a borrowed reference. Return NULL on failure. */ + PyObject * inferior_to_inferior_object (struct inferior *inferior) { @@ -180,15 +181,12 @@ inferior_to_inferior_object (struct infe inf_obj->nthreads = 0; set_inferior_data (inferior, infpy_inf_data_key, inf_obj); - } - else - Py_INCREF ((PyObject *)inf_obj); return (PyObject *) inf_obj; } -/* Finds the Python Inferior object for the given PID. Returns a +/* Finds the Python Inferior object for the given PID. Returns a new reference, or NULL if PID does not match any inferior object. */ PyObject * @@ -197,7 +195,12 @@ find_inferior_object (int pid) struct inferior *inf = find_inferior_pid (pid); if (inf) - return inferior_to_inferior_object (inf); + { + PyObject *inf_obj = inferior_to_inferior_object (inf); + + Py_XINCREF (inf_obj); + return inf_obj; + } return NULL; } @@ -384,7 +387,6 @@ build_inferior_list (struct inferior *in return 0; success = PyList_Append (list, inferior); - Py_DECREF (inferior); if (success) return 1; @@ -768,12 +770,16 @@ py_free_inferior (struct inferior *inf, } /* Implementation of gdb.selected_inferior() -> gdb.Inferior. - Returns the current inferior object. */ + Returns a new reference to the current inferior object. */ PyObject * gdbpy_selected_inferior (PyObject *self, PyObject *args) { - return inferior_to_inferior_object (current_inferior ()); + PyObject *inf_obj; + + inf_obj = inferior_to_inferior_object (current_inferior ()); + Py_XINCREF (inf_obj); + return inf_obj; } int