From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/4] Introduce ref_ptr::new_reference
Date: Mon, 30 Apr 2018 04:21:00 -0000 [thread overview]
Message-ID: <20180430042147.28337-2-tom@tromey.com> (raw)
In-Reply-To: <20180430042147.28337-1-tom@tromey.com>
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 <tom@tromey.com>
* 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<T, Policy> new_reference (T *obj)
+ {
+ Policy::incref (obj);
+ return ref_ptr<T, Policy> (obj);
+ }
+
private:
T *m_obj;
--
2.13.6
prev parent reply other threads:[~2018-04-30 4:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-30 4:21 [RFA 0/4] add ref_ptr::new_reference Tom Tromey
2018-04-30 4:21 ` [RFA 4/4] Change Python code to use new_reference Tom Tromey
2018-04-30 13:34 ` Phil Muldoon
2018-04-30 4:21 ` [RFA 2/4] Remove new_bfd_ref Tom Tromey
2018-04-30 4:21 ` [RFA 3/4] Use new_reference for struct value Tom Tromey
2018-04-30 17:05 ` Pedro Alves
2018-04-30 17:32 ` Tom Tromey
2018-04-30 4:21 ` Tom Tromey [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180430042147.28337-2-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox