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

Tom Tromey
2026-03-03T18:19:16Z

>>>>> 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