Re: [PATCH v2 5/9] gdb/python: allow ref_ptr<T, Policy>::new_reference to accept subclasses of T

Matthieu Longo
2026-03-04T16:58:00Z

On 03/03/2026 18:18, Tom Tromey wrote:
>>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:
>
>> When ref_ptr<T,Policy>::new_reference() is specialized for 'PyObject'
>> (i.e. gdbpy_ref<>), it currently requires the argument type to be exactly
>> 'PyObject *'. As a result, pointers to subclasses of 'PyObject' must be
>> explicitly cast before being passed, making call sites unnecessarily
>> verbose.
>
>> This patch makes ref_ptr<T,Policy>::new_reference() a template method
>> that accepts both T and subclasses of T, performing the cast to 'T *'
>> internally when needed. This removes redundant casts at call sites
>> without changing behavior.
>
> See this series
>
> https://inbox.sourceware.org/gdb-patches/20260221-python-ref-simplif-v1-0-5b06f48d3096@tromey.com/
>
> I can land that this week if it's convenient.
>
> Tom

Yes please.
I will wait for you to merge it before republishing a new revision of my series.

Matthieu