Simplify REGISTRY cleanup usages
authorYao Qi <yao@codesourcery.com>
Thu, 24 Oct 2013 12:42:02 +0000 (20:42 +0800)
committerYao Qi <yao@codesourcery.com>
Tue, 29 Oct 2013 06:36:29 +0000 (14:36 +0800)
In registry.c:registry_clear_data, the registered data is iterated and
invoke each 'free' function with the data passed:

  for (registration = data_registry->registrations, i = 0;
       i < fields->num_data;
       registration = registration->next, i++)
    if (fields->data[i] != NULL && registration->data->free != NULL)
      adaptor (registration->data->free, container, fields->data[i]);

we can see that data is passed to function 'free' and data is not NULL.
In each usage, we don't have to get the data again through key and
do NULL pointer checking.  This patch is to simplify them.

gdb:

2013-10-29  Yao Qi  <yao@codesourcery.com>

* auto-load.c (auto_load_pspace_data_cleanup): Get data from
parameter 'arg' instead of from program_space_data.
* objfiles.c (objfiles_pspace_data_cleanup): Likewise.
* solib-darwin.c (darwin_pspace_data_cleanup): Likewise.
* solib-dsbt.c (dsbt_pspace_data_cleanup): Likewise.
* solib-svr4.c (svr4_pspace_data_cleanup): Likewise.
* inflow.c (inflow_inferior_data_cleanup): Get data from
parameter 'arg' instead of inferior_data.
* registry.h: Add comments.

gdb/ChangeLog
gdb/auto-load.c
gdb/inflow.c
gdb/objfiles.c
gdb/registry.h
gdb/solib-darwin.c
gdb/solib-dsbt.c
gdb/solib-svr4.c

index 8bb0385f65d7cc930f13464745499cf955b07b66..d050c23bc325801d1e1b78216cea0f86b2572f4a 100644 (file)
@@ -1,3 +1,15 @@
+2013-10-29  Yao Qi  <yao@codesourcery.com>
+
+       * auto-load.c (auto_load_pspace_data_cleanup): Get data from
+       parameter 'arg' instead of from program_space_data.
+       * objfiles.c (objfiles_pspace_data_cleanup): Likewise.
+       * solib-darwin.c (darwin_pspace_data_cleanup): Likewise.
+       * solib-dsbt.c (dsbt_pspace_data_cleanup): Likewise.
+       * solib-svr4.c (svr4_pspace_data_cleanup): Likewise.
+       * inflow.c (inflow_inferior_data_cleanup): Get data from
+       parameter 'arg' instead of inferior_data.
+       * registry.h: Add comments.
+
 2013-10-28  Pedro Alves  <palves@redhat.com>
 
        * breakpoint.c (watchpoints_triggered)
 2013-10-28  Pedro Alves  <palves@redhat.com>
 
        * breakpoint.c (watchpoints_triggered)
index 4eb7cdd499eff613ee22bc5bc9bf06cbe90d8282..2c534c79088bb562e17d40008b8fe6c9b66d069d 100644 (file)
@@ -572,15 +572,11 @@ static const struct program_space_data *auto_load_pspace_data;
 static void
 auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
 static void
 auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
