babl r298 - in trunk: . babl



Author: neo
Date: Sat Mar 29 19:02:20 2008
New Revision: 298
URL: http://svn.gnome.org/viewvc/babl?rev=298&view=rev

Log:
2008-03-29  Sven Neumann  <sven gimp org>

	* babl/babl-component.c
	* babl/babl-conversion.c
	* babl/babl-db.c
	* babl/babl-extension.c
	* babl/babl-fish-path.c
	* babl/babl-fish-reference.c
	* babl/babl-fish-simple.c
	* babl/babl-format.c
	* babl/babl-model.c
	* babl/babl-type.c: applied patch from Jan Heller that changes 
the
	code to test for a pre-existent instance of a babl class in the
	database before creating a new one.



Modified:
   trunk/ChangeLog
   trunk/babl/babl-component.c
   trunk/babl/babl-conversion.c
   trunk/babl/babl-db.c
   trunk/babl/babl-extension.c
   trunk/babl/babl-fish-path.c
   trunk/babl/babl-fish-reference.c
   trunk/babl/babl-fish-simple.c
   trunk/babl/babl-format.c
   trunk/babl/babl-model.c
   trunk/babl/babl-type.c

Modified: trunk/babl/babl-component.c
==============================================================================
--- trunk/babl/babl-component.c	(original)
+++ trunk/babl/babl-component.c	Sat Mar 29 19:02:20 2008
@@ -109,14 +109,22 @@
 
   va_end (varg);
 
+  babl = babl_db_exist (db, id, first_arg);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = component_new (first_arg, id, luma, chroma, alpha);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 BABL_CLASS_TEMPLATE (component)

Modified: trunk/babl/babl-conversion.c
==============================================================================
--- trunk/babl/babl-conversion.c	(original)
+++ trunk/babl/babl-conversion.c	Sat Mar 29 19:02:20 2008
@@ -79,7 +79,7 @@
           }
         else if (planar)
           {
-            babl_fatal ("planar conversions not supported for %ssupported",
+            babl_fatal ("planar conversions not supported for %s",
                         babl_class_name (source->class_type));
           }
         break;
@@ -257,18 +257,26 @@
     {
       type = BABL_CONVERSION_PLANAR;
     }
-  babl = conversion_new (create_name (source, destination, type),
-                         id, source, destination, linear, plane, planar);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    else
-      babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
-
-    return ret;
-  }
+  char * name = create_name (source, destination, type);
+  
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
+  babl = conversion_new (name, id, source, destination, linear, plane, planar);
+
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
+  return babl;
 }
 
 static long

Modified: trunk/babl/babl-db.c
==============================================================================
--- trunk/babl/babl-db.c	(original)
+++ trunk/babl/babl-db.c	Sat Mar 29 19:02:20 2008
@@ -94,12 +94,6 @@
 babl_db_insert (BablDb *db,
                 Babl   *item)
 {
-
-  Babl *found = babl_db_exist (db, item->instance.id, item->instance.name);
-
-  if (found)
-    return found;
-
   if (item->instance.id)
     babl_hash_table_insert (db->id_hash, item);
   babl_hash_table_insert (db->name_hash, item);

Modified: trunk/babl/babl-extension.c
==============================================================================
--- trunk/babl/babl-extension.c	(original)
+++ trunk/babl/babl-extension.c	Sat Mar 29 19:02:20 2008
@@ -184,7 +184,7 @@
   init = dlsym (dl_handle, "init");
   if (!init)
     {
-      babl_log ("\n\tint babl_extension_init() function not found in extenstion '%s'", path);
+      babl_log ("\n\tint babl_extension_init() function not found in extension '%s'", path);
       dlclose (dl_handle);
       return load_failed (babl);
     }
@@ -202,7 +202,8 @@
       return load_failed (babl);
     }
 
