X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/34f655c10412ca059d43c78d1e137ab577acdd17..ff1e93acf2626d2531a97de3b54bce9b5a37bcb5:/arena.c diff --git a/arena.c b/arena.c index 20d286c..7604823 100644 --- a/arena.c +++ b/arena.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: arena.c,v 1.1 2000/06/17 10:37:53 mdw Exp $ + * $Id: arena.c,v 1.5 2004/04/08 01:36:11 mdw Exp $ * * Abstraction for memory allocation arenas * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,37 +15,31 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib 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 Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: arena.c,v $ - * Revision 1.1 2000/06/17 10:37:53 mdw - * Basic arena management. - * - */ - /*----- Header files ------------------------------------------------------*/ #include +#include #include "arena.h" /*----- The standard arena ------------------------------------------------*/ static void *_alloc(arena *a, size_t sz) { return malloc(sz); } -static void *_realloc(arena *a, void *p, size_t sz){ return realloc(p, sz); } -static void _free(arena *a, void *p) { free (p); } +static void *_realloc(arena *a, void *p, size_t sz, size_t osz) + { return realloc(p, sz); } +static void _free(arena *a, void *p) { free(p); } static arena_ops stdlib_ops = { _alloc, _realloc, _free, 0 }; arena arena_stdlib = { &stdlib_ops }; @@ -61,6 +55,7 @@ arena *arena_global = &arena_stdlib; * Arguments: @arena *a@ = pointer to arena block * @void *p@ = pointer to memory block to resize * @size_t sz@ = size desired for the block + * @size_t osz@ = size of the old block * * Returns: --- * @@ -68,12 +63,12 @@ arena *arena_global = &arena_stdlib; * support @realloc@ properly. */ -void *arena_fakerealloc(arena *a, void *p, size_t sz) +void *arena_fakerealloc(arena *a, void *p, size_t sz, size_t osz) { void *q = A_ALLOC(a, sz); if (!q) return (0); - memcpy(q, p, sz); + memcpy(q, p, sz > osz ? osz : sz); A_FREE(a, p); return (q); } @@ -81,7 +76,8 @@ void *arena_fakerealloc(arena *a, void *p, size_t sz) /* --- Function equivalents of the macros --- */ void *a_alloc(arena *a, size_t sz) { return (A_ALLOC(a, sz)); } -void *a_realloc(arena *a, void *p, size_t sz) { return A_REALLOC(a, p, sz); } +void *a_realloc(arena *a, void *p, size_t sz, size_t osz) +{ return A_REALLOC(a, p, sz, osz); } void a_free(arena *a, void *p) { A_FREE(a, p); } /*----- That's all, folks -------------------------------------------------*/