X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d3409d5ecf2492cff862616de72a580d1a8e8dc0..5d01b1b9514a258c5a3c201e944f676cb2c467f0:/mparena.h diff --git a/mparena.h b/mparena.h index 61c735e..94b69ad 100644 --- a/mparena.h +++ b/mparena.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: mparena.h,v 1.1 1999/11/17 18:02:16 mdw Exp $ + * $Id: mparena.h,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * Allocation and freeing of MP buffers * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,28 +15,20 @@ * 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. - * + * * Catacomb 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 Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: mparena.h,v $ - * Revision 1.1 1999/11/17 18:02:16 mdw - * New multiprecision integer arithmetic suite. - * - */ - -#ifndef MPARENA_H -#define MPARENA_H +#ifndef CATACOMB_MPARENA_H +#define CATACOMB_MPARENA_H #ifdef __cplusplus extern "C" { @@ -44,7 +36,9 @@ /*----- Header files ------------------------------------------------------*/ -#ifndef MPW_H +#include + +#ifndef CATACOMB_MPW_H # include "mpw.h" #endif @@ -68,28 +62,17 @@ typedef struct mparena_node { typedef struct mparena { mparena_node *root; - struct mparena_ops *ops; + unsigned n; + arena *a; } mparena; -/* --- @mparena_ops@ --- * - * - * Operations required for an arena memory manager. The default manager just - * calls @xmalloc@ and @free@, although it's possible to envisage a more - * paranoid implementation which allocates locked memory pages. Switch them - * over with @mparena_setops@. It's usual to only do this when you've - * attached your extra state to the end of the @mparena@ structure. - */ - -typedef struct mparena_ops { - void *(*alloc)(mparena */*a*/, size_t /*sz*/); - void (*free)(mparena */*a*/, void */*p*/); -} mparena_ops; +/*----- Standard arenas ---------------------------------------------------*/ -/*----- Magical constants -------------------------------------------------*/ +extern mparena mparena_global; +#define MPARENA_GLOBAL (&mparena_global) -#define MPARENA_GLOBAL ((mparena *)0) - -extern mparena_ops mparena_defaultops; +extern mparena mparena_secure; +#define MPARENA_SECURE (&mparena_secure) /*----- Functions provided ------------------------------------------------*/ @@ -105,19 +88,19 @@ extern mparena_ops mparena_defaultops; extern void mparena_create(mparena */*a*/); -#define MPARENA_INIT { 0, &mparena_defaultops } +#define MPARENA_INIT { 0, 0, &arena_stdlib } -/* --- @mparena_setops@ --- * +/* --- @mparena_setarena@ --- * * - * Arguments: @mparena *a@ = pointer to arena block - * @mparena_ops *ops@ = pointer to operations block or null + * Arguments: @mparena *a@ = pointer to MP arena block + * @arena *aa@ = pointer to arena * - * Returns: The previous operations block. + * Returns: --- * - * Use: Sets or queries the operations attached to an arena. + * Use: Sets the underlying arena for an MP arena. */ -extern mparena_ops *mparena_setops(mparena */*a*/, mparena_ops */*ops*/); +extern void mparena_setarena(mparena */*a*/, arena */*aa*/); /* --- @mparena_destroy@ --- * * @@ -127,11 +110,24 @@ extern mparena_ops *mparena_setops(mparena */*a*/, mparena_ops */*ops*/); * * Use: Frees an MP arena, and all the vectors held within it. The * blocks which are currently allocated can be freed into some - * other arena. + * other MP arena, as long as the underlying arenas are the + * same. */ extern void mparena_destroy(mparena */*a*/); +/* --- @mparena_count@ --- * + * + * Arguments: @mparena *a@ = pointer to arena block + * + * Returns: Number of allocated blocks from this arena. + * + * Use: Reports the number of blocks allocated from the arena and not + * yet freed. + */ + +extern unsigned mparena_count(mparena */*a*/); + /* --- @mpalloc@ --- * * * Arguments: @mparena *a@ = pointer to arena block @@ -152,8 +148,7 @@ extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/); * * Returns: --- * - * Use: Returns an MP vector to an arena. It doesn't have to be - * returned to the arena from which it was allocated. + * Use: Returns an MP vector to an arena. */ extern void mpfree(mparena */*a*/, mpw */*v*/);