diff options
author | Tom Tromey <tom@tromey.com> | 2022-06-01 15:31:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-08-04 13:28:04 -0600 |
commit | cb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch) | |
tree | 7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/python/py-arch.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.bz2 |
Use registry in gdbarch
gdbarch implements its own registry-like approach. This patch changes
it to instead use registry.h. It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.
The main benefit of this change is that it introduces type safety to
the gdbarch registry. It also removes a bunch of code.
One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup. This
doesn't seem very important to me, though.
Diffstat (limited to 'gdb/python/py-arch.c')
-rw-r--r-- | gdb/python/py-arch.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 594e4ed..cf09785 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -28,7 +28,8 @@ struct arch_object { struct gdbarch *gdbarch; }; -static struct gdbarch_data *arch_object_data = NULL; +static const registry<gdbarch>::key<PyObject, gdb::noop_deleter<PyObject>> + arch_object_data; /* Require a valid Architecture. */ #define ARCHPY_REQUIRE_VALID(arch_obj, arch) \ @@ -48,7 +49,7 @@ extern PyTypeObject arch_object_type /* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch post init registration mechanism (gdbarch_data_register_post_init). */ -static void * +static PyObject * arch_object_data_init (struct gdbarch *gdbarch) { arch_object *arch_obj = PyObject_New (arch_object, &arch_object_type); @@ -58,7 +59,7 @@ arch_object_data_init (struct gdbarch *gdbarch) arch_obj->gdbarch = gdbarch; - return (void *) arch_obj; + return (PyObject *) arch_obj; } /* Returns the struct gdbarch value corresponding to the given Python @@ -88,10 +89,14 @@ gdbpy_is_architecture (PyObject *obj) PyObject * gdbarch_to_arch_object (struct gdbarch *gdbarch) { - PyObject *new_ref = (PyObject *) gdbarch_data (gdbarch, arch_object_data); + PyObject *new_ref = arch_object_data.get (gdbarch); + if (new_ref == nullptr) + { + new_ref = arch_object_data_init (gdbarch); + arch_object_data.set (gdbarch, new_ref); + } - /* new_ref could be NULL if registration of arch_object with GDBARCH failed - in arch_object_data_init. */ + /* new_ref could be NULL if creation failed. */ Py_XINCREF (new_ref); return new_ref; @@ -337,13 +342,6 @@ gdbpy_all_architecture_names (PyObject *self, PyObject *args) return list.release (); } -void _initialize_py_arch (); -void -_initialize_py_arch () -{ - arch_object_data = gdbarch_data_register_post_init (arch_object_data_init); -} - /* Initializes the Architecture class in the gdb module. */ int |