From 336bb2a1c1d24f5db07394a109f7cd6c5b58b10d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 11 Sep 2024 10:35:20 -0600 Subject: 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 --- gdb/python/py-linetable.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'gdb/python/py-linetable.c') diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index e3e71f9..8c0a6cc 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -287,27 +287,11 @@ ltpy_dealloc (PyObject *self) static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_linetable (void) { - if (PyType_Ready (&linetable_object_type) < 0) + if (gdbpy_type_ready (&linetable_object_type) < 0) return -1; - if (PyType_Ready (&linetable_entry_object_type) < 0) + if (gdbpy_type_ready (&linetable_entry_object_type) < 0) return -1; - if (PyType_Ready (<py_iterator_object_type) < 0) - return -1; - - Py_INCREF (&linetable_object_type); - Py_INCREF (&linetable_entry_object_type); - Py_INCREF (<py_iterator_object_type); - - if (gdb_pymodule_addobject (gdb_module, "LineTable", - (PyObject *) &linetable_object_type) < 0) - return -1; - - if (gdb_pymodule_addobject (gdb_module, "LineTableEntry", - (PyObject *) &linetable_entry_object_type) < 0) - return -1; - - if (gdb_pymodule_addobject (gdb_module, "LineTableIterator", - (PyObject *) <py_iterator_object_type) < 0) + if (gdbpy_type_ready (<py_iterator_object_type) < 0) return -1; return 0; -- cgit v1.1