From: Lutz M. <lu...@us...> - 2004-10-04 06:27:13
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10678/libexif Modified Files: exif-content.c exif-data.c exif-entry.c exif-loader.c exif-log.c exif-log.h exif-mem.c exif-mem.h exif-mnote-data-priv.h exif-mnote-data.c Log Message: 2004-10-04 Lutz Mueller <lu...@us...> * libexif/*: Finish replaceable memory-management. Index: exif-log.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-log.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- exif-log.c 9 Sep 2004 06:27:21 -0000 1.3 +++ exif-log.c 4 Oct 2004 06:26:59 -0000 1.4 @@ -30,6 +30,8 @@ ExifLogFunc func; void *data; + + ExifMem *mem; }; static struct { @@ -65,15 +67,28 @@ } ExifLog * -exif_log_new (void) +exif_log_new_mem (ExifMem *mem) { ExifLog *log; - log = malloc (sizeof (ExifLog)); + log = exif_mem_alloc (mem, sizeof (ExifLog)); if (!log) return NULL; - memset (log, 0, sizeof (ExifLog)); log->ref_count = 1; + log->mem = mem; + exif_mem_ref (mem); + + return log; +} + +ExifLog * +exif_log_new (void) +{ + ExifMem *mem = exif_mem_new_default (); + ExifLog *log = exif_log_new_mem (mem); + + exif_mem_unref (mem); + return log; } @@ -96,8 +111,8 @@ exif_log_free (ExifLog *log) { if (!log) return; - memset (log, 0, sizeof (ExifLog)); - free (log); + + exif_mem_free (log->mem, log); } void Index: exif-mnote-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- exif-mnote-data.c 13 Jul 2004 15:16:37 -0000 1.7 +++ exif-mnote-data.c 4 Oct 2004 06:26:59 -0000 1.8 @@ -31,14 +31,17 @@ }; void -exif_mnote_data_construct (ExifMnoteData *d) +exif_mnote_data_construct (ExifMnoteData *d, ExifMem *mem) { - if (!d) return; + if (!d || !mem) return; if (d->priv) return; - d->priv = malloc (sizeof (ExifMnoteDataPriv)); + d->priv = exif_mem_alloc (mem, sizeof (ExifMnoteDataPriv)); if (!d->priv) return; - memset (d->priv, 0, sizeof (ExifMnoteDataPriv)); + d->priv->ref_count = 1; + + d->mem = mem; + exif_mem_ref (mem); } void @@ -53,9 +56,11 @@ if (!d) return; if (d->priv) { if (d->methods.free) d->methods.free (d); - free (d->priv); + exif_mem_free (d->mem, d->priv); d->priv = NULL; } + exif_mem_unref (d->mem); + d->mem = NULL; } void Index: exif-content.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-content.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- exif-content.c 2 Oct 2004 05:55:25 -0000 1.11 +++ exif-content.c 4 Oct 2004 06:26:59 -0000 1.12 @@ -39,11 +39,9 @@ ExifContent * exif_content_new (void) { - ExifContent *content; - ExifMem *mem = exif_mem_new (exif_mem_alloc_func, - exif_mem_realloc_func, exif_mem_free_func); + ExifMem *mem = exif_mem_new_default (); + ExifContent *content = exif_content_new_mem (mem); - content = exif_content_new_mem (mem); exif_mem_unref (mem); return content; Index: exif-mnote-data-priv.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data-priv.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- exif-mnote-data-priv.h 13 Jul 2004 15:16:37 -0000 1.6 +++ exif-mnote-data-priv.h 4 Oct 2004 06:26:59 -0000 1.7 @@ -60,9 +60,12 @@ /* Logging */ ExifLog *log; + + /* Memory management */ + ExifMem *mem; }; -void exif_mnote_data_construct (ExifMnoteData *); +void exif_mnote_data_construct (ExifMnoteData *, ExifMem *mem); void exif_mnote_data_set_byte_order (ExifMnoteData *, ExifByteOrder); void exif_mnote_data_set_offset (ExifMnoteData *, unsigned int); Index: exif-loader.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-loader.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- exif-loader.c 2 Oct 2004 05:55:26 -0000 1.11 +++ exif-loader.c 4 Oct 2004 06:26:59 -0000 1.12 @@ -183,11 +183,9 @@ ExifLoader * exif_loader_new (void) { - ExifLoader *l; - ExifMem *mem = exif_mem_new (exif_mem_alloc_func, - exif_mem_realloc_func, exif_mem_free_func); + ExifMem *mem = exif_mem_new_default (); + ExifLoader *l = exif_loader_new_mem (mem); - l = exif_loader_new_mem (mem); exif_mem_unref (mem); return l; Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- exif-data.c 2 Oct 2004 05:55:25 -0000 1.49 +++ exif-data.c 4 Oct 2004 06:26:59 -0000 1.50 @@ -82,11 +82,9 @@ ExifData * exif_data_new (void) { - ExifData *d; - ExifMem *mem = exif_mem_new (exif_mem_alloc_func, - exif_mem_realloc_func, exif_mem_free_func); + ExifMem *mem = exif_mem_new_default (); + ExifData *d = exif_data_new_mem (mem); - d = exif_data_new_mem (mem); exif_mem_unref (mem); return d; @@ -705,7 +703,7 @@ /* Olympus & Nikon */ if ((e->size >= 5) && (!memcmp (e->data, "OLYMP", 5) || !memcmp (e->data, "Nikon", 5))) { - data->priv->md = exif_mnote_data_olympus_new (); + data->priv->md = exif_mnote_data_olympus_new (data->priv->mem); } else { char value[7]; em = exif_data_get_entry (data, EXIF_TAG_MAKE); @@ -713,9 +711,9 @@ if ((e->size >= 2) && (e->data[0] == 0x00) && (e->data[1] == 0x1b)) { if (em && !strncasecmp (exif_entry_get_value (em, value, sizeof(value)), "Nikon", 5)) { - data->priv->md = exif_mnote_data_olympus_new (); + data->priv->md = exif_mnote_data_olympus_new (data->priv->mem); } else { - data->priv->md = exif_mnote_data_pentax_new (); + data->priv->md = exif_mnote_data_pentax_new (data->priv->mem); } } else { @@ -723,7 +721,7 @@ if (em) { if (!strcmp (exif_entry_get_value (em, value, sizeof(value)), "Canon")) - data->priv->md = exif_mnote_data_canon_new (); + data->priv->md = exif_mnote_data_canon_new (data->priv->mem); } } } Index: exif-log.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-log.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- exif-log.h 12 Sep 2004 19:52:23 -0000 1.4 +++ exif-log.h 4 Oct 2004 06:26:59 -0000 1.5 @@ -25,14 +25,16 @@ extern "C" { #endif /* __cplusplus */ +#include <libexif/exif-mem.h> #include <stdarg.h> typedef struct _ExifLog ExifLog; -ExifLog *exif_log_new (void); -void exif_log_ref (ExifLog *log); -void exif_log_unref (ExifLog *log); -void exif_log_free (ExifLog *log); +ExifLog *exif_log_new (void); +ExifLog *exif_log_new_mem (ExifMem *); +void exif_log_ref (ExifLog *log); +void exif_log_unref (ExifLog *log); +void exif_log_free (ExifLog *log); typedef enum { EXIF_LOG_CODE_NONE, Index: exif-entry.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-entry.c,v retrieving revision 1.65 retrieving revision 1.66 diff -u -d -r1.65 -r1.66 --- exif-entry.c 2 Oct 2004 05:55:25 -0000 1.65 +++ exif-entry.c 4 Oct 2004 06:26:59 -0000 1.66 @@ -98,11 +98,9 @@ ExifEntry * exif_entry_new (void) { - ExifEntry *e; - ExifMem *mem = exif_mem_new (exif_mem_alloc_func, - exif_mem_realloc_func, exif_mem_free_func); + ExifMem *mem = exif_mem_new_default (); + ExifEntry *e = exif_entry_new_mem (mem); - e = exif_entry_new_mem (mem); exif_mem_unref (mem); return e; Index: exif-mem.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-mem.h 2 Oct 2004 05:55:26 -0000 1.1 +++ exif-mem.h 4 Oct 2004 06:26:59 -0000 1.2 @@ -43,9 +43,7 @@ void exif_mem_free (ExifMem *, void *); /* For your convenience */ -void *exif_mem_alloc_func (ExifLong); -void *exif_mem_realloc_func (void *, ExifLong); -void exif_mem_free_func (void *); +ExifMem *exif_mem_new_default (void); #ifdef __cplusplus } Index: exif-mem.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mem.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-mem.c 2 Oct 2004 05:55:26 -0000 1.1 +++ exif-mem.c 4 Oct 2004 06:26:59 -0000 1.2 @@ -9,19 +9,19 @@ ExifMemFreeFunc free_func; }; -void * +static void * exif_mem_alloc_func (ExifLong ds) { return calloc ((size_t) ds, 1); } -void * +static void * exif_mem_realloc_func (void *d, ExifLong ds) { return realloc (d, (size_t) ds); } -void +static void exif_mem_free_func (void *d) { free (d); @@ -86,3 +86,10 @@ { return (mem && mem->realloc_func) ? mem->realloc_func (d, ds) : NULL; } + +ExifMem * +exif_mem_new_default (void) +{ + return exif_mem_new (exif_mem_alloc_func, exif_mem_realloc_func, + exif_mem_free_func); +} |