From: Tom Tromey Date: Mon, 30 Apr 2018 02:59:21 +0000 (-0600) Subject: Introduce ref_ptr::new_reference X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7c1b5f3db73d7ecab03dc4e866e291582935fb04;p=binutils-gdb.git 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 * common/gdb_ref_ptr.h (ref_ptr::new_reference): New static method. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9ca2e8e9574..b65ec81e359 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-04-30 Tom Tromey + + * common/gdb_ref_ptr.h (ref_ptr::new_reference): New static + method. + 2018-04-30 Tom Tromey * jit.c (jit_read_code_entry): Use type_align. diff --git a/gdb/common/gdb_ref_ptr.h b/gdb/common/gdb_ref_ptr.h index 57d1db96e6c..768c8136928 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;