defined ASE_MEMXXX and started adding copier and freeer

This commit is contained in:
2008-08-08 05:02:08 +00:00
parent 93a0589204
commit 6f69035772
6 changed files with 271 additions and 67 deletions

View File

@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS = nostdinc
AM_CFLAGS = -I$(top_builddir)/include
lib_LTLIBRARIES = libasecmn.la
libasecmn_la_SOURCES = map.c mem.c misc.c rex.c str_bas.c str_cnv.c str_dyn.c
libasecmn_la_SOURCES = mem.h \
map.c mem.c misc.c rex.c str_bas.c str_cnv.c str_dyn.c sll.c
libasecmn_la_LDFLAGS = -version-info 1:0:0

View File

@ -56,7 +56,7 @@ libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libasecmn_la_LIBADD =
am_libasecmn_la_OBJECTS = map.lo mem.lo misc.lo rex.lo str_bas.lo \
str_cnv.lo str_dyn.lo
str_cnv.lo str_dyn.lo sll.lo
libasecmn_la_OBJECTS = $(am_libasecmn_la_OBJECTS)
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp
@ -195,7 +195,9 @@ target_alias = @target_alias@
AUTOMAKE_OPTIONS = nostdinc
AM_CFLAGS = -I$(top_builddir)/include
lib_LTLIBRARIES = libasecmn.la
libasecmn_la_SOURCES = map.c mem.c misc.c rex.c str_bas.c str_cnv.c str_dyn.c
libasecmn_la_SOURCES = mem.h \
map.c mem.c misc.c rex.c str_bas.c str_cnv.c str_dyn.c sll.c
libasecmn_la_LDFLAGS = -version-info 1:0:0
all: all-am
@ -270,6 +272,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_dyn.Plo@am__quote@

26
ase/lib/cmn/mem.h Normal file
View File

@ -0,0 +1,26 @@
/*
* $Id$
*
* {License}
*/
#ifndef _ASE_LIB_CMN_MEM_H_
#define _ASE_LIB_CMN_MEM_H_
#ifdef USE_STDC
#include <string.h>
#define ASE_MEMCPY(dst,src,len) memcpy(dst,src,len)
#define ASE_MEMCMP(p1,p2,len) memcmp(p1,p2,len)
#define ASE_MEMSET(dst,val,len) memset(dst,val,len)
#else
#include <ase/cmn/mem.h>
#define ASE_MEMCPY(dst,src,len) ase_memcpy(dst,src,len)
#define ASE_MEMCMP(p1,p2,len) ase_memcmp(p1,p2,len)
#define ASE_MEMSET(dst,val,len) ase_memset(dst,val,len)
#endif
#endif

View File

