Make the "SLAB_ALLOC()" and "SLAB_FREE()" macros take the type of the
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 4 Jul 2004 00:28:11 +0000 (00:28 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 4 Jul 2004 00:28:11 +0000 (00:28 +0000)
object being allocated, rather than the name of the free list, as an
argument (with the name of the free list constructed from the name of
the type), and add macros to define and declare the free list, also
taking the type of the object being allocated.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@11305 f5534014-38df-0310-8fa8-9805f1628bb7

epan/ftypes/ftypes.c
epan/ftypes/ftypes.h
epan/proto.c
epan/slab.h

index 55517f8d9606e9547882faad726720dcf041838e..8ec16bd6f7ca75ee50f24b98a875ab2d9ac32674 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftypes.c,v 1.24 2004/06/28 06:01:33 guy Exp $
+ * $Id: ftypes.c,v 1.25 2004/07/04 00:28:11 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -32,7 +32,7 @@
 static ftype_t* type_list[FT_NUM_TYPES];
 
 /* Space for quickly allocating/de-allocating fvalue_t's */
-fvalue_t *fvalue_free_list=NULL;
+SLAB_FREE_LIST_DECLARE(fvalue_t)
 
 /* These are the ftype registration functions that need to be called.
  * This list and the initialization function could be produced
@@ -213,7 +213,7 @@ fvalue_new(ftenum_t ftype)
        ftype_t                 *ft;
        FvalueNewFunc           new_value;
 
-       SLAB_ALLOC(fv, fvalue_free_list);
+       SLAB_ALLOC(fv, fvalue_t);
 
        FTYPE_LOOKUP(ftype, ft);
        fv->ftype = ft;
index 90cb5020c7704629cca86279cca05ee2728a80fd..3c60b700bbd2af223a23734553921b6464d2eaf8 100644 (file)
@@ -1,7 +1,7 @@
 /* ftypes.h
  * Definitions for field types
  *
- * $Id: ftypes.h,v 1.33 2004/06/24 21:50:05 sahlberg Exp $
+ * $Id: ftypes.h,v 1.34 2004/07/04 00:28:11 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -234,7 +234,7 @@ fvalue_init(fvalue_t *fv, ftenum_t ftype);
 /* Free all memory used by an fvalue_t. With MSVC and a 
  * libethereal.dll, we need a special declaration.
  */
-ETH_VAR_IMPORT fvalue_t *fvalue_free_list;
+ETH_VAR_IMPORT SLAB_FREE_LIST_DECLARE(fvalue_t)
 
 
 #define FVALUE_CLEANUP(fv)                                     \
@@ -249,7 +249,7 @@ ETH_VAR_IMPORT fvalue_t *fvalue_free_list;
 #define FVALUE_FREE(fv)                                                \
        {                                                       \
                FVALUE_CLEANUP(fv)                              \
-               SLAB_FREE(fv, fvalue_free_list);                \
+               SLAB_FREE(fv, fvalue_t);                        \
        }
 
 
index 9283502d25f47aca253d1745f79bc7dbdee832e2..a8b1bd5c52e2eb299d1b9686b10db00f72707641 100644 (file)
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.132 2004/05/01 15:15:08 ulfl Exp $
+ * $Id: proto.c,v 1.133 2004/07/04 00:28:11 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -153,34 +153,34 @@ static GMemChunk *gmc_hfinfo = NULL;
 
 /* Contains information about a field when a dissector calls
  * proto_tree_add_item.  */
-static field_info *field_info_free_list=NULL;
+static SLAB_FREE_LIST_DEFINE(field_info)
 static field_info *field_info_tmp=NULL;
 #define FIELD_INFO_NEW(fi)                                     \
-       SLAB_ALLOC(fi, field_info_free_list)
+       SLAB_ALLOC(fi, field_info)
 #define FIELD_INFO_FREE(fi)                                    \
-       SLAB_FREE(fi, field_info_free_list)
+       SLAB_FREE(fi, field_info)
 
 
 
 /* Contains the space for proto_nodes. */
-static proto_node *proto_node_free_list=NULL;
+static SLAB_FREE_LIST_DEFINE(proto_node)
 #define PROTO_NODE_NEW(node)                           \
-       SLAB_ALLOC(node, proto_node_free_list)          \
+       SLAB_ALLOC(node, proto_node)                    \
        node->first_child = NULL;                       \
        node->last_child = NULL;                        \
        node->next = NULL;
 
 #define PROTO_NODE_FREE(node)                          \
-       SLAB_FREE(node, proto_node_free_list)
+       SLAB_FREE(node, proto_node)
 
 
 
 /* String space for protocol and field items for the GUI */
-static item_label_t *item_label_free_list = NULL;
+static SLAB_FREE_LIST_DEFINE(item_label_t)
 #define ITEM_LABEL_NEW(il)                             \
-       SLAB_ALLOC(il, item_label_free_list)
+       SLAB_ALLOC(il, item_label_t)
 #define ITEM_LABEL_FREE(il)                            \
-       SLAB_FREE(il, item_label_free_list)
+       SLAB_FREE(il, item_label_t)
 
 
 
@@ -658,7 +658,7 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
                 * good thing we saved it, now we can reverse the
                 * memory leak and reclaim it.
                 */
-               SLAB_FREE(field_info_tmp, field_info_free_list);
+               SLAB_FREE(field_info_tmp, field_info);
        }
        /* we might throw an exception, keep track of this one
         * across the "dangerous" section below.
index 41e6ab1e0947184dfbae356378f42c79fdb76ff2..59ce602fb049fd26670c4d22fd5b38d90de5dbaf 100644 (file)
@@ -1,7 +1,7 @@
 /* slab.h
  * Definitions for very simple slab handling
  *
- * $Id: slab.h,v 1.2 2003/12/03 08:53:36 guy Exp $
+ * $Id: slab.h,v 1.3 2004/07/04 00:28:11 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -31,11 +31,23 @@ typedef struct _freed_item {
        struct _freed_item *next;
 } freed_item_t;
 
+/*
+ * Generate definition of the free list pointer.
+ */
+#define SLAB_FREE_LIST_DEFINE(type)            \
+       type *type ## _free_list = NULL;
+
+/*
+ * Generate an external declaration of the free list pointer.
+ */
+#define SLAB_FREE_LIST_DECLARE(type)           \
+       type *type ## _free_list;
+
 /* we never free any memory we have allocated, when it is returned to us
    we just store it in the free list until (hopefully) it gets used again
 */
