[PATCH 0/4] Disallow the return of borrowed references
Simon Marchi
simark@simark.ca
Sun Sep 16 00:56:00 GMT 2018
On 2018-09-13 1:30 a.m., Tom Tromey wrote:
> While working on a different Python patch, I misread
> pspace_to_pspace_object and thought it was not handling reference
> counts properly.
>
> It is -- but I found it difficult to reason about because it returns a
> borrowed reference, but uses gdbpy_ref as well.
>
> This series changes gdb so that none of the Python functions will
> return a borrowed reference. These functions are modified instead to
> return a new reference using gdbpy_ref<>, which not only makes the
> intent clear, but also makes it more difficult to have a buggy caller.
>
> This could go further and make all functions return gdbpy_ref<>.
> (Even Python-facing ones could be done via template fuction wrappers.)
> However I have not done this.
>
> I think now gdb should disallow Python functions returning borrowed
> references. Accepting a borrowed reference is still ok, and I think
> should continue to be.
>
> I think this series found at least one bug:
> infpy_thread_from_thread_handle could return None without incref'ing
> it.
>
> Let me know what you think. I tested this on x86-64 Fedora 28.
I think it makes sense and simplifies the way to think about the code. The
only difference is a little bit more increfing/decrefing, but it's probably
not significant.
Simon
More information about the Gdb-patches
mailing list