Re: [PATCH v2 4/9] gdb: add new helpers for retrieving a type's fully qualified name

Tom Tromey
2026-03-03T18:59:40Z

>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:

> +/* Return the type's fully qualified name from a PyTypeObject. */
> +const char *
> +gdb_py_tp_name (PyTypeObject *py_type) noexcept
> +{
> +#if PY_VERSION_HEX >= 0x030d0000
...
> +#elif ! defined (Py_LIMITED_API)
...
> +#else
> + #error "The version of Python you are using does not expose " \
> + "PyType_GetFullyQualifiedName() as a part of the limited C API."
> +#endif

I think this case can't actually be hit... can it?

My reasoning is that the very first case is taken if either the limited
API is in use (which requires 0x030e0000 as of this patch) or if Python
is new enough.

So, all other cases fall into the non-limited case.

It would be better IMO to remove it if it cannot ever happen.

> +#else
> + #error "The version of Python you are using does not expose Py_TYPE() "\
> + "as a part of the limited C API."

I'd prefer that #error not be indented here.

> +++ b/gdb/python/py-obj-type.h
> @@ -0,0 +1,31 @@
> +/* Helpers related to Python object type
> +
> +/* Return the type's fully qualified name from a PyTypeObject. */
> +extern const char *
> +gdb_py_tp_name (PyTypeObject *py_type) noexcept;
> +
> +/* Return the type's fully qualified name from a PyObject. */
> +extern const char *
> +gdbpy_py_obj_tp_name (PyObject *self) noexcept;

Declarations in gdb don't have a newline after the return type.

thanks,
Tom