about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-12-08 04:02:45 +0000
committerUlrich Drepper <drepper@redhat.com>1999-12-08 04:02:45 +0000
commit76a2102b0874ed777309caf846b5f4d021bb830d (patch)
tree29b483d3fa775eeec677c06ecf3dbdfdf5e413d9
parent8f61a78efeb714b82549df45f735f5e7ee9c1826 (diff)
downloadglibc-76a2102b0874ed777309caf846b5f4d021bb830d.tar.gz
glibc-76a2102b0874ed777309caf846b5f4d021bb830d.tar.xz
glibc-76a2102b0874ed777309caf846b5f4d021bb830d.zip
Update.
1999-12-07  Ulrich Drepper  <drepper@cygnus.com>

	* iconv/gconv_db.c (gen_steps): Set __counter initialy to 1.
	(increment_counter): New function.  Broken out of find_derivation.
	(find_derivation): No need for a lock.  Increment counter only when
	the derivation was already available.
	* iconv/gconv_dl.c: Add debugging functions.
	(known_compare): We have to use strcmp.
-rw-r--r--ChangeLog9
-rw-r--r--iconv/gconv_db.c70
-rw-r--r--iconv/gconv_dl.c30
3 files changed, 71 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 4def948c70..fe45168239 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+1999-12-07  Ulrich Drepper  <drepper@cygnus.com>
+
+	* iconv/gconv_db.c (gen_steps): Set __counter initialy to 1.
+	(increment_counter): New function.  Broken out of find_derivation.
+	(find_derivation): No need for a lock.  Increment counter only when
+	the derivation was already available.
+	* iconv/gconv_dl.c: Add debugging functions.
+	(known_compare): We have to use strcmp.
+
 1999-12-06  Ulrich Drepper  <drepper@cygnus.com>
 
 	* iconvdata/sami-ws2.c (CHARSET_NAME): Fix typo.
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index 8879fe05f2..842cd1faec 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -222,7 +222,7 @@ gen_steps (struct derivation_step *best, const char *toset,
 
 	      result[step_cnt].__shlib_handle = shlib_handle;
 	      result[step_cnt].__modname = shlib_handle->name;
-	      result[step_cnt].__counter = 0;
+	      result[step_cnt].__counter = 1;
 	      result[step_cnt].__fct = shlib_handle->fct;
 	      result[step_cnt].__init_fct = shlib_handle->init_fct;
 	      result[step_cnt].__end_fct = shlib_handle->end_fct;
@@ -281,6 +281,35 @@ gen_steps (struct derivation_step *best, const char *toset,
 }
 
 
+#ifndef STATIC_GCONV
+static int
+internal_function
+increment_counter (struct __gconv_step *steps, size_t nsteps)
+{
+  /* Increment the user counter.  */
+  size_t cnt = nsteps;
+  int result = __GCONV_OK;
+
+  while (cnt-- > 0)
+    if (steps[cnt].__counter++ == 0)
+      {
+	steps[cnt].__shlib_handle =
+	  __gconv_find_shlib (steps[cnt].__modname);
+	if (steps[cnt].__shlib_handle == NULL)
+	  {
+	    /* Oops, this is the second time we use this module (after
+	       unloading) and this time loading failed!?  */
+	    while (++cnt < nsteps)
+	      __gconv_release_shlib (steps[cnt].__shlib_handle);
+	    result = __GCONV_NOCONV;
+	    break;
+	  }
+      }
+  return result;
+}
+#endif
+
+
 /* The main function: find a possible derivation from the `fromset' (either
    the given name or the alias) to the `toset' (again with alias).  */
 static int
@@ -289,19 +318,11 @@ find_derivation (const char *toset, const char *toset_expand,
 		 const char *fromset, const char *fromset_expand,
 		 struct __gconv_step **handle, size_t *nsteps)
 {
-  __libc_lock_define_initialized (static, lock)
   struct derivation_step *first, *current, **lastp, *solution = NULL;
   int best_cost_hi = INT_MAX;
   int best_cost_lo = INT_MAX;
   int result;
 
-  result = derivation_lookup (fromset_expand ?: fromset, toset_expand ?: toset,
-			      handle, nsteps);
-  if (result == __GCONV_OK)
-    return result;
-
-  __libc_lock_lock (lock);
-
   /* There is a small chance that this derivation is meanwhile found.  This
      can happen if in `find_derivation' we look for this derivation, didn't
      find it but at the same time another thread looked for this derivation. */
@@ -309,7 +330,9 @@ find_derivation (const char *toset, const char *toset_expand,
 			      handle, nsteps);
   if (result == __GCONV_OK)
     {
-      __libc_lock_unlock (lock);
+#ifndef STATIC_GCONV
+      result = increment_counter (*handle, *nsteps);
+#endif
       return result;
     }
 
@@ -604,8 +627,6 @@ find_derivation (const char *toset, const char *toset_expand,
   add_derivation (fromset_expand ?: fromset, toset_expand ?: toset,
 		  *handle, *nsteps);
 
-  __libc_lock_unlock (lock);
-
   return result;
 }
 
@@ -667,31 +688,6 @@ __gconv_find_transform (const char *toset, const char *fromset,
   result = find_derivation (toset, toset_expand, fromset, fromset_expand,
 			    handle, nsteps);
 
-#ifndef STATIC_GCONV
-  /* Increment the user counter.  */
-  if (result == __GCONV_OK)
-    {
-      size_t cnt = *nsteps;
-      struct __gconv_step *steps = *handle;
-
-      while (cnt > 0)
-	if (steps[--cnt].__counter++ == 0)
-	  {
-	    steps[cnt].__shlib_handle =
-	      __gconv_find_shlib (steps[cnt].__modname);
-	    if (steps[cnt].__shlib_handle == NULL)
-	      {
-		/* Oops, this is the second time we use this module (after
-		   unloading) and this time loading failed!?  */
-		while (++cnt < *nsteps)
-		  __gconv_release_shlib (steps[cnt].__shlib_handle);
-		result = __GCONV_NOCONV;
-		break;
-	      }
-	  }
-    }
-#endif
-
   /* Release the lock.  */
   __libc_lock_unlock (lock);
 
diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
index 7d327edc68..d4738b5c03 100644
--- a/iconv/gconv_dl.c
+++ b/iconv/gconv_dl.c
@@ -28,6 +28,13 @@
 
 #include <gconv_int.h>
 
+
+#ifdef DEBUG
+/* For debugging purposes.  */
+static void print_all (void);
+#endif
+
+
 /* This is a tuning parameter.  If a transformation module is not used
    anymore it gets not immediately unloaded.  Instead we wait a certain
    number of load attempts for further modules.  If none of the
@@ -50,7 +57,7 @@ known_compare (const void *p1, const void *p2)
   const struct __gconv_loaded_object *s2 =
     (const struct __gconv_loaded_object *) p2;
 
-  return (intptr_t) s1->handle - (intptr_t) s2->handle;
+  return strcmp (s1->name, s2->name);
 }
 
 /* Open the gconv database if necessary.  A non-negative return value
@@ -198,3 +205,24 @@ free_mem (void)
   __tdestroy (loaded, do_release_all);
 }
 text_set_element (__libc_subfreeres, free_mem);
+
+
+#ifdef DEBUG
+static void
+do_print (const void *nodep, VISIT value, int level)
+{
+  struct __gconv_loaded_object *obj = *(struct __gconv_loaded_object **) nodep;
+
+  printf ("%10s: \"%s\", %d\n",
+	  value == leaf ? "leaf" :
+	  value == preorder ? "preorder" :
+	  value == postorder ? "postorder" : "endorder",
+	  obj->name, obj->counter);
+}
+
+static void
+print_all (void)
+{
+  __twalk (loaded, do_print);
+}
+#endif