@ -5,25 +5,50 @@
*/
#include <ase/cmn/sll.h>
#include <ase/cmn/mem.h>
#include "mem.h"
struct ase_sll_t
{
ase_mmgr_t* mmgr;
ase_sll_copier_t copier;
ase_sll_freeer_t freeer;
ase_size_t size;
ase_sll_node_t* head;
ase_sll_node_t* tail;
};
struct ase_sll_node_t
{
ase_sll_node_t* data;
ase_size_t size;
ase_sll_node_t* next;
};
void* ase_sll_copyinline (ase_sll_t* sll, void* data, ase_size_t size)
{
/* this is a dummy copier */
return ASE_NULL;
}
ase_sll_t* ase_sll_open (ase_mmgr_t* mmgr)
{
return ase_sll_openx (mmgr, 0, ASE_NULL);
}
ase_sll_openx (ase_mmgr_t* mmgr, ase_size_t extension, ase_fuser_t fuser)
ase_sll_t* ase_sll_openx (ase_mmgr_t* mmgr, ase_size_t extension, ase_fuser_t fuser)
{
ase_sll_t* sll;
ssll = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_sll_t) + extension);
sll = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_sll_t) + extension);
if (sll == ASE_NULL) return ASE_NULL;
ase_memset (sll, 0, ASE_SIZEOF(ase_sll_t) + extension);
if (mmgr_fuser) mmgr = fuser (mmgr, sll + 1);
ASE_MEMSET (sll, 0, ASE_SIZEOF(ase_sll_t) + extension);
if (fuser != ASE_NULL) mmgr = fuser (mmgr, sll + 1);
sll->mmgr = mmgr;
return mmgr;
return sll;
}
void ase_sll_close (ase_sll_t* sll)
@ -38,51 +63,101 @@ void ase_sll_clear (ase_sll_t* sll)
{
ase_sll_node_t* n = sll->head->next;
// 1
no need to free expli9citly....
// 2
sll->freeer (sll->head->data);
ASE_FREE (sll->mmgr,
if (sll->freeer != ASE_NULL)
{
sll->freeer (sll, sll->head->data, sll->head->size);
}
ASE_FREE (sll->mmgr, sll->head);
sll->head = n;
}
sll->tail = ASE_NULL;
}
void ass_sll_setcopier (ase_sll_t* sll)
void* ase_sll_getextension (ase_sll_t* sll)
{
return sll + 1;
}
void ase_sll_setfreeer (ase_sll_t* sll)
ase_size_t ase_sll_getsize (ase_sll_t* sll)
{
return sll->size;
}
void ase_sll_append (ase_sll_t* sll, void* data)
void ass_sll_setcopier (ase_sll_t* sll, ase_sll_copier_t copier)
{
sll->copier = copier;
}
ase_sll_node_t* ase_sll_prepend (ase_sll_t* sll, void* data, size_t len)
void ase_sll_setfreeer (ase_sll_t* sll, ase_sll_freeer_t freeer)
{
sll->freeer = freeer;
}
static ase_sll_node_t* alloc_node (ase_sll_t* sll, void* data, ase_size_t size)
{
ase_sll_node_t* n;
// 1
n = ASE_MALLOC (sll->mmgr, ASE_SIZEOF(ase_sll_node_t) + len);
if (n == ASE_NULL) return ASE_NULL;
// TODO: ASE_MEMCPY to define to be memcpy or ase_memcpy or RtlCopyMemory...
ASE_MEMCPY (n + 1, data, len);
n->data = data;
n->len = len;
if (sll->copier == ASE_NULL)
{
n = ASE_MALLOC (sll->mmgr, ASE_SIZEOF(ase_sll_node_t));
if (n == ASE_NULL) return ASE_NULL;
n->data = data;
}
else if (sll->copier == ASE_SLL_COPIER_INLINE)
{
n = ASE_MALLOC (sll->mmgr, ASE_SIZEOF(ase_sll_node_t) + size);
if (n == ASE_NULL) return ASE_NULL;
// 2
n = ASE_MALLOC (sll->mmgr, ASE_SIZEOF(ase_sll_node_t));
ASE_MEMCPY (n + 1, data, size);
n->data = n + 1;
}
else
{
n = ASE_MALLOC (sll->mmgr, ASE_SIZEOF(ase_sll_node_t));
if (n == ASE_NULL) return ASE_NULL;
n->data = sll->copier (sll, data, size);
}
n->size = size;
n->next = ASE_NULL;
}
ase_sll_node_t* ase_sll_prepend (ase_sll_t* sll, void* data, ase_size_t size)
{
ase_sll_node_t* n = alloc_node (sll, data, size);
if (n == ASE_NULL) return ASE_NULL;
n->data = sll->copier (data, len);
n->len = len;
n->next = sll->head;
sll->head = n;
if (sll->tail == ASE_NULL) sll->tail = n;
sll->size++;
return n;
}
ase_sll_node_t* ase_sll_append (ase_sll_t* sll, void* data, ase_size_t size)
{
ase_sll_node_t* n = alloc_node (sll, data, size);
if (n == ASE_NULL) return ASE_NULL;
if (sll->tail != ASE_NULL) sll->tail->next = n;
sll->tail = n;
if (sll->head == ASE_NULL) sll->head = n;
sll->size++;
return n;
}
void ase_sll_walk (ase_sll_t* sll, ase_sll_walker_t walker)
{
ase_sll_node_t* n = sll->head;
while (n != ASE_NULL)
{
walker (sll, n->data, n->size);
n = n->next;
}
}