]> mj.ucw.cz Git - libucw.git/blobdiff - lib/pool.c
Fix escaping of "+" characters in outgoing parameters. (BTW: when Galeon
[libucw.git] / lib / pool.c
index 8c352f0fa9f83081cbf92551fa09179a52375958..8b7c372518b232f1f28cf2bda6b2d43bf5264067 100644 (file)
@@ -1,14 +1,17 @@
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
- *     (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997--2001 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
  */
 
-#include <stdio.h>
-#include <stdlib.h>
+#include "lib/lib.h"
+#include "lib/pools.h"
 
 
-#include "lib.h"
-#include "pools.h"
+#include <stdlib.h>
+#include <string.h>
 
 struct memchunk {
   struct memchunk *next;
 
 struct memchunk {
   struct memchunk *next;
@@ -16,7 +19,7 @@ struct memchunk {
 };
 
 struct mempool *
 };
 
 struct mempool *
-new_pool(uns size)
+mp_new(uns size)
 {
   struct mempool *p = xmalloc(sizeof(struct mempool));
 
 {
   struct mempool *p = xmalloc(sizeof(struct mempool));
 
@@ -30,25 +33,25 @@ new_pool(uns size)
 }
 
 void
 }
 
 void
-free_pool(struct mempool *p)
+mp_delete(struct mempool *p)
 {
   struct memchunk *c, *d;
 
   for(d=p->first; d; d = c)
     {
       c = d->next;
 {
   struct memchunk *c, *d;
 
   for(d=p->first; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
   for(d=p->first_large; d; d = c)
     {
       c = d->next;
     }
   for(d=p->first_large; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
     }
-  free(p);
+  xfree(p);
 }
 
 void
 }
 
 void
-flush_pool(struct mempool *p)
+mp_flush(struct mempool *p)
 {
   struct memchunk *c;
 
 {
   struct memchunk *c;
 
@@ -57,12 +60,12 @@ flush_pool(struct mempool *p)
   while (c = p->first_large)
     {
       p->first_large = c->next;
   while (c = p->first_large)
     {
       p->first_large = c->next;
-      free(c);
+      xfree(c);
     }
 }
 
 void *
     }
 }
 
 void *
-pool_alloc(struct mempool *p, uns s)
+mp_alloc(struct mempool *p, uns s)
 {
   if (s <= p->threshold)
     {
 {
   if (s <= p->threshold)
     {
@@ -71,9 +74,12 @@ pool_alloc(struct mempool *p, uns s)
        {
          struct memchunk *c;
 
        {
          struct memchunk *c;
 
-         if (p->current && p->current->next)
-           /* Still have free chunks from previous incarnation */
-           c = p->current->next;
+         if (p->current)
+           {
+             /* Still have free chunks from previous incarnation */
+             c = p->current;
+             p->current = c->next;
+           }
          else
            {
              c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
          else
            {
              c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
@@ -81,7 +87,6 @@ pool_alloc(struct mempool *p, uns s)
              p->plast = &c->next;
              c->next = NULL;
            }
              p->plast = &c->next;
              c->next = NULL;
            }
-         p->current = c;
          x = c->data;
          p->last = x + p->chunk_size;
        }
          x = c->data;
          p->last = x + p->chunk_size;
        }
@@ -96,3 +101,11 @@ pool_alloc(struct mempool *p, uns s)
       return c->data;
     }
 }
       return c->data;
     }
 }
+
+void *
+mp_alloc_zero(struct mempool *p, uns s)
+{
+  void *x = mp_alloc(p, s);
+  bzero(x, s);
+  return x;
+}