diff options
author | Tom Tromey <tom@tromey.com> | 2018-04-29 20:59:21 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-04-30 11:33:11 -0600 |
commit | 7c1b5f3db73d7ecab03dc4e866e291582935fb04 (patch) | |
tree | 01ac632a9ca2a8de49aba34932ec8d7c14ca57b8 | |
parent | e11fb955fbab035748fa53ffc30c103157a284b6 (diff) | |
download | gdb-7c1b5f3db73d7ecab03dc4e866e291582935fb04.zip gdb-7c1b5f3db73d7ecab03dc4e866e291582935fb04.tar.gz gdb-7c1b5f3db73d7ecab03dc4e866e291582935fb04.tar.bz2 |
Introduce ref_ptr::new_reference
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-30 Tom Tromey <tom@tromey.com>
* common/gdb_ref_ptr.h (ref_ptr::new_reference): New static
method.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/common/gdb_ref_ptr.h | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9ca2e8e..b65ec81 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-04-30 Tom Tromey <tom@tromey.com> + * common/gdb_ref_ptr.h (ref_ptr::new_reference): New static + method. + +2018-04-30 Tom Tromey <tom@tromey.com> + * jit.c (jit_read_code_entry): Use type_align. * i386-tdep.c (i386_gdbarch_init): Don't call set_gdbarch_long_long_align_bit. diff --git a/gdb/common/gdb_ref_ptr.h b/gdb/common/gdb_ref_ptr.h index 57d1db9..768c813 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; |