public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [8/17] allow indirect access in registry.h
@ 2011-12-14 21:19 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2011-12-14 21:19 UTC (permalink / raw)
  To: gdb-patches

This changes the new registry.h so that we can insert an indirection
between the container object and the registry fields.

This is just preparation for the next patch.  It doesn't really change
anything by itself, as nothing uses the new facility yet.

Tom

From e27ebc0a681f8a7c152ecfbd7431f2df47e4e98b Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 5 Dec 2011 12:21:42 -0700
Subject: [PATCH 08/18] allow indirect access to registry fields

	* registry.h (struct registry_fields): New.
	(REGISTRY_FIELDS): Redefine.
	(REGISTRY_ACCESS_FIELD): New macro.
	(DEFINE_REGISTRY): Add ACCESS argument.  Update defined
	functions.
---
 gdb/registry.h |   55 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/gdb/registry.h b/gdb/registry.h
index c2a102b..7a78056 100644
--- a/gdb/registry.h
+++ b/gdb/registry.h
@@ -54,16 +54,31 @@
    Fetch the data for an object; returns NULL if it has not been set.
 */
 
+/* This structure is used in a container to hold the data that the
+   registry uses.  */
+
+struct registry_fields
+{
+  void **data;
+  unsigned num_data;
+};
+
 /* This macro is used in a container struct definition to define the
    fields used by the registry code.  */
 
 #define REGISTRY_FIELDS				\
-  void **data;					\
-  unsigned num_data
+  struct registry_fields registry_data
+
+/* A convenience macro for the typical case where the registry data is
+   kept as fields of the object.  This can be passed as the ACCESS
+   method to DEFINE_REGISTRY.  */
+
+#define REGISTRY_ACCESS_FIELD(CONTAINER) \
+  (CONTAINER)
 
 /* Define a new registry implementation.  */
 
-#define DEFINE_REGISTRY(TAG)						\
+#define DEFINE_REGISTRY(TAG, ACCESS)					\
 struct TAG ## _data							\
 {									\
   unsigned index;							\
@@ -114,36 +129,38 @@ register_ ## TAG ## _data (void)					\
 void									\
 TAG ## _alloc_data (struct TAG *container)				\
 {									\
-  gdb_assert (container->data == NULL);					\
-  container->num_data = TAG ## _data_registry.num_registrations;	\
-  container->data = XCALLOC (container->num_data, void *);		\
+  struct registry_fields *rdata = &ACCESS (container)->registry_data;	\
+  gdb_assert (rdata->data == NULL);					\
+  rdata->num_data = TAG ## _data_registry.num_registrations;		\
+  rdata->data = XCALLOC (rdata->num_data, void *);			\
 }									\
 									\
 void									\
 clear_ ## TAG ## _data (struct TAG *container)				\
 {									\
+  struct registry_fields *rdata = &ACCESS (container)->registry_data;	\
   struct TAG ## _data_registration *registration;			\
   int i;								\
 									\
-  gdb_assert (container->data != NULL);					\
+  gdb_assert (rdata->data != NULL);					\
 									\
   /* Process all the save handlers.  */					\
 									\
   for (registration = TAG ## _data_registry.registrations, i = 0;	\
-       i < container->num_data;						\
+       i < rdata->num_data;						\
        registration = registration->next, i++)				\
-    if (container->data[i] != NULL && registration->data->save != NULL)	\
-      registration->data->save (container, container->data[i]);		\
+    if (rdata->data[i] != NULL && registration->data->save != NULL)	\
+      registration->data->save (container, rdata->data[i]);		\
 									\
   /* Now process all the free handlers.  */				\
 									\
   for (registration = TAG ## _data_registry.registrations, i = 0;	\
-       i < container->num_data;						\
+       i < rdata->num_data;						\
        registration = registration->next, i++)				\
-    if (container->data[i] != NULL && registration->data->free != NULL)	\
-      registration->data->free (container, container->data[i]);		\
+    if (rdata->data[i] != NULL && registration->data->free != NULL)	\
+      registration->data->free (container, rdata->data[i]);		\
 									\
-  memset (container->data, 0, container->num_data * sizeof (void *));	\
+  memset (rdata->data, 0, rdata->num_data * sizeof (void *));		\
 }									\
 									\
 void									\
@@ -160,15 +177,17 @@ void									\
 set_ ## TAG ## _data (struct TAG *container, const struct TAG ## _data *data, \
 		  void *value)						\
 {									\
-  gdb_assert (data->index < container->num_data);			\
-  container->data[data->index] = value;					\
+  struct registry_fields *rdata = &ACCESS (container)->registry_data;	\
+  gdb_assert (data->index < rdata->num_data);				\
+  rdata->data[data->index] = value;					\
 }									\
 									\
 void *									\
 TAG ## _data (struct TAG *container, const struct TAG ## _data *data)	\
 {									\
-  gdb_assert (data->index < container->num_data);			\
-  return container->data[data->index];					\
+  struct registry_fields *rdata = &ACCESS (container)->registry_data;	\
+  gdb_assert (data->index < rdata->num_data);				\
+  return rdata->data[data->index];					\
 }
 
 
-- 
1.7.6.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-12-14 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-14 21:19 [8/17] allow indirect access in registry.h Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).