-#define SLAB_ALLOC(item, list)                                 \
-       if(!list){                                              \
+#define SLAB_ALLOC(item, type)                                 \
+       if(!type ## _free_list){                                                \
                int i;                                          \
                char *tmp;                                      \
                tmp=(char *)g_malloc(NITEMS_PER_SLAB*           \
@@ -44,21 +56,21 @@ typedef struct _freed_item {
                for(i=0;i<NITEMS_PER_SLAB;i++){                 \
                        item=(void *)tmp;                       \
                        ((freed_item_t *)((void *)item))->next= \
-                           (freed_item_t *)((void *)list);     \
-                       list=item;                              \
+                           (freed_item_t *)((void *)type ## _free_list);\
+                       type ## _free_list=item;                        \
                        tmp+=                                   \
                            ((sizeof(*item) > sizeof(freed_item_t)) ?\
                                sizeof(*item) : sizeof(freed_item_t));\
                }                                               \
        }                                                       \
-       item=list;                                              \
-       list=(void *)(((freed_item_t *)((void *)item))->next);
+       item=type ## _free_list;                                        \
+       type ## _free_list=(void *)(((freed_item_t *)((void *)item))->next);
 
-#define SLAB_FREE(item, list)                          \
-{                                                      \
-       ((freed_item_t *)((void *)item))->next=         \
-           (freed_item_t *)((void *)list);             \
-       list=item;                                      \
+#define SLAB_FREE(item, type)                                  \
+{                                                              \
+       ((freed_item_t *)((void *)item))->next=                 \
+           (freed_item_t *)((void *)type ## _free_list);       \
+       type ## _free_list=item;                                        \
 }
 
 #endif /* slab.h */