[babl] Port all of babl to use use babl_set_destructor
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] Port all of babl to use use babl_set_destructor
- Date: Sun, 27 Jun 2010 16:32:36 +0000 (UTC)
commit 870eefc3bbc8ab6867c5f031707bcb096e103e08
Author: �yvind Kolås <pippin gimp org>
Date: Sun Jun 27 14:50:41 2010 +0100
Port all of babl to use use babl_set_destructor
Making all babl objects be free-able with babl_free means that overall
management code can be directly shared between the different
babl-classes.
babl/Makefile.am | 2 +-
babl/babl-class.h | 25 +++++----------------
babl/babl-classes.h | 2 +-
babl/babl-component.c | 9 -------
babl/babl-component.h | 2 +-
babl/babl-conversion.c | 8 ------
babl/babl-conversion.h | 2 +-
babl/babl-db.c | 34 +++++++++++++++++++---------
babl/babl-db.h | 3 --
babl/babl-extension.c | 56 +++++++++++++----------------------------------
babl/babl-extension.h | 4 +-
babl/babl-fish-path.c | 14 ++++++++++-
babl/babl-fish.c | 29 ------------------------
babl/babl-format.c | 13 +---------
babl/babl-format.h | 2 +-
babl/babl-hash-table.c | 23 ++++++++++---------
babl/babl-hash-table.h | 4 ---
babl/babl-image.c | 12 ----------
babl/babl-internal.h | 36 ++++++------------------------
babl/babl-list.c | 19 +++++++--------
babl/babl-list.h | 3 --
babl/babl-model.c | 11 ++++-----
babl/babl-model.h | 2 +-
babl/babl-sampling.c | 4 +--
babl/babl-sampling.h | 4 ++-
babl/babl-type.c | 12 ++++------
babl/babl-type.h | 2 +-
babl/babl.c | 48 ++++++++++++++++++++++++++--------------
28 files changed, 141 insertions(+), 244 deletions(-)
---
diff --git a/babl/Makefile.am b/babl/Makefile.am
index d62125c..12cd969 100644
--- a/babl/Makefile.am
+++ b/babl/Makefile.am
@@ -11,7 +11,6 @@ c_sources = \
babl-component.c \
babl-conversion.c \
babl-core.c \
- babl-cpuaccel.c \
babl-db.c \
babl-extension.c \
babl-fish-path.c \
@@ -32,6 +31,7 @@ c_sources = \
babl-sanity.c \
babl-type.c \
babl-util.c \
+ babl-cpuaccel.c \
babl-version.c
h_sources = \
diff --git a/babl/babl-class.h b/babl/babl-class.h
index 534c476..4e9bbaf 100644
--- a/babl/babl-class.h
+++ b/babl/babl-class.h
@@ -33,25 +33,12 @@ typedef int (*BablEachFunction) (Babl *entry,
* to be iterated over, common functionality is defined through these
* macros.
*/
-#define BABL_CLASS_DECLARE(klass) \
- \
-Babl * babl_##klass##_from_id (int id); \
-void babl_##klass##_class_init (void); \
-void babl_##klass##_class_destroy (void); \
-void babl_##klass##_class_for_each (BablEachFunction each_fun, \
- void *user_data)
-
-/* If a class is declared as a "named class" it means it is a class
- * that has a specific name connected to it, that also allows defining
- * a new instance. These classes share common functionality with the
- * non_name classes but have two extra methods, the means to lookup by
- * name, as well as to create new named objects that later can be
- * looked up. These methods are babl_klass() babl_klass_new() but they
- * are declared outside of this macro.
- */
-#define BABL_NAMED_CLASS_DECLARE(klass) \
-BABL_CLASS_DECLARE (klass)
-
+#define BABL_CLASS_DECLARE(klass) \
+ \
+BablDb * babl_##klass##_db (void); \
+Babl * babl_##klass##_from_id (int id); \
+void babl_##klass##_class_for_each (BablEachFunction each_fun, \
+ void *user_data)
/* common header for any item inserted into database, the actual
* implementation of babl-instance is in babl-internal
diff --git a/babl/babl-classes.h b/babl/babl-classes.h
index eeaa262..0427c30 100644
--- a/babl/babl-classes.h
+++ b/babl/babl-classes.h
@@ -20,6 +20,7 @@
#define _BABL_CLASSES_H
#include "babl-class.h"
+#include "babl-db.h"
/* magic number used at the start of all babl objects, used to do
* differentiation in polymorphic functions. (as well as manual type
@@ -54,7 +55,6 @@ enum {
BABL_SKY
};
-
#include "babl-type.h"
#include "babl-sampling.h"
#include "babl-component.h"
diff --git a/babl/babl-component.c b/babl/babl-component.c
index 301e64d..54a06b3 100644
--- a/babl/babl-component.c
+++ b/babl/babl-component.c
@@ -23,15 +23,6 @@
#include <stdarg.h>
-
-static int
-each_babl_component_destroy (Babl *babl,
- void *data)
-{
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
static Babl *
component_new (const char *name,
int id,
diff --git a/babl/babl-component.h b/babl/babl-component.h
index df9d719..2c45cdc 100644
--- a/babl/babl-component.h
+++ b/babl/babl-component.h
@@ -22,7 +22,7 @@
/****************************************************************/
/* BablComponent */
-BABL_NAMED_CLASS_DECLARE (component);
+BABL_CLASS_DECLARE (component);
typedef struct
diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c
index 422e2dd..ea6be81 100644
--- a/babl/babl-conversion.c
+++ b/babl/babl-conversion.c
@@ -24,14 +24,6 @@
#include "babl-internal.h"
#include "babl-db.h"
-static int
-each_babl_conversion_destroy (Babl *babl,
- void *data)
-{
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
static Babl *
conversion_new (const char *name,
int id,
diff --git a/babl/babl-conversion.h b/babl/babl-conversion.h
index d231b64..fbbb279 100644
--- a/babl/babl-conversion.h
+++ b/babl/babl-conversion.h
@@ -19,7 +19,7 @@
#ifndef _BABL_CONVERSION_H
#define _BABL_CONVERSION_H
-BABL_NAMED_CLASS_DECLARE (conversion);
+BABL_CLASS_DECLARE (conversion);
Babl * babl_conversion (const char *name);
diff --git a/babl/babl-db.c b/babl/babl-db.c
index 7825cc0..fed9a05 100644
--- a/babl/babl-db.c
+++ b/babl/babl-db.c
@@ -55,10 +55,33 @@ db_hash_by_id (BablHashTable *htab, Babl *item)
return babl_hash_by_int (htab, item->instance.id);
}
+static int
+each_free (Babl *data,
+ void *foo)
+{
+ babl_free (data);
+ return 0;
+}
+
+static int
+babl_db_destroy (void *data)
+{
+ BablDb *db = data;
+ babl_assert (db);
+
+ babl_db_each (db, each_free, NULL);
+ babl_mutex_destroy (db->mutex);
+ babl_free (db->name_hash);
+ babl_free (db->id_hash);
+ babl_free (db->babl_list);
+ return 0;
+}
+
BablDb *
babl_db_init (void)
{
BablDb *db = babl_calloc (sizeof (BablDb), 1);
+ babl_set_destructor (db, babl_db_destroy);
db->name_hash = babl_hash_table_init (db_hash_by_name, db_find_by_name);
db->id_hash = babl_hash_table_init (db_hash_by_id, db_find_by_id);
@@ -68,17 +91,6 @@ babl_db_init (void)
return db;
}
-void
-babl_db_destroy (BablDb *db)
-{
- babl_assert (db);
-
- babl_mutex_destroy (db->mutex);
- babl_hash_table_destroy (db->name_hash);
- babl_hash_table_destroy (db->id_hash);
- babl_list_destroy (db->babl_list);
- babl_free (db);
-}
Babl *
babl_db_find (BablDb *db,
diff --git a/babl/babl-db.h b/babl/babl-db.h
index 6b4e6ff..a07a17b 100644
--- a/babl/babl-db.h
+++ b/babl/babl-db.h
@@ -43,9 +43,6 @@ BablDb *
babl_db_init (void);
void
-babl_db_destroy (BablDb *db);
-
-void
babl_db_each (BablDb *db,
BablEachFunction each_fun,
void *user_data);
diff --git a/babl/babl-extension.c b/babl/babl-extension.c
index 1628d03..1973588 100644
--- a/babl/babl-extension.c
+++ b/babl/babl-extension.c
@@ -20,10 +20,6 @@
#include "config.h"
-#define BABL_PATH LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
-
-#define BABL_INIT_HOOK init_hook ();
-#define BABL_DESTROY_HOOK destroy_hook ();
#ifdef BABL_DYNAMIC_EXTENSIONS
/* must be defined before inclusion of babl-internal.h */
@@ -37,8 +33,6 @@
#include <string.h>
#include <stdarg.h>
-static int each_babl_extension_destroy (Babl *babl, void *data);
-
static Babl *babl_extension_current_extender = NULL;
Babl *
@@ -55,6 +49,9 @@ babl_set_extender (Babl *new_extender)
babl_extension_current_extender = new_extender;
}
+static int
+babl_extension_destroy (void *data);
+
static Babl *
extension_new (const char *path,
void *dl_handle,
@@ -63,6 +60,7 @@ extension_new (const char *path,
Babl *babl;
babl = babl_malloc (sizeof (BablExtension) + strlen (path) + 1);
+ babl_set_destructor (babl, babl_extension_destroy);
babl->instance.name = (char *) babl + sizeof (BablExtension);
strcpy (babl->instance.name, path);
babl->instance.id = 0;
@@ -93,7 +91,11 @@ babl_extension_base (void)
void (*destroy)(void) = NULL;
if (!db)
- db = babl_db_init ();
+ {
+ babl_extension_quiet_log ();
+ babl_set_extender (NULL);
+ db = babl_db_init ();
+ }
babl = extension_new ("BablBase",
dl_handle,
destroy);
@@ -111,15 +113,7 @@ babl_extension_base (void)
return babl;
}
-static void
-init_hook (void)
-{
- babl_extension_quiet_log ();
- babl_set_extender (NULL);
-}
-
-static void
-destroy_hook (void)
+void babl_extension_deinit (void)
{
babl_free (babl_quiet);
babl_quiet = NULL;
@@ -187,7 +181,7 @@ load_failed (Babl *babl)
{
if (babl)
{
- each_babl_extension_destroy (babl, NULL);
+ babl_free (babl);
}
babl_set_extender (NULL);
return NULL;
@@ -278,17 +272,6 @@ babl_extension_load_dir (const char *base_path)
}
}
-static const char *
-babl_dir_list (void)
-{
- const char *ret;
-
- ret = getenv ("BABL_PATH");
- if (!ret)
- ret = BABL_PATH;
- return ret;
-}
-
static char *
expand_path (char *path)
{
@@ -325,7 +308,7 @@ expand_path (char *path)
/* parse the provided colon seperated list of paths to search
*/
-static void
+void
babl_extension_load_dir_list (const char *dir_list)
{
int eos = 0;
@@ -364,25 +347,18 @@ babl_extension_load_dir_list (const char *dir_list)
babl_free (path);
}
-static void
-dynamic_init_hook (void)
-{
- babl_extension_load_dir_list (babl_dir_list ());
-}
-
#endif
+
static int
-each_babl_extension_destroy (Babl *babl,
- void *data)
+babl_extension_destroy (void *data)
{
+ Babl *babl = data;
if (babl->extension.destroy)
babl->extension.destroy ();
if (babl->extension.dl_handle)
dlclose (babl->extension.dl_handle);
-
- babl_free (babl);
- return 0; /* continue iterating */
+ return 0;
}
BABL_CLASS_IMPLEMENT (extension)
diff --git a/babl/babl-extension.h b/babl/babl-extension.h
index cd7f831..4c2610a 100644
--- a/babl/babl-extension.h
+++ b/babl/babl-extension.h
@@ -22,13 +22,13 @@
/****************************************************************/
/* BablExtension */
-BABL_NAMED_CLASS_DECLARE (extension);
+BABL_CLASS_DECLARE (extension);
/*
* BablExtension objects are only used internally in babl.
*/
Babl * babl_extension (const char *name);
-
+void babl_extension_load_dir_list (const char *dir_list);
typedef struct
{
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index 2622cb3..da5e0b0 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -236,6 +236,16 @@ create_name (char *buf,
return buf;
}
+static int
+babl_fish_path_destroy (void *data)
+{
+ Babl *babl=data;
+ if (babl->fish_path.conversion_list)
+ babl_free (babl->fish_path.conversion_list);
+ babl->fish_path.conversion_list = NULL;
+ return 0;
+}
+
Babl *
babl_fish_path (const Babl *source,
const Babl *destination)
@@ -255,6 +265,7 @@ babl_fish_path (const Babl *source,
babl = babl_calloc (1, sizeof (BablFishPath) +
strlen (name) + 1);
+ babl_set_destructor (babl, babl_fish_path_destroy);
babl->class_type = BABL_FISH_PATH;
babl->instance.id = babl_fish_get_id (source, destination);
@@ -284,12 +295,11 @@ babl_fish_path (const Babl *source,
get_conversion_path (&pc, (Babl *) source, 0, max_path_length ());
babl_mutex_unlock (babl_format_mutex);
- babl_list_destroy (pc.current_path);
+ babl_free (pc.current_path);
}
if (babl_list_size (babl->fish_path.conversion_list) == 0)
{
- babl_list_destroy (babl->fish_path.conversion_list);
babl_free (babl);
return NULL;
}
diff --git a/babl/babl-fish.c b/babl/babl-fish.c
index a09efaf..dad518b 100644
--- a/babl/babl-fish.c
+++ b/babl/babl-fish.c
@@ -22,7 +22,6 @@
#include <string.h>
#include <stdarg.h>
-
typedef struct _BablFindFish BablFindFish;
typedef struct _BablFindFish
@@ -49,14 +48,6 @@ find_memcpy_fish (Babl *item,
void *data);
static int
-each_babl_fish_destroy (Babl *babl,
- void *data);
-
-
-/* ====================================== */
-
-
-static int
find_fish_path (Babl *item,
void *data)
{
@@ -145,14 +136,6 @@ babl_fish_get_id (const Babl *source,
return id;
}
-BablDb *
-babl_fish_db (void)
-{
- if (!db)
- db = babl_db_init ();
- return db;
-}
-
Babl *
babl_fish (const void *source,
const void *destination)
@@ -278,16 +261,4 @@ babl_fish (const void *source,
}
}
-
-
-static int
-each_babl_fish_destroy (Babl *babl,
- void *data)
-{
- if (babl->class_type == BABL_FISH_PATH)
- babl_list_destroy (babl->fish_path.conversion_list);
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
BABL_CLASS_MINIMAL_IMPLEMENT (fish);
diff --git a/babl/babl-format.c b/babl/babl-format.c
index 227dab0..4c75d3c 100644
--- a/babl/babl-format.c
+++ b/babl/babl-format.c
@@ -34,20 +34,11 @@ static int babl_format_destruct (void *babl)
babl_free (format->image_template);
format->image_template = NULL;
}
+ if (format->from_list)
+ babl_free (format->from_list);
return 0;
}
-static int
-each_babl_format_destroy (Babl *babl,
- void *data)
-{
- if (babl->format.from_list)
- babl_list_destroy (babl->format.from_list);
- babl_free (babl);
-
- return 0; /* continue iterating */
-}
-
static Babl *
format_new (const char *name,
int id,
diff --git a/babl/babl-format.h b/babl/babl-format.h
index f130bcd..fb8dfac 100644
--- a/babl/babl-format.h
+++ b/babl/babl-format.h
@@ -19,7 +19,7 @@
#ifndef _BABL_FORMAT_H
#define _BABL_FORMAT_H
-BABL_NAMED_CLASS_DECLARE (format);
+BABL_CLASS_DECLARE (format);
typedef struct
{
diff --git a/babl/babl-hash-table.c b/babl/babl-hash-table.c
index 8afc3aa..99b7427 100644
--- a/babl/babl-hash-table.c
+++ b/babl/babl-hash-table.c
@@ -143,6 +143,17 @@ babl_hash_table_size (BablHashTable *htab)
return htab->mask + 1;
}
+
+static int
+babl_hash_table_destroy (void *data)
+{
+ BablHashTable *htab = data;
+ babl_free (htab->data_table);
+ babl_free (htab->chain_table);
+ return 0;
+}
+
+
BablHashTable *
babl_hash_table_init (BablHashValFunction hfunc,
BablHashFindFunction ffunc)
@@ -153,7 +164,7 @@ babl_hash_table_init (BablHashValFunction hfunc,
babl_assert(ffunc);
htab = babl_calloc (sizeof (BablHashTable), 1);
- babl_assert (htab);
+ babl_set_destructor (htab, babl_hash_table_destroy);
htab->data_table = NULL;
htab->chain_table = NULL;
@@ -171,16 +182,6 @@ babl_hash_table_init (BablHashValFunction hfunc,
return htab;
}
-void
-babl_hash_table_destroy (BablHashTable *htab)
-{
- babl_assert (htab);
-
- babl_free (htab->data_table);
- babl_free (htab->chain_table);
- babl_free (htab);
-}
-
int
babl_hash_table_insert (BablHashTable *htab,
Babl *item)
diff --git a/babl/babl-hash-table.h b/babl/babl-hash-table.h
index ec546f3..f56d02f 100644
--- a/babl/babl-hash-table.h
+++ b/babl/babl-hash-table.h
@@ -65,8 +65,4 @@ babl_hash_table_find (BablHashTable *htab,
BablHashFindFunction find_func,
void *data);
-void
-babl_hash_table_destroy (BablHashTable *htab);
-
-
#endif
diff --git a/babl/babl-image.c b/babl/babl-image.c
index ed28c89..631fe6d 100644
--- a/babl/babl-image.c
+++ b/babl/babl-image.c
@@ -237,15 +237,3 @@ babl_image_new (void *first,
babl = image_new (format, model, components, component, sampling, type, data, pitch, stride);
return babl;
}
-
-void
-babl_image_class_destroy (void)
-{
- /* nothing to do */
-}
-
-void
-babl_image_class_init (void)
-{
- /* nothing to do */
-}
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index 70538e9..1f5fe23 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -40,9 +40,9 @@
#include "babl.h"
#define _BABL_INTERNAL_H
-#include "babl-class.h"
#include "babl-classes.h"
#include "babl-introspect.h"
+#include "babl-class.h"
#include "babl-list.h"
#include "babl-hash-table.h"
#include "babl-db.h"
@@ -80,13 +80,13 @@ Babl * babl_extender (void);
void babl_set_extender (Babl *new_extender);
Babl * babl_extension_quiet_log (void);
+void babl_extension_deinit (void);
long babl_fish_reference_process (Babl *babl,
BablImage *source,
BablImage *destination,
long n);
-BablDb * babl_fish_db (void);
Babl * babl_fish_reference (const Babl *source,
const Babl *destination);
Babl * babl_fish_simple (BablConversion *conversion);
@@ -243,19 +243,6 @@ void babl_internal_init (void);
void babl_internal_destroy (void);
-#ifndef BABL_INIT_HOOK
-#define BABL_INIT_HOOK
-#endif
-#ifndef BABL_PRE_INIT_HOOK
-#define BABL_PRE_INIT_HOOK
-#endif
-#ifndef BABL_DESTROY_HOOK
-#define BABL_DESTROY_HOOK
-#endif
-#ifndef BABL_DESTROY_PRE_HOOK
-#define BABL_DESTROY_PRE_HOOK
-#endif
-
/* this template is expanded in the files including babl-internal.h,
* generating code, the declarations for these functions are found in
* the BABL_CLASS expansions done in babl.h as well, thus babl.h needs
@@ -263,22 +250,13 @@ void babl_internal_destroy (void);
*/
#define BABL_CLASS_MINIMAL_IMPLEMENT(klass) \
-void \
-babl_##klass##_class_init (void) \
+ \
+BablDb * \
+babl_##klass##_db (void) \
{ \
- BABL_PRE_INIT_HOOK; \
if (!db) \
db=babl_db_init (); \
- BABL_INIT_HOOK; \
-} \
- \
-void \
-babl_##klass##_class_destroy (void) \
-{ \
- BABL_DESTROY_PRE_HOOK; \
- babl_db_each (db,each_babl_##klass##_destroy, NULL); \
- babl_db_destroy (db); \
- BABL_DESTROY_HOOK; \
+ return db; \
} \
\
void \
@@ -319,7 +297,7 @@ babl_##klass##_from_id (int id) \
babl_fatal ("%s(%i): not found", G_STRFUNC, id); \
} \
return babl; \
-}
+} \
#define BABL(obj) ((Babl*)(obj))
diff --git a/babl/babl-list.c b/babl/babl-list.c
index 2cf1251..49647bb 100644
--- a/babl/babl-list.c
+++ b/babl/babl-list.c
@@ -31,12 +31,20 @@ babl_list_init (void)
return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE);
}
+static int
+babl_list_destroy (void *data)
+{
+ BablList *list = data;
+ babl_free (list->items);
+ return 0;
+}
+
BablList *
babl_list_init_with_size (int initial_size)
{
BablList *list = babl_calloc (sizeof (BablList), 1);
- babl_assert (list);
+ babl_set_destructor (list, babl_list_destroy);
if (initial_size == 0)
initial_size = 1;
@@ -52,15 +60,6 @@ babl_list_init_with_size (int initial_size)
}
void
-babl_list_destroy (BablList *list)
-{
- babl_assert (list);
-
- babl_free (list->items);
- babl_free (list);
-}
-
-void
babl_list_insert_last (BablList *list,
Babl *item)
{
diff --git a/babl/babl-list.h b/babl/babl-list.h
index c9c64e8..60cdf6e 100644
--- a/babl/babl-list.h
+++ b/babl/babl-list.h
@@ -36,9 +36,6 @@ babl_list_init (void);
BablList *
babl_list_init_with_size (int initial_size);
-void
-babl_list_destroy (BablList *list);
-
int
babl_list_size (BablList *list);
diff --git a/babl/babl-model.c b/babl/babl-model.c
index 2b26e91..eb7eee4 100644
--- a/babl/babl-model.c
+++ b/babl/babl-model.c
@@ -23,15 +23,13 @@
#include "babl-internal.h"
#include "babl-db.h"
-
static int
-each_babl_model_destroy (Babl *babl,
- void *data)
+babl_model_destroy (void *data)
{
+ Babl *babl = data;
if (babl->model.from_list)
- babl_list_destroy (babl->model.from_list);
- babl_free (babl);
- return 0; /* continue iterating */
+ babl_free (babl->model.from_list);
+ return 0;
}
static char *
@@ -60,6 +58,7 @@ model_new (const char *name,
babl = babl_malloc (sizeof (BablModel) +
sizeof (BablComponent *) * (components) +
strlen (name) + 1);
+ babl_set_destructor (babl, babl_model_destroy);
babl->model.component = (void *) (((char *) babl) + sizeof (BablModel));
babl->instance.name = (void *) (((char *) babl->model.component) + sizeof (BablComponent *) * (components));
diff --git a/babl/babl-model.h b/babl/babl-model.h
index 617c91c..0a4786b 100644
--- a/babl/babl-model.h
+++ b/babl/babl-model.h
@@ -19,7 +19,7 @@
#ifndef _BABL_MODEL_H
#define _BABL_MODEL_H
-BABL_NAMED_CLASS_DECLARE (model);
+BABL_CLASS_DECLARE (model);
typedef struct
{
diff --git a/babl/babl-sampling.c b/babl/babl-sampling.c
index d3fa637..a3fa3a6 100644
--- a/babl/babl-sampling.c
+++ b/babl/babl-sampling.c
@@ -47,9 +47,7 @@ static int
each_babl_sampling_destroy (Babl *babl,
void *data)
{
- if (babl->sampling.from_list)
- babl_list_destroy (babl->sampling.from_list);
- return 0; /* continue iterating */
+ return 0;
}
void
diff --git a/babl/babl-sampling.h b/babl/babl-sampling.h
index 869e3de..82e6d15 100644
--- a/babl/babl-sampling.h
+++ b/babl/babl-sampling.h
@@ -24,10 +24,12 @@ BABL_CLASS_DECLARE (sampling);
typedef struct
{
BablInstance instance;
- BablList *from_list;
int horizontal;
int vertical;
char name[4];
} BablSampling;
+void
+babl_sampling_class_init (void);
+
#endif
diff --git a/babl/babl-type.c b/babl/babl-type.c
index c150e2c..467b33f 100644
--- a/babl/babl-type.c
+++ b/babl/babl-type.c
@@ -24,18 +24,15 @@
#include "babl-internal.h"
#include "babl-db.h"
-
static int
-each_babl_type_destroy (Babl *babl,
- void *data)
+babl_type_destroy (void *data)
{
+ Babl *babl = data;
if (babl->type.from_list)
- babl_list_destroy (babl->type.from_list);
- babl_free (babl);
- return 0; /* continue iterating */
+ babl_free (babl->type.from_list);
+ return 0;
}
-
static Babl *
type_new (const char *name,
int id,
@@ -47,6 +44,7 @@ type_new (const char *name,
babl_assert (bits % 8 == 0);
babl = babl_malloc (sizeof (BablType) + strlen (name) + 1);
+ babl_set_destructor (babl, babl_type_destroy);
babl->instance.name = (void *) ((char *) babl + sizeof (BablType));
babl->class_type = BABL_TYPE;
babl->instance.id = id;
diff --git a/babl/babl-type.h b/babl/babl-type.h
index 10e4040..8030fe5 100644
--- a/babl/babl-type.h
+++ b/babl/babl-type.h
@@ -19,7 +19,7 @@
#ifndef _BABL_TYPE_H
#define _BABL_TYPE_H
-BABL_NAMED_CLASS_DECLARE (type);
+BABL_CLASS_DECLARE (type);
typedef struct
{
diff --git a/babl/babl.c b/babl/babl.c
index 6386f60..bc3f7de 100644
--- a/babl/babl.c
+++ b/babl/babl.c
@@ -21,6 +21,19 @@
static int ref_count = 0;
+#define BABL_PATH LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
+
+static const char *
+babl_dir_list (void)
+{
+ const char *ret;
+
+ ret = getenv ("BABL_PATH");
+ if (!ret)
+ ret = BABL_PATH;
+ return ret;
+}
+
void
babl_init (void)
{
@@ -29,20 +42,20 @@ babl_init (void)
if (ref_count++ == 0)
{
babl_internal_init ();
- babl_type_class_init ();
babl_sampling_class_init ();
- babl_component_class_init ();
- babl_model_class_init ();
- babl_format_class_init ();
- babl_conversion_class_init ();
+ babl_type_db ();
+ babl_component_db ();
+ babl_model_db ();
+ babl_format_db ();
+ babl_conversion_db ();
+ babl_extension_db ();
+ babl_fish_db ();
babl_core_init ();
babl_sanity ();
babl_extension_base ();
babl_sanity ();
- babl_extension_class_init ();
- babl_sanity ();
- babl_fish_class_init ();
- babl_sanity ();
+
+ babl_extension_load_dir_list (babl_dir_list ());
}
}
@@ -63,14 +76,15 @@ babl_exit (void)
}
}
- babl_extension_class_destroy ();
- babl_fish_class_destroy ();
- babl_conversion_class_destroy ();
- babl_format_class_destroy ();
- babl_model_class_destroy ();
- babl_component_class_destroy ();
- babl_sampling_class_destroy ();
- babl_type_class_destroy ();
+ babl_extension_deinit ();
+ babl_free (babl_extension_db ());;
+ babl_free (babl_fish_db ());;
+ babl_free (babl_conversion_db ());;
+ babl_free (babl_format_db ());;
+ babl_free (babl_model_db ());;
+ babl_free (babl_component_db ());;
+ babl_free (babl_type_db ());;
+
babl_internal_destroy ();
#if BABL_DEBUG_MEM
babl_memory_sanity ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]