summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-09-30 03:16:37 +0000
committerAdrian Thurston <thurston@complang.org>2011-09-30 03:16:37 +0000
commit977d50d254b0dd1e7ba821d05345980ede33759d (patch)
treeabd8ecf2781e1a8bccdc6113299106539dd981e2
parent9814e48d8b4cd2c8441ac7637ac4d9ec5155e766 (diff)
downloadcolm-977d50d254b0dd1e7ba821d05345980ede33759d.tar.gz
Added an option for using malloc in the pool alloc. Helps with tracking down
memory leaks with valgrind. Fixed a couple leaks.
-rwxr-xr-xautogen.sh2
-rw-r--r--colm/pool.c10
-rw-r--r--colm/tree.c7
-rw-r--r--configure.in3
4 files changed, 14 insertions, 8 deletions
diff --git a/autogen.sh b/autogen.sh
index a9444153..be06eec4 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-libtoolize --copy --force
+#libtoolize --copy --force
aclocal
autoheader
automake --foreign --add-missing
diff --git a/colm/pool.c b/colm/pool.c
index a4f7d681..022f134f 100644
--- a/colm/pool.c
+++ b/colm/pool.c
@@ -38,6 +38,11 @@ void *poolAllocAllocate( PoolAlloc *poolAlloc )
{
debug( REALM_POOL, "pool allocation\n" );
+#ifdef POOL_MALLOC
+ void *res = malloc( poolAlloc->sizeofT );
+ memset( res, 0, poolAlloc->sizeofT );
+ return res;
+#else
//#ifdef COLM_LOG_BYTECODE
//cerr << "allocating in: " << __PRETTY_FUNCTION__ << endl;
//#endif
@@ -65,6 +70,7 @@ void *poolAllocAllocate( PoolAlloc *poolAlloc )
}
memset( newEl, 0, poolAlloc->sizeofT );
return newEl;
+#endif
}
void poolAllocFree( PoolAlloc *poolAlloc, void *el )
@@ -78,9 +84,13 @@ void poolAllocFree( PoolAlloc *poolAlloc, void *el )
memset( el, 0xcc, sizeof(T) );
#endif
+#ifdef POOL_MALLOC
+ free( el );
+#else
PoolItem *pi = (PoolItem*) el;
pi->next = poolAlloc->pool;
poolAlloc->pool = pi;
+#endif
}
void poolAllocClear( PoolAlloc *poolAlloc )
diff --git a/colm/tree.c b/colm/tree.c
index d82ad0d5..f3661f2b 100644
--- a/colm/tree.c
+++ b/colm/tree.c
@@ -272,7 +272,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat )
leftIgnore = ilAllocate( prg );
leftIgnore->id = LEL_ID_IGNORE_LIST;
- leftIgnore->refs = 1;
leftIgnore->child = ignore;
leftIgnore->generation = prg->nextIlGen++;
@@ -291,7 +290,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat )
leftIgnore = ilAllocate( prg );
leftIgnore->id = LEL_ID_IGNORE_LIST;
- leftIgnore->refs = 1;
leftIgnore->child = 0;
leftIgnore->generation = prg->nextIlGen++;
leftIgnore->cmd = IL_CMD_GO_LEFT;
@@ -316,7 +314,6 @@ Tree *constructReplacementTree( Tree **bindings, Program *prg, long pat )
IgnoreList *rightIgnore = ilAllocate( prg );
rightIgnore->id = LEL_ID_IGNORE_LIST;
- rightIgnore->refs = 1;
rightIgnore->child = 0;
rightIgnore->generation = prg->nextIlGen++;
rightIgnore->cmd = IL_CMD_GO_RIGHT;
@@ -1133,7 +1130,6 @@ void setUiterCur( Program *prg, UserIter *uiter, Tree *tree )
IgnoreList *leftIgnore = ilAllocate( prg );
leftIgnore->id = LEL_ID_IGNORE_LIST;
- leftIgnore->refs = 1;
leftIgnore->child = 0;
leftIgnore->generation = prg->nextIlGen++;
leftIgnore->cmd = IL_CMD_GO_LEFT;
@@ -1156,7 +1152,6 @@ void setUiterCur( Program *prg, UserIter *uiter, Tree *tree )
IgnoreList *rightIgnore = ilAllocate( prg );
rightIgnore->id = LEL_ID_IGNORE_LIST;
- rightIgnore->refs = 1;
rightIgnore->child = 0;
rightIgnore->generation = prg->nextIlGen++;
rightIgnore->cmd = IL_CMD_GO_RIGHT;
@@ -1186,7 +1181,6 @@ void setTriterCur( Program *prg, TreeIter *iter, Tree *tree )
IgnoreList *leftIgnore = ilAllocate( prg );
leftIgnore->id = LEL_ID_IGNORE_LIST;
- leftIgnore->refs = 1;
leftIgnore->child = 0;
leftIgnore->generation = prg->nextIlGen++;
leftIgnore->cmd = IL_CMD_GO_LEFT;
@@ -1209,7 +1203,6 @@ void setTriterCur( Program *prg, TreeIter *iter, Tree *tree )
IgnoreList *rightIgnore = ilAllocate( prg );
rightIgnore->id = LEL_ID_IGNORE_LIST;
- rightIgnore->refs = 1;
rightIgnore->child = 0;
rightIgnore->generation = prg->nextIlGen++;
rightIgnore->cmd = IL_CMD_GO_RIGHT;
diff --git a/configure.in b/configure.in
index 983599c1..78f39515 100644
--- a/configure.in
+++ b/configure.in
@@ -61,6 +61,9 @@ AC_LANG_CPLUSPLUS
dnl Check for definition of MAKE.
AC_PROG_MAKE_SET
+AC_ARG_ENABLE(pool-malloc, "allocate pool objects with malloc",
+ AC_DEFINE([POOL_MALLOC], [1], [allocate pool objects with malloc]))
+
# Logging features
# AC_ARG_ENABLE(log, "turn on logging", AC_DEFINE(COLM_LOG))
# AC_ARG_ENABLE(log-bytecode, "turns on bytecode logging", AC_DEFINE(COLM_LOG_BYTECODE))