-  struct auto_load_pspace_info *info;
+  struct auto_load_pspace_info *info = arg;
 
 
-  info = program_space_data (pspace, auto_load_pspace_data);
-  if (info != NULL)
-    {
-      if (info->loaded_scripts)
-       htab_delete (info->loaded_scripts);
-      xfree (info);
-    }
+  if (info->loaded_scripts)
+    htab_delete (info->loaded_scripts);
+  xfree (info);
 }
 
 /* Get the current autoload data.  If none is found yet, add it now.  This
 }
 
 /* Get the current autoload data.  If none is found yet, add it now.  This
index f64c0c186f8d7d137994247a0d1e1ca8af98345f..ad73efeb0aa8f87cd9f5de72ecad0f2e989cc7fd 100644 (file)
@@ -487,15 +487,11 @@ static const struct inferior_data *inflow_inferior_data;
 static void
 inflow_inferior_data_cleanup (struct inferior *inf, void *arg)
 {
 static void
 inflow_inferior_data_cleanup (struct inferior *inf, void *arg)
 {
-  struct terminal_info *info;
+  struct terminal_info *info = arg;
 
 
-  info = inferior_data (inf, inflow_inferior_data);
-  if (info != NULL)
-    {
-      xfree (info->run_terminal);
-      xfree (info->ttystate);
-      xfree (info);
-    }
+  xfree (info->run_terminal);
+  xfree (info->ttystate);
+  xfree (info);
 }
 
 /* Get the current svr4 data.  If none is found yet, add it now.  This
 }
 
 /* Get the current svr4 data.  If none is found yet, add it now.  This
index d1f312141dad20c81be79ebcbc9099ab0327c68f..7029196b463024f2dc63222c44670be70db8794e 100644 (file)
@@ -85,14 +85,10 @@ static const struct program_space_data *objfiles_pspace_data;
 static void
 objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
 static void
 objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
-  struct objfile_pspace_info *info;
+  struct objfile_pspace_info *info = arg;
 
 
-  info = program_space_data (pspace, objfiles_pspace_data);
-  if (info != NULL)
-    {
-      xfree (info->sections);
-      xfree (info);
-    }
+  xfree (info->sections);
+  xfree (info);
 }
 
 /* Get the current svr4 data.  If none is found yet, add it now.  This
 }
 
 /* Get the current svr4 data.  If none is found yet, add it now.  This
index b3d1b552696087ef4da525d438e15a43861327ad..cb5d0c384de2e1ff783ea0f7f953f77725319034 100644 (file)
    
    - register_TAG_data_with_cleanup(TAG, SAVE, FREE)
    Get a new key for the container type TAG.
    
    - register_TAG_data_with_cleanup(TAG, SAVE, FREE)
    Get a new key for the container type TAG.
-   SAVE and FREE are defined as void (*) (struct TAG *, void *)
-   When the container is destroyed, first all registered SAVE
+   SAVE and FREE are defined as void (*) (struct TAG *object, void *data)
+   When the container object OBJECT is destroyed, first all registered SAVE
    functions are called.
    Then all FREE functions are called.
    functions are called.
    Then all FREE functions are called.
-   Either or both may be NULL.
+   Either or both may be NULL.  DATA is the data associated with the
+   container object OBJECT.
    
    - clear_TAG_data(TAG, OBJECT)
    Clear all the data associated with OBJECT.  Should be called by the
    
    - clear_TAG_data(TAG, OBJECT)
    Clear all the data associated with OBJECT.  Should be called by the
index c4c6308cf251934cf525ce0d5ced370f542cfe3a..c37049abf25070d3d018f8d7a6c8c352f373765a 100644 (file)
@@ -88,10 +88,7 @@ static const struct program_space_data *solib_darwin_pspace_data;
 static void
 darwin_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
 static void
 darwin_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
-  struct darwin_info *info;
-
-  info = program_space_data (pspace, solib_darwin_pspace_data);
-  xfree (info);
+  xfree (arg);
 }
 
 /* Get the current darwin data.  If none is found yet, add it now.  This
 }
 
 /* Get the current darwin data.  If none is found yet, add it now.  This
index 4fe24f82e6e98002642f2a99eea10cbafc436695..4e2091b1f99d30e693aeff5423ec7017179e9c9e 100644 (file)
@@ -166,10 +166,7 @@ static const struct program_space_data *solib_dsbt_pspace_data;
 static void
 dsbt_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
 static void
 dsbt_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
-  struct dsbt_info *info;
-
-  info = program_space_data (pspace, solib_dsbt_pspace_data);
-  xfree (info);
+  xfree (arg);
 }
 
 /* Get the current dsbt data.  If none is found yet, add it now.  This
 }
 
 /* Get the current dsbt data.  If none is found yet, add it now.  This
index ddbbd944e2fbfa8a4acc6238474e4c37233305f4..3eea0570afc647a04f1308dea2b253cdf253e43f 100644 (file)
@@ -407,11 +407,7 @@ free_solib_list (struct svr4_info *info)
 static void
 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
 static void
 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
-  struct svr4_info *info;
-
-  info = program_space_data (pspace, solib_svr4_pspace_data);
-  if (info == NULL)
-    return;
+  struct svr4_info *info = arg;
 
   free_probes_table (info);
   free_solib_list (info);
 
   free_probes_table (info);
   free_solib_list (info);