-  if (babl_db_insert (db, babl) == babl)
+  babl_db_insert (db, babl);
+  if (babl == babl_db_exist_by_name (db, path))
     {
       babl_set_extender (NULL);
       return babl;

Modified: trunk/babl/babl-fish-path.c
==============================================================================
--- trunk/babl/babl-fish-path.c	(original)
+++ trunk/babl/babl-fish-path.c	Sat Mar 29 19:02:20 2008
@@ -284,6 +284,15 @@
   char           *name = create_name (source, destination, 1);
   BablConversion *temp_chain[BABL_HARD_MAX_PATH_LENGTH];
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl_assert (BABL_IS_BABL (source));
   babl_assert (BABL_IS_BABL (destination));
 
@@ -329,12 +338,11 @@
       return NULL;
     }
 
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }
 
 static long

Modified: trunk/babl/babl-fish-reference.c
==============================================================================
--- trunk/babl/babl-fish-reference.c	(original)
+++ trunk/babl/babl-fish-reference.c	Sat Mar 29 19:02:20 2008
@@ -51,6 +51,15 @@
   Babl *babl = NULL;
   char *name = create_name (source, destination, 1);
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl_assert (BABL_IS_BABL (source));
   babl_assert (BABL_IS_BABL (destination));
 
@@ -71,12 +80,12 @@
   babl->fish.error       = 0.0;  /* assuming the provided reference conversions for types
                                     and models are as exact as possible
                                   */
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }
 
 

Modified: trunk/babl/babl-fish-simple.c
==============================================================================
--- trunk/babl/babl-fish-simple.c	(original)
+++ trunk/babl/babl-fish-simple.c	Sat Mar 29 19:02:20 2008
@@ -34,6 +34,15 @@
 
   name = create_name (conversion);
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = babl_malloc (sizeof (BablFishSimple) +
                       strlen (name) + 1);
   babl->class_type    = BABL_FISH_SIMPLE;
@@ -50,10 +59,9 @@
                                    reference, and babl fish reference only requests clean
                                    conversions */
 
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }

Modified: trunk/babl/babl-format.c
==============================================================================
--- trunk/babl/babl-format.c	(original)
+++ trunk/babl/babl-format.c	Sat Mar 29 19:02:20 2008
@@ -45,24 +45,25 @@
 {
   Babl *babl;
 
-  {
-    int i;
-    /* i is desintation position */
-    for (i = 0; i < model->components; i++)
-      {
-        int j;
-
-        for (j = 0; j < components; j++)
-          {
-            if (component[j] == model->component[i])
-              goto component_found;
-          }
-        babl_fatal ("matching source component for %s in model %s not found",
-                    model->component[i]->instance.name, model->instance.name);
-component_found:
-        ;
-      }
-  }
+  /* i is desintation position */
+  int i, j, component_found = 0;
+  for (i = 0; i < model->components; i++)
+    {
+      for (j = 0; j < components; j++)
+        {
+          if (component[j] == model->component[i])
+            {
+              component_found = 1;
+              break;
+            }  
+        }
+      if (!component_found) 
+        {
+          component_found = 0;
+          babl_fatal ("matching source component for %s in model %s not found",
+                      model->component[i]->instance.name, model->instance.name);
+        }
+    }
 
   /* allocate all memory in one chunk */
   babl = babl_malloc (sizeof (BablFormat) +
@@ -295,17 +296,28 @@
 
   va_end (varg);
 
-  babl = format_new (name ? name : create_name (model, components, component, type),
+  if (!name) 
+    name = create_name (model, components, component, type);
+
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+    
+  babl = format_new (name,
                      id,
                      planar, components, model,
                      component, sampling, type);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 int

Modified: trunk/babl/babl-model.c
==============================================================================
--- trunk/babl/babl-model.c	(original)
+++ trunk/babl/babl-model.c	Sat Mar 29 19:02:20 2008
@@ -161,14 +161,24 @@
 
   va_end (varg);
 
-  babl = model_new (create_name (name, components, component), id, components, component);
+  name = create_name (name, components, component);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
+  babl = model_new (name, id, components, component);
+
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 

Modified: trunk/babl/babl-type.c
==============================================================================
--- trunk/babl/babl-type.c	(original)
+++ trunk/babl/babl-type.c	Sat Mar 29 19:02:20 2008
@@ -128,14 +128,22 @@
 
   va_end (varg);
 
+  babl = babl_db_exist (db, id, first_arg);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = type_new (first_arg, id, bits);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]