From cebe2307eb89031d5efa5ec867098b3da1ca68fe Mon Sep 17 00:00:00 2001 From: enge Date: Tue, 18 Oct 2011 08:51:42 +0000 Subject: memory.c, random.c: remove internal memory checks since we rely on valgrind git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@1099 211d60ee-9f03-0410-a15a-8952a2c7a4e4 --- AUTHORS | 2 - tests/Makefile.am | 2 +- tests/memory.c | 200 ------------------------------------------------------ tests/random.c | 10 +-- 4 files changed, 2 insertions(+), 212 deletions(-) delete mode 100644 tests/memory.c diff --git a/AUTHORS b/AUTHORS index 8d31f63..04bb21b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,5 +4,3 @@ Main authors: Paul Zimmermann Mickaƫl Gastineau has contributed the file Makefile.vc. - -File tests/memory.c taken from GNU MPFR, version 3.0.1. diff --git a/tests/Makefile.am b/tests/Makefile.am index f039c36..d4f425e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -36,7 +36,7 @@ tsub_ui tswap ttan ttanh tui_div tui_ui_sub tget_version check_LTLIBRARIES=libmpc-tests.la libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ -comparisons.c memory.c +comparisons.c EXTRA_DIST = abs.dat acos.dat acosh.dat asin.dat asinh.dat atan.dat atanh.dat \ add.dat add_fr.dat arg.dat conj.dat cos.dat cosh.dat div.dat div_fr.dat \ diff --git a/tests/memory.c b/tests/memory.c deleted file mode 100644 index d4f8cf4..0000000 --- a/tests/memory.c +++ /dev/null @@ -1,200 +0,0 @@ -/* Memory allocation used during tests. - -Copyright 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. -Contributed by the Arenaire and Cacao projects, INRIA. - -This file is part of the GNU MPFR Library (version 3.0.1). - -The GNU MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -The GNU MPFR Library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see -http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Note: this file comes from GMP's tests/memory.c */ - -#include -#include /* for abort */ -#include -#include "gmp.h" - -#define __gmp_default_allocate malloc -#define __gmp_default_reallocate(p,old,new) realloc(p,new) -#define __gmp_default_free(p,size) free(p) - -#include "mpc-tests.h" - -/* Each block allocated is a separate malloc, for the benefit of a redzoning - malloc debugger during development or when bug hunting. - - Sizes passed when reallocating or freeing are checked (the default - routines don't care about these). - - Memory leaks are checked by requiring that all blocks have been freed - when tests_memory_end() is called. Test programs must be sure to have - "clear"s for all temporary variables used. */ - -struct header { - void *ptr; - size_t size; - struct header *next; -}; - -static struct header *tests_memory_list; - -/* Return a pointer to a pointer to the found block (so it can be updated - when unlinking). */ -static struct header ** -tests_memory_find (void *ptr) -{ - struct header **hp; - - for (hp = &tests_memory_list; *hp != NULL; hp = &((*hp)->next)) - if ((*hp)->ptr == ptr) - return hp; - - return NULL; -} - -/* -static int -tests_memory_valid (void *ptr) -{ - return (tests_memory_find (ptr) != NULL); -} -*/ - -static void * -tests_allocate (size_t size) -{ - struct header *h; - - if (size == 0) - { - printf ("tests_allocate(): attempt to allocate 0 bytes\n"); - abort (); - } - - h = (struct header *) __gmp_default_allocate (sizeof (*h)); - h->next = tests_memory_list; - tests_memory_list = h; - - h->size = size; - h->ptr = __gmp_default_allocate (size); - return h->ptr; -} - -static void * -tests_reallocate (void *ptr, size_t old_size, size_t new_size) -{ - struct header **hp, *h; - - if (new_size == 0) - { - printf ("tests_reallocate(): attempt to reallocate 0x%lX to 0 bytes\n", - (unsigned long) ptr); - abort (); - } - - hp = tests_memory_find (ptr); - if (hp == NULL) - { - printf ("tests_reallocate(): attempt to reallocate bad pointer 0x%lX\n", - (unsigned long) ptr); - abort (); - } - h = *hp; - - if (h->size != old_size) - { - /* Note: we should use the standard %zu to print sizes, but - this is not supported by old C implementations. */ - printf ("tests_reallocate(): bad old size %lu at 0x%lX, should be %lu\n", - (unsigned long) old_size, (unsigned long) ptr, - (unsigned long) h->size); - abort (); - } - - h->size = new_size; - h->ptr = __gmp_default_reallocate (ptr, old_size, new_size); - return h->ptr; -} - -static struct header ** -tests_free_find (void *ptr) -{ - struct header **hp = tests_memory_find (ptr); - if (hp == NULL) - { - printf ("tests_free(): attempt to free bad pointer 0x%lX\n", - (unsigned long) ptr); - abort (); - } - return hp; -} - -static void -tests_free_nosize (void *ptr) -{ - struct header **hp = tests_free_find (ptr); - struct header *h = *hp; - - *hp = h->next; /* unlink */ - - __gmp_default_free (ptr, h->size); - __gmp_default_free (h, sizeof (*h)); -} - -static void -tests_free (void *ptr, size_t size) -{ - struct header **hp = tests_free_find (ptr); - struct header *h = *hp; - - if (h->size != size) - { - /* Note: we should use the standard %zu to print sizes, but - this is not supported by old C implementations. */ - printf ("tests_free(): bad size %lu at 0x%lX, should be %lu\n", - (unsigned long) size, (unsigned long) ptr, - (unsigned long) h->size); - abort (); - } - - tests_free_nosize (ptr); -} - -void -tests_memory_start (void) -{ - tests_memory_list = NULL; - mp_set_memory_functions (tests_allocate, tests_reallocate, tests_free); -} - -void -tests_memory_end (void) -{ - if (tests_memory_list != NULL) - { - struct header *h; - unsigned count; - - printf ("tests_memory_end(): not all memory freed\n"); - - count = 0; - for (h = tests_memory_list; h != NULL; h = h->next) - count++; - - printf (" %u blocks remaining\n", count); - abort (); - } -} diff --git a/tests/random.c b/tests/random.c index 587463c..d5f44c4 100644 --- a/tests/random.c +++ b/tests/random.c @@ -1,6 +1,6 @@ /* random.c -- Handle seed for random numbers. -Copyright (C) 2008, 2009, 2010 INRIA +// Copyright (C) 2008, 2009, 2010, 2011 INRIA This file is part of GNU MPC. @@ -48,11 +48,6 @@ test_start (void) char *environment_seed; unsigned long seed; - /* if we use valgrind, no need to have our own memory check */ -#ifndef MPC_USE_VALGRIND - tests_memory_start (); -#endif - if (rands_initialized) { fprintf (stderr, @@ -101,9 +96,6 @@ test_end (void) gmp_randclear (rands); } mpfr_free_cache (); -#ifndef MPC_USE_VALGRIND - tests_memory_end (); -#endif } /* Set z to a non zero value random value with absolute values of Re(z) and -- cgit v1.2.1