chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Describe custom interface.
[mLib]
/
arena.c
diff --git
a/arena.c
b/arena.c
index 20d286c00320b8080b13736ca6e9233367422393..58820fae5b87b5e4a16d6c5f266da6eff08c8254 100644
(file)
--- a/
arena.c
+++ b/
arena.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: arena.c,v 1.
1 2000/06/17 10:37:53
mdw Exp $
+ * $Id: arena.c,v 1.
3 2000/08/06 11:00:18
mdw Exp $
*
* Abstraction for memory allocation arenas
*
*
* Abstraction for memory allocation arenas
*
@@
-30,6
+30,12
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: arena.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: arena.c,v $
+ * Revision 1.3 2000/08/06 11:00:18 mdw
+ * Daft bug fix. Include <string.h>.
+ *
+ * Revision 1.2 2000/07/16 12:29:16 mdw
+ * Change to arena `realloc' interface, to fix a design bug.
+ *
* Revision 1.1 2000/06/17 10:37:53 mdw
* Basic arena management.
*
* Revision 1.1 2000/06/17 10:37:53 mdw
* Basic arena management.
*
@@
-38,13
+44,15
@@
/*----- Header files ------------------------------------------------------*/
#include <stdlib.h>
/*----- Header files ------------------------------------------------------*/
#include <stdlib.h>
+#include <string.h>
#include "arena.h"
/*----- The standard arena ------------------------------------------------*/
static void *_alloc(arena *a, size_t sz) { return malloc(sz); }
#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 *_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 };
static void _free(arena *a, void *p) { free (p); }
static arena_ops stdlib_ops = { _alloc, _realloc, _free, 0 };
@@
-61,6
+69,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
* 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: ---
*
*
* Returns: ---
*
@@
-68,12
+77,12
@@
arena *arena_global = &arena_stdlib;
* support @realloc@ properly.
*/
* 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);
{
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);
}
A_FREE(a, p);
return (q);
}
@@
-81,7
+90,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)); }
/* --- 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 -------------------------------------------------*/
void a_free(arena *a, void *p) { A_FREE(a, p); }
/*----- That's all, folks -------------------------------------------------*/