Automatically add types to Python modules

PR python/32163 points out that various types provided by gdb are not
added to the gdb module, so they aren't available for interactive
inspection.  I think this is just an oversight.

This patch fixes the problem by introducing a new helper function that
both readies the type and then adds it to the appropriate module.  The
patch also poisons PyType_Ready, the idea being to avoid this bug in
the future.

v2:
* Fixed a bug in original patch in gdb.Architecture registration
* Added regression test for the types mentioned in the bug

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32163
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
This commit is contained in:
Tom Tromey
2024-09-11 10:35:20 -06:00
parent b9155b800c
commit 336bb2a1c1
35 changed files with 102 additions and 230 deletions

View File

@@ -512,19 +512,14 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_symtabs (void)
{
symtab_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&symtab_object_type) < 0)
if (gdbpy_type_ready (&symtab_object_type) < 0)
return -1;
sal_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&sal_object_type) < 0)
if (gdbpy_type_ready (&sal_object_type) < 0)
return -1;
if (gdb_pymodule_addobject (gdb_module, "Symtab",
(PyObject *) &symtab_object_type) < 0)
return -1;
return gdb_pymodule_addobject (gdb_module, "Symtab_and_line",
(PyObject *) &sal_object_type);
return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_symtabs);