iconv: Use __twalk_r in __gconv_release_shlib

Message ID 87y33pvzu8.fsf@oldenburg2.str.redhat.com
State New
Headers show
Series
  • iconv: Use __twalk_r in __gconv_release_shlib
Related show

Commit Message

Florian Weimer May 2, 2019, 11:51 a.m.
2019-05-02  Florian Weimer  <fweimer@redhat.com>

	* iconv/gconv_dl.c (release_handle): Remove file-level definition.
	(do_release_shlib): Adjust for __twalk_r.
	(__gconv_release_shlib): Call __twalk_r.

Comments

Florian Weimer June 4, 2019, 11:14 a.m. | #1
* Florian Weimer:

> 2019-05-02  Florian Weimer  <fweimer@redhat.com>

>

> 	* iconv/gconv_dl.c (release_handle): Remove file-level definition.

> 	(do_release_shlib): Adjust for __twalk_r.

> 	(__gconv_release_shlib): Call __twalk_r.

>

> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c

> index cf7023a9aa..8379a488ed 100644

> --- a/iconv/gconv_dl.c

> +++ b/iconv/gconv_dl.c

> @@ -149,15 +149,11 @@ __gconv_find_shlib (const char *name)

>    return found;

>  }

>  

> -

> -/* This is very ugly but the tsearch functions provide no way to pass

> -   information to the walker function.  So we use a global variable.

> -   It is MT safe since we use a lock.  */

> -static struct __gconv_loaded_object *release_handle;

> -

>  static void

> -do_release_shlib (void *nodep, VISIT value, int level)

> +do_release_shlib (const void *nodep, VISIT value, void *closure)

>  {

> +

> +  struct __gconv_loaded_object *release_handle = closure;

>    struct __gconv_loaded_object *obj = *(struct __gconv_loaded_object **) nodep;

>  

>    if (value != preorder && value != leaf)

> @@ -184,13 +180,10 @@ do_release_shlib (void *nodep, VISIT value, int level)

>  void

>  __gconv_release_shlib (struct __gconv_loaded_object *handle)

>  {

> -  /* Urgh, this is ugly but we have no other possibility.  */

> -  release_handle = handle;

> -

>    /* Process all entries.  Please note that we also visit entries

>       with release counts <= 0.  This way we can finally unload them

>       if necessary.  */

> -  __twalk (loaded, (__action_fn_t) do_release_shlib);

> +  __twalk_r (loaded, do_release_shlib, handle);

>  }


Ping?  This gets rid of “very ugly” code (their words, not mine).

Thanks,
Florian
Andreas Schwab June 4, 2019, 11:58 a.m. | #2
On Mai 02 2019, Florian Weimer <fweimer@redhat.com> wrote:

> 	* iconv/gconv_dl.c (release_handle): Remove file-level definition.

> 	(do_release_shlib): Adjust for __twalk_r.

> 	(__gconv_release_shlib): Call __twalk_r.


Ok.

> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c

> index cf7023a9aa..8379a488ed 100644

> --- a/iconv/gconv_dl.c

> +++ b/iconv/gconv_dl.c

> @@ -149,15 +149,11 @@ __gconv_find_shlib (const char *name)

>    return found;

>  }

>  

> -

> -/* This is very ugly but the tsearch functions provide no way to pass

> -   information to the walker function.  So we use a global variable.

> -   It is MT safe since we use a lock.  */

> -static struct __gconv_loaded_object *release_handle;

> -

>  static void

> -do_release_shlib (void *nodep, VISIT value, int level)

> +do_release_shlib (const void *nodep, VISIT value, void *closure)

>  {

> +

> +  struct __gconv_loaded_object *release_handle = closure;


Extra empty line.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Florian Weimer June 4, 2019, 12:23 p.m. | #3
* Andreas Schwab:

> On Mai 02 2019, Florian Weimer <fweimer@redhat.com> wrote:

>

>> 	* iconv/gconv_dl.c (release_handle): Remove file-level definition.

>> 	(do_release_shlib): Adjust for __twalk_r.

>> 	(__gconv_release_shlib): Call __twalk_r.

>

> Ok.

>

>> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c

>> index cf7023a9aa..8379a488ed 100644

>> --- a/iconv/gconv_dl.c

>> +++ b/iconv/gconv_dl.c

>> @@ -149,15 +149,11 @@ __gconv_find_shlib (const char *name)

>>    return found;

>>  }

>>  

>> -

>> -/* This is very ugly but the tsearch functions provide no way to pass

>> -   information to the walker function.  So we use a global variable.

>> -   It is MT safe since we use a lock.  */

>> -static struct __gconv_loaded_object *release_handle;

>> -

>>  static void

>> -do_release_shlib (void *nodep, VISIT value, int level)

>> +do_release_shlib (const void *nodep, VISIT value, void *closure)

>>  {

>> +

>> +  struct __gconv_loaded_object *release_handle = closure;

>

> Extra empty line.


Thanks, pushed with that change.

Florian

Patch

diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
index cf7023a9aa..8379a488ed 100644
--- a/iconv/gconv_dl.c
+++ b/iconv/gconv_dl.c
@@ -149,15 +149,11 @@  __gconv_find_shlib (const char *name)
   return found;
 }
 
-
-/* This is very ugly but the tsearch functions provide no way to pass
-   information to the walker function.  So we use a global variable.
-   It is MT safe since we use a lock.  */
-static struct __gconv_loaded_object *release_handle;
-
 static void
-do_release_shlib (void *nodep, VISIT value, int level)
+do_release_shlib (const void *nodep, VISIT value, void *closure)
 {
+
+  struct __gconv_loaded_object *release_handle = closure;
   struct __gconv_loaded_object *obj = *(struct __gconv_loaded_object **) nodep;
 
   if (value != preorder && value != leaf)
@@ -184,13 +180,10 @@  do_release_shlib (void *nodep, VISIT value, int level)
 void
 __gconv_release_shlib (struct __gconv_loaded_object *handle)
 {
-  /* Urgh, this is ugly but we have no other possibility.  */
-  release_handle = handle;
-
   /* Process all entries.  Please note that we also visit entries
      with release counts <= 0.  This way we can finally unload them
      if necessary.  */
-  __twalk (loaded, (__action_fn_t) do_release_shlib);
+  __twalk_r (loaded, do_release_shlib, handle);
 }