[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp tests/libpspp/range-set-test.c tests/autom... [simpler-p
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp tests/libpspp/range-set-test.c tests/autom... [simpler-proc] |
Date: |
Sat, 31 Mar 2007 03:31:58 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Branch: simpler-proc
Changes by: Ben Pfaff <blp> 07/03/31 03:31:58
Modified files:
tests/libpspp : range-set-test.c
tests : automake.mk
src/libpspp : range-set.h range-set.c
Log message:
Add pool support to range_set.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/tests/libpspp/range-set-test.c?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/pspp/tests/automake.mk?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.27.2.6&r2=1.27.2.7
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/range-set.h?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/range-set.c?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.1.2.1&r2=1.1.2.2
Patches:
Index: tests/libpspp/range-set-test.c
===================================================================
RCS file: /cvsroot/pspp/pspp/tests/libpspp/Attic/range-set-test.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- tests/libpspp/range-set-test.c 30 Mar 2007 16:43:57 -0000 1.1.2.1
+++ tests/libpspp/range-set-test.c 31 Mar 2007 03:31:57 -0000 1.1.2.2
@@ -19,10 +19,11 @@
/* This is a test program for the routines defined in
range-set.c. This test program aims to be as comprehensive as
possible. With -DNDEBUG, "gcov -b" should report 100%
- coverage of lines and branches in heap.c routines. (Without
- -DNDEBUG, branches caused by failed assertions will also not
- be taken.) "valgrind --leak-check=yes --show-reachable=yes"
- should give a clean report, both with and without -DNDEBUG. */
+ coverage of lines and branches in range-set.c routines.
+ (Without -DNDEBUG, branches caused by failed assertions will
+ not be taken.) "valgrind --leak-check=yes
+ --show-reachable=yes" should give a clean report, both with
+ and without -DNDEBUG. */
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -37,6 +38,7 @@
#include <string.h>
#include <libpspp/compiler.h>
+#include <libpspp/pool.h>
#include "xalloc.h"
@@ -168,7 +170,7 @@
{
unsigned long int start = 0;
unsigned long int width = 0;
- struct range_set *rs = range_set_create ();
+ struct range_set *rs = range_set_create_pool (NULL);
while (next_region (pattern, start + width, &start, &width))
range_set_insert (rs, start, width);
check_pattern (rs, pattern);
@@ -285,6 +287,29 @@
}
}
+/* Tests freeing a range set through a pool. */
+static void
+test_pool (void)
+{
+ struct pool *pool;
+ struct range_set *rs;
+
+ /* Destroy the range set, then the pool.
+ Makes sure that this doesn't cause a double-free. */
+ pool = pool_create ();
+ rs = range_set_create_pool (pool);
+ range_set_insert (rs, 1, 10);
+ range_set_destroy (rs);
+ pool_destroy (pool);
+
+ /* Just destroy the pool.
+ Makes sure that this doesn't cause a leak. */
+ pool = pool_create ();
+ rs = range_set_create_pool (pool);
+ range_set_insert (rs, 1, 10);
+ pool_destroy (pool);
+}
+
/* Main program. */
/* Runs TEST_FUNCTION and prints a message about NAME. */
@@ -303,6 +328,7 @@
run_test (test_insert, "insert");
run_test (test_delete, "delete");
run_test (test_allocate, "allocate");
+ run_test (test_pool, "pool");
putchar ('\n');
return 0;
Index: tests/automake.mk
===================================================================
RCS file: /cvsroot/pspp/pspp/tests/automake.mk,v
retrieving revision 1.27.2.6
retrieving revision 1.27.2.7
diff -u -b -r1.27.2.6 -r1.27.2.7
--- tests/automake.mk 30 Mar 2007 16:43:57 -0000 1.27.2.6
+++ tests/automake.mk 31 Mar 2007 03:31:57 -0000 1.27.2.7
@@ -184,10 +184,12 @@
tests_libpspp_range_set_test_SOURCES = \
src/libpspp/bt.c \
src/libpspp/bt.h \
+ src/libpspp/pool.c \
+ src/libpspp/pool.h \
src/libpspp/range-set.c \
src/libpspp/range-set.h \
tests/libpspp/range-set-test.c
-tests_libpspp_range_set_test_LDADD = gl/libgl.a
+tests_libpspp_range_set_test_LDADD = gl/libgl.a @LIBINTL@
tests_libpspp_range_set_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
tests_libpspp_sparse_array_test_SOURCES = \
Index: src/libpspp/range-set.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/Attic/range-set.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- src/libpspp/range-set.h 30 Mar 2007 16:43:57 -0000 1.1.2.2
+++ src/libpspp/range-set.h 31 Mar 2007 03:31:58 -0000 1.1.2.3
@@ -28,7 +28,10 @@
#include <stdbool.h>
+struct pool;
+
struct range_set *range_set_create (void);
+struct range_set *range_set_create_pool (struct pool *);
void range_set_destroy (struct range_set *);
void range_set_insert (struct range_set *,
Index: src/libpspp/range-set.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/Attic/range-set.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- src/libpspp/range-set.c 30 Mar 2007 16:43:57 -0000 1.1.2.1
+++ src/libpspp/range-set.c 31 Mar 2007 03:31:58 -0000 1.1.2.2
@@ -33,14 +33,15 @@
#include <libpspp/assertion.h>
#include <libpspp/bt.h>
#include <libpspp/compiler.h>
+#include <libpspp/pool.h>
#include "xalloc.h"
/* A set of ranges. */
struct range_set
{
- /* Tree of range_set_nodes. */
- struct bt bt;
+ struct pool *pool; /* Pool for freeing range_set. */
+ struct bt bt; /* Tree of range_set_nodes. */
/* Cache. */
unsigned long int cache_start; /* Start of region. */
@@ -76,12 +77,24 @@
struct range_set_node *);
static void merge_node_with_successors (struct range_set *,
struct range_set_node *);
+static void destroy_pool (void *);
/* Creates and returns a new, empty range set. */
struct range_set *
range_set_create (void)
{
+ return range_set_create_pool (NULL);
+}
+
+/* Creates and returns a new, empty range set in the given
+ POOL. */
+struct range_set *
+range_set_create_pool (struct pool *pool)
+{
struct range_set *rs = xmalloc (sizeof *rs);
+ rs->pool = pool;
+ if (pool != NULL)
+ pool_register (pool, destroy_pool, rs);
bt_init (&rs->bt, compare_range_set_nodes, NULL);
rs->cache_end = 0;
return rs;
@@ -91,9 +104,14 @@
void
range_set_destroy (struct range_set *rs)
{
+ if (rs != NULL)
+ {
+ if (rs->pool != NULL)
+ pool_unregister (rs->pool, rs);
while (!range_set_is_empty (rs))
delete_node (rs, first_node (rs));
free (rs);
+ }
}
/* Inserts the region starting at START and extending for WIDTH
@@ -462,3 +480,13 @@
delete_node (rs, next);
}
}
+
+/* Destroys range set RS.
+ Helper function for range_set_create_pool. */
+static void
+destroy_pool (void *rs_)
+{
+ struct range_set *rs = rs_;
+ rs->pool = NULL;
+ range_set_destroy (rs);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] pspp tests/libpspp/range-set-test.c tests/autom... [simpler-proc],
Ben Pfaff <=