aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-block.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-10-18 11:38:10 -0600
committerTom Tromey <tom@tromey.com>2022-07-28 14:16:50 -0600
commit08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63 (patch)
treee1050b58dcebee1150881f43f64c1c186955d240 /gdb/python/py-block.c
parent8f83e7b9262e08fa43ca6e645337511c68ddc52a (diff)
downloadgdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.zip
gdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.tar.gz
gdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.tar.bz2
Rewrite registry.h
This rewrites registry.h, removing all the macros and replacing it with relatively ordinary template classes. The result is less code than the previous setup. It replaces large macros with a relatively straightforward C++ class, and now manages its own cleanup. The existing type-safe "key" class is replaced with the equivalent template class. This approach ended up requiring relatively few changes to the users of the registry code in gdb -- code using the key system just required a small change to the key's declaration. All existing users of the old C-like API are now converted to use the type-safe API. This mostly involved changing explicit deletion functions to be an operator() in a deleter class. The old "save/free" two-phase process is removed, and replaced with a single "free" phase. No existing code used both phases. The old "free" callbacks took a parameter for the enclosing container object. However, this wasn't truly needed and is removed here as well.
Diffstat (limited to 'gdb/python/py-block.c')
-rw-r--r--gdb/python/py-block.c70
1 files changed, 28 insertions, 42 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 872fb89..b9aea3a 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -77,9 +77,33 @@ struct block_syms_iterator_object {
} \
} while (0)
+/* This is called when an objfile is about to be freed.
+ Invalidate the block as further actions on the block would result
+ in bad data. All access to obj->symbol should be gated by
+ BLPY_REQUIRE_VALID which will raise an exception on invalid
+ blocks. */
+struct blpy_deleter
+{
+ void operator() (block_object *obj)
+ {
+ while (obj)
+ {
+ block_object *next = obj->next;
+
+ obj->block = NULL;
+ obj->objfile = NULL;
+ obj->next = NULL;
+ obj->prev = NULL;
+
+ obj = next;
+ }
+ }
+};
+
extern PyTypeObject block_syms_iterator_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
-static const struct objfile_data *blpy_objfile_data_key;
+static const registry<objfile>::key<block_object, blpy_deleter>
+ blpy_objfile_data_key;
static PyObject *
blpy_iter (PyObject *self)
@@ -269,10 +293,7 @@ blpy_dealloc (PyObject *obj)
if (block->prev)
block->prev->next = block->next;
else if (block->objfile)
- {
- set_objfile_data (block->objfile, blpy_objfile_data_key,
- block->next);
- }
+ blpy_objfile_data_key.set (block->objfile, block->next);
if (block->next)
block->next->prev = block->prev;
block->block = NULL;
@@ -293,11 +314,10 @@ set_block (block_object *obj, const struct block *block,
if (objfile)
{
obj->objfile = objfile;
- obj->next = ((block_object *)
- objfile_data (objfile, blpy_objfile_data_key));
+ obj->next = blpy_objfile_data_key.get (objfile);
if (obj->next)
obj->next->prev = obj;
- set_objfile_data (objfile, blpy_objfile_data_key, obj);
+ blpy_objfile_data_key.set (objfile, obj);
}
else
obj->next = NULL;
@@ -404,40 +424,6 @@ blpy_iter_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
-/* This function is called when an objfile is about to be freed.
- Invalidate the block as further actions on the block would result
- in bad data. All access to obj->symbol should be gated by
- BLPY_REQUIRE_VALID which will raise an exception on invalid
- blocks. */
-static void
-del_objfile_blocks (struct objfile *objfile, void *datum)
-{
- block_object *obj = (block_object *) datum;
-
- while (obj)
- {
- block_object *next = obj->next;
-
- obj->block = NULL;
- obj->objfile = NULL;
- obj->next = NULL;
- obj->prev = NULL;
-
- obj = next;
- }
-}
-
-void _initialize_py_block ();
-void
-_initialize_py_block ()
-{
- /* Register an objfile "free" callback so we can properly
- invalidate blocks when an object file is about to be
- deleted. */
- blpy_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
-}
-
int
gdbpy_initialize_blocks (void)
{