This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 02/14] Change event code to use gdbpy_reference
On 11/11/2016 12:09 AM, Pedro Alves wrote:
> On 11/07/2016 05:47 AM, Tom Tromey wrote:
>> PyObject *
>> create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
>> {
>> - PyObject *breakpoint_event_obj =
>> - create_stop_event_object (&breakpoint_event_object_type);
>> + gdbpy_reference breakpoint_event_obj
>> + (create_stop_event_object (&breakpoint_event_object_type));
>>
>
>> - fail:
>> - Py_XDECREF (breakpoint_event_obj);
>> - return NULL;
>> + return breakpoint_event_obj.release ();
>> }
>
> Wouldn't it better to make these create_foo functions return a
> gdbpy_reference ? Then at the call site you'd use std::move instead
> of reset (when assigning to an existing lval):
>
> stop_event_obj = std::move (create_breakpoint_event_object (list.get (),
> first_bp));
Err, not even std::move would be necessary, of course,
since the function's return would be an rvalue in this context already.
So you'd just do:
stop_event_obj = create_breakpoint_event_object (list.get (), first_bp));
That could be done after this series lands, in any case.
> The advantage of following such a principle is that it makes it impossible
> for callers to forget to manage the result with a gdbpy_reference, since
> assigning the return to a raw PyObject * won't compile.
Thanks,
Pedro Alves