* [PATCH] Fix REGISTRY cleanups
@ 2013-10-26 3:50 Yao Qi
2013-10-28 3:45 ` Joel Brobecker
0 siblings, 1 reply; 6+ messages in thread
From: Yao Qi @ 2013-10-26 3:50 UTC (permalink / raw)
To: gdb-patches
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.
gdb:
2013-10-26 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.
---
gdb/auto-load.c | 12 ++++--------
gdb/inflow.c | 12 ++++--------
gdb/objfiles.c | 10 +++-------
gdb/solib-darwin.c | 5 +----
gdb/solib-dsbt.c | 5 +----
gdb/solib-svr4.c | 6 +-----
6 files changed, 14 insertions(+), 36 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 4eb7cdd..2c534c7 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -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)
{
- 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
diff --git a/gdb/inflow.c b/gdb/inflow.c
index f64c0c1..ad73efe 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -487,15 +487,11 @@ static const struct inferior_data *inflow_inferior_data;
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
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index d1f3121..7029196 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -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)
{
- 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
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index c4c6308..c37049a 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -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)
{
- 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
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 4fe24f8..4e2091b 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -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)
{
- 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
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index ddbbd94..3eea057 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -407,11 +407,7 @@ free_solib_list (struct svr4_info *info)
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);
--
1.7.7.6
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix REGISTRY cleanups
2013-10-26 3:50 [PATCH] Fix REGISTRY cleanups Yao Qi
@ 2013-10-28 3:45 ` Joel Brobecker
2013-10-28 11:36 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2013-10-28 3:45 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
> 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.
>
> gdb:
>
> 2013-10-26 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.
Looks like a nice simplification, but it should be explicitly documented
in registry.h as well. At the moment, it's not clear what gets passed
to the callback, and because of that, you had to quote the actual code.
> ---
> gdb/auto-load.c | 12 ++++--------
> gdb/inflow.c | 12 ++++--------
> gdb/objfiles.c | 10 +++-------
> gdb/solib-darwin.c | 5 +----
> gdb/solib-dsbt.c | 5 +----
> gdb/solib-svr4.c | 6 +-----
> 6 files changed, 14 insertions(+), 36 deletions(-)
>
> diff --git a/gdb/auto-load.c b/gdb/auto-load.c
> index 4eb7cdd..2c534c7 100644
> --- a/gdb/auto-load.c
> +++ b/gdb/auto-load.c
> @@ -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)
> {
> - 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
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index f64c0c1..ad73efe 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -487,15 +487,11 @@ static const struct inferior_data *inflow_inferior_data;
> 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
> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
> index d1f3121..7029196 100644
> --- a/gdb/objfiles.c
> +++ b/gdb/objfiles.c
> @@ -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)
> {
> - 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
> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
> index c4c6308..c37049a 100644
> --- a/gdb/solib-darwin.c
> +++ b/gdb/solib-darwin.c
> @@ -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)
> {
> - 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
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index 4fe24f8..4e2091b 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -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)
> {
> - 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
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index ddbbd94..3eea057 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -407,11 +407,7 @@ free_solib_list (struct svr4_info *info)
> 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);
> --
> 1.7.7.6
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix REGISTRY cleanups
2013-10-28 3:45 ` Joel Brobecker
@ 2013-10-28 11:36 ` Pedro Alves
2013-10-28 12:35 ` Yao Qi
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-28 11:36 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Yao Qi, gdb-patches
On 10/28/2013 03:45 AM, Joel Brobecker wrote:
>> 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.
>>
>> gdb:
>>
>> 2013-10-26 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.
>
> Looks like a nice simplification (...)
+1. Agreed.
(Yao, FYI, "fix" in the subject line confused me a little,
as I found myself scratching my head a little trying to understand
what bug this actually fixes, only to realize it's a code
cleanup sort of fix. I'd suggest changing the subject/commit
to reflect that.)
Thanks,
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix REGISTRY cleanups
2013-10-28 11:36 ` Pedro Alves
@ 2013-10-28 12:35 ` Yao Qi
2013-10-28 14:13 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Yao Qi @ 2013-10-28 12:35 UTC (permalink / raw)
To: Pedro Alves; +Cc: Joel Brobecker, gdb-patches
On 10/28/2013 07:36 PM, Pedro Alves wrote:
> (Yao, FYI, "fix" in the subject line confused me a little,
> as I found myself scratching my head a little trying to understand
> what bug this actually fixes, only to realize it's a code
> cleanup sort of fix. I'd suggest changing the subject/commit
> to reflect that.)
How about "Simplify REGISTRY cleanup usages"? I also update the
comments in registry.h to document the arguments of FREE function.
--
Yao (é½å°§)
Subject: [PATCH] Simplify REGISTRY cleanup usages
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-28 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/auto-load.c | 12 ++++--------
gdb/inflow.c | 12 ++++--------
gdb/objfiles.c | 10 +++-------
gdb/registry.h | 7 ++++---
gdb/solib-darwin.c | 5 +----
gdb/solib-dsbt.c | 5 +----
gdb/solib-svr4.c | 6 +-----
7 files changed, 18 insertions(+), 39 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 4eb7cdd..2c534c7 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -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)
{
- 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
diff --git a/gdb/inflow.c b/gdb/inflow.c
index f64c0c1..ad73efe 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -487,15 +487,11 @@ static const struct inferior_data *inflow_inferior_data;
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
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index d1f3121..7029196 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -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)
{
- 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
diff --git a/gdb/registry.h b/gdb/registry.h
index b3d1b55..cb5d0c3 100644
--- a/gdb/registry.h
+++ b/gdb/registry.h
@@ -45,11 +45,12 @@
- 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.
- 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
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index c4c6308..c37049a 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -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)
{
- 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
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 4fe24f8..4e2091b 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -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)
{
- 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
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index ddbbd94..3eea057 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -407,11 +407,7 @@ free_solib_list (struct svr4_info *info)
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);
--
1.7.7.6
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix REGISTRY cleanups
2013-10-28 12:35 ` Yao Qi
@ 2013-10-28 14:13 ` Pedro Alves
2013-10-29 6:42 ` Yao Qi
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-28 14:13 UTC (permalink / raw)
To: Yao Qi; +Cc: Joel Brobecker, gdb-patches
On 10/28/2013 12:33 PM, Yao Qi wrote:
> On 10/28/2013 07:36 PM, Pedro Alves wrote:
>> (Yao, FYI, "fix" in the subject line confused me a little,
>> as I found myself scratching my head a little trying to understand
>> what bug this actually fixes, only to realize it's a code
>> cleanup sort of fix. I'd suggest changing the subject/commit
>> to reflect that.)
>
> How about "Simplify REGISTRY cleanup usages"? I also update the
> comments in registry.h to document the arguments of FREE function.
Looks good to me.
Thanks,
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix REGISTRY cleanups
2013-10-28 14:13 ` Pedro Alves
@ 2013-10-29 6:42 ` Yao Qi
0 siblings, 0 replies; 6+ messages in thread
From: Yao Qi @ 2013-10-29 6:42 UTC (permalink / raw)
To: Pedro Alves; +Cc: Joel Brobecker, gdb-patches
On 10/28/2013 10:13 PM, Pedro Alves wrote:
> Looks good to me.
Patch is committed.
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-29 6:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-26 3:50 [PATCH] Fix REGISTRY cleanups Yao Qi
2013-10-28 3:45 ` Joel Brobecker
2013-10-28 11:36 ` Pedro Alves
2013-10-28 12:35 ` Yao Qi
2013-10-28 14:13 ` Pedro Alves
2013-10-29 6:42 ` Yao Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox