From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33665 invoked by alias); 30 Apr 2018 04:21:54 -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 33620 invoked by uid 89); 30 Apr 2018 04:21:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=seemed, H*MI:sk:2018043, wrapper, H*i:sk:2018043 X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.61.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Apr 2018 04:21:52 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 740824011057E for ; Sun, 29 Apr 2018 23:21:51 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id D0JzfhrhIWCOCD0Jzfbb0H; Sun, 29 Apr 2018 23:21:51 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:34252 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fD0Jz-001psR-6N; Sun, 29 Apr 2018 23:21:51 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/4] Introduce ref_ptr::new_reference Date: Mon, 30 Apr 2018 04:21:00 -0000 Message-Id: <20180430042147.28337-2-tom@tromey.com> In-Reply-To: <20180430042147.28337-1-tom@tromey.com> References: <20180430042147.28337-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fD0Jz-001psR-6N X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:34252 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-04/txt/msg00606.txt.bz2 I noticed a common pattern with gdb::ref_ptr, where callers would "incref" and then create a new wrapper object, like: Py_INCREF (obj); gdbpy_ref<> ref (obj); The ref_ptr constructor intentionally does not acquire a new reference, but it seemed to me that it would be reasonable to add a static member function that does so. In this patch I chose to call the function "new_reference". I considered "acquire_reference" as well, but "new" seemed less ambiguous than "acquire" to me. ChangeLog 2018-04-29 Tom Tromey * common/gdb_ref_ptr.h (ref_ptr::new_reference): New static method. --- gdb/ChangeLog | 5 +++++ gdb/common/gdb_ref_ptr.h | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/gdb/common/gdb_ref_ptr.h b/gdb/common/gdb_ref_ptr.h index 57d1db96e6..768c813692 100644 --- a/gdb/common/gdb_ref_ptr.h +++ b/gdb/common/gdb_ref_ptr.h @@ -149,6 +149,13 @@ class ref_ptr return m_obj; } + /* Acquire a new reference and return a ref_ptr that owns it. */ + static ref_ptr new_reference (T *obj) + { + Policy::incref (obj); + return ref_ptr (obj); + } + private: T *m_obj; -- 2.13.6