/* -*-c-*-
*
- * $Id: mparena.c,v 1.5 2000/06/17 11:35:48 mdw Exp $
+ * $Id$
*
* Allocation and freeing of MP buffers
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* 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.c,v $
- * Revision 1.5 2000/06/17 11:35:48 mdw
- * Overhaul to use mLib's arena system underneath.
- *
- * Revision 1.4 1999/12/10 23:28:52 mdw
- * Memory allocation counting.
- *
- * Revision 1.3 1999/11/22 13:58:00 mdw
- * Document the tweakables.
- *
- * Revision 1.2 1999/11/21 22:14:19 mdw
- * Fix bug. Improve diagnostic capabilities.
- *
- * Revision 1.1 1999/11/17 18:02:16 mdw
- * New multiprecision integer arithmetic suite.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
* itself.
*/
-/* #define MPARENA_TRIVIAL */
+#define MPARENA_TRIVIAL
/* --- @MPARENA_DEBUG@ --- *
*
unsigned mparena_count(mparena *a)
{
return (a->n);
-}
+}
/* --- @mpalloc@ --- *
*
mpw *mpalloc(mparena *a, size_t sz)
{
mpw *v;
+ if (!sz) return (0);
+ a->n++;
v = A_ALLOC(a->a, MPWS(sz));
if (!v)
THROW(EXC_NOMEM);
#ifdef MPARENA_DEBUG
MPARENA_OPENFILE;
- fprintf(debugfp, "alloc %u\n before: ", sz);
+ fprintf(debugfp, "alloc %u\n before: ", sz);
tdump(a->root); putc('\n', debugfp);
#endif
void mpfree(mparena *a, mpw *v)
{
+ if (!v) return;
+ a->n--;
A_FREE(a->a, v);
}