add 'lumiera_free' as replacement for 'free'

lumiera_free() is for now just a static inline wraper around free()
Later this makes it easier to hook in some resource managing functions
or a Garbage Collector in.

Replaced all current uses of free()
This commit is contained in:
Christian Thaeter 2008-08-07 05:40:26 +02:00
parent f5df65b0a1
commit 12feb6e7b8
6 changed files with 25 additions and 11 deletions

View file

@ -50,7 +50,7 @@ lumiera_file_destroy (LumieraFile self)
{
TRACE (file);
lumiera_filedescriptor_release (self->descriptor);
free ((void*)self->name);
lumiera_free ((void*)self->name);
return self;
}
@ -67,7 +67,7 @@ void
lumiera_file_delete (LumieraFile self)
{
TRACE (file);
free (lumiera_file_destroy (self));
lumiera_free (lumiera_file_destroy (self));
}

View file

@ -234,7 +234,7 @@ lumiera_filedescriptor_delete (LumieraFiledescriptor self)
TODO ("release filehandle");
lumiera_mutex_destroy (&self->lock);
free (self);
lumiera_free (self);
lumiera_mutexacquirer_unlock (&registry_lock);
}

View file

@ -58,7 +58,7 @@ lumiera_filehandlecache_delete (void)
RESOURCE_FORGET (filehandlecache, lumiera_fhcache->rh);
lumiera_mrucache_destroy (&lumiera_fhcache->cache);
lumiera_mutex_destroy (&lumiera_fhcache->lock);
free (lumiera_fhcache);
lumiera_free (lumiera_fhcache);
lumiera_fhcache = NULL;
}
}

View file

@ -19,6 +19,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "lib/safeclib.h"
#include "lib/mrucache.h"
@ -39,9 +40,9 @@ lumiera_mrucache_destroy (LumieraMruCache self)
{
llist_unlink (node);
if (self->destructor_cb)
free (self->destructor_cb (node));
lumiera_free (self->destructor_cb (node));
else
free (node);
lumiera_free (node);
}
self->cached = 0;
return self;
@ -52,7 +53,7 @@ lumiera_mrucache_age (LumieraMruCache self, int nelem)
{
REQUIRE (self);
while (self->cached && nelem--)
free (lumiera_mrucache_pop (self));
lumiera_free (lumiera_mrucache_pop (self));
return nelem;
}

View file

@ -18,7 +18,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "error.h"
#include "lib/error.h"
#include "lib/safeclib.h"
#include <string.h>
#include <stdlib.h>
@ -114,8 +115,8 @@ lumiera_tmpbuf_freeall (void)
{
pthread_setspecific (lumiera_tmpbuf_tls_key, NULL);
for (int idx = 0; idx < 64; ++idx)
free (buf->buffers[idx]);
free (buf);
lumiera_free (buf->buffers[idx]);
lumiera_free (buf);
}
}
@ -133,7 +134,7 @@ lumiera_tmpbuf_provide (size_t size)
if (buf->sizes[buf->idx] < size || buf->sizes[buf->idx] > 8*size)
{
free (buf->buffers[buf->idx]);
lumiera_free (buf->buffers[buf->idx]);
buf->sizes[buf->idx] = (size+4*sizeof(long)) & ~(4*sizeof(long)-1);
buf->buffers[buf->idx] = lumiera_malloc (buf->sizes[buf->idx]);
}

View file

@ -50,6 +50,18 @@ void*
lumiera_calloc (size_t n, size_t size);
/**
* Free previously allocated memory.
* @param mem pointer to the memory block obtained by lumiera_malloc or lumiera_calloc
*/
static inline void
lumiera_free (void* mem)
{
/* for now only a alias, might change in future */
free (mem);
}
/**
* Duplicate a C string.
* always succeeds or dies