Re: [PATCH v2 9/9] gdb/python: add accessor helpers for __dict__ in Python extension objects

Tom Tromey
2026-03-03T19:02:57Z

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

> A previous patch centralized the creation logic; this patch focuses
> on centralizing the access to the dictionary. It introduces two new
> macros:

Thanks.

> + #define gdbpy_dict_wrapper_PyGetSetDef(object_name) \
> + { \
> + "__dict__", /* name */ \
> + (getter) gdb_py_generic_dict_getter, \
> + (setter) nullptr, \
> + "The __dict__ for this " object_name ".", /* doc */ \
> + nullptr, /* closure */ \
> + }
> +
> + #define gdbpy_dict_wrapper_PyTypeObject_tps \
> + /*tp_getattro*/ \
> + gdb_py_generic_getattro, \
> + /*tp_setattro*/ \
> + gdb_py_generic_setattro

I wouldn't indent the '#define'. But I tend to think it would be better
to just use constexpr functions here.

I'd also suggest changing the name, the "PyGetSetDef" suffix is kind of
un-gdb-ish and anyway not really needed for a function, since this will
be clear from the return type.

You can see an example of doing this in a similar-ish context here

https://sourceware.org/pipermail/gdb-patches/2026-February/225253.html

Tom