diff options
-rw-r--r-- | epan/ftypes/ftypes.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftypes.h | 5 | ||||
-rw-r--r-- | epan/proto.c | 5 | ||||
-rw-r--r-- | epan/slab.h | 49 |
4 files changed, 34 insertions, 29 deletions
diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index 8ec16bd6f7..211d33accf 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -1,5 +1,5 @@ /* - * $Id: ftypes.c,v 1.25 2004/07/04 00:28:11 guy Exp $ + * $Id: ftypes.c,v 1.26 2004/07/04 02:29:43 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 */ -SLAB_FREE_LIST_DECLARE(fvalue_t) +SLAB_FREE_LIST_DEFINE(fvalue_t) /* These are the ftype registration functions that need to be called. * This list and the initialization function could be produced diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 3c60b700bb..6796920790 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -1,7 +1,7 @@ /* ftypes.h * Definitions for field types * - * $Id: ftypes.h,v 1.34 2004/07/04 00:28:11 guy Exp $ + * $Id: ftypes.h,v 1.35 2004/07/04 02:29:43 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -231,6 +231,9 @@ void fvalue_init(fvalue_t *fv, ftenum_t ftype); +/* Define type needed for the fvalue_t free list. */ +SLAB_ITEM_TYPE_DEFINE(fvalue_t) + /* Free all memory used by an fvalue_t. With MSVC and a * libethereal.dll, we need a special declaration. */ diff --git a/epan/proto.c b/epan/proto.c index a8b1bd5c52..97a48073ce 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -1,7 +1,7 @@ /* proto.c * Routines for protocol tree * - * $Id: proto.c,v 1.133 2004/07/04 00:28:11 guy Exp $ + * $Id: proto.c,v 1.134 2004/07/04 02:29:43 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -153,6 +153,7 @@ static GMemChunk *gmc_hfinfo = NULL; /* Contains information about a field when a dissector calls * proto_tree_add_item. */ +SLAB_ITEM_TYPE_DEFINE(field_info) static SLAB_FREE_LIST_DEFINE(field_info) static field_info *field_info_tmp=NULL; #define FIELD_INFO_NEW(fi) \ @@ -163,6 +164,7 @@ static field_info *field_info_tmp=NULL; /* Contains the space for proto_nodes. */ +SLAB_ITEM_TYPE_DEFINE(proto_node) static SLAB_FREE_LIST_DEFINE(proto_node) #define PROTO_NODE_NEW(node) \ SLAB_ALLOC(node, proto_node) \ @@ -176,6 +178,7 @@ static SLAB_FREE_LIST_DEFINE(proto_node) /* String space for protocol and field items for the GUI */ +SLAB_ITEM_TYPE_DEFINE(item_label_t) static SLAB_FREE_LIST_DEFINE(item_label_t) #define ITEM_LABEL_NEW(il) \ SLAB_ALLOC(il, item_label_t) diff --git a/epan/slab.h b/epan/slab.h index 59ce602fb0..a2182eb3e1 100644 --- a/epan/slab.h +++ b/epan/slab.h @@ -1,7 +1,7 @@ /* slab.h * Definitions for very simple slab handling * - * $Id: slab.h,v 1.3 2004/07/04 00:28:11 guy Exp $ + * $Id: slab.h,v 1.4 2004/07/04 02:29:43 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -27,50 +27,49 @@ #define NITEMS_PER_SLAB 100 -typedef struct _freed_item { - struct _freed_item *next; -} freed_item_t; +/* + * Generate declaration of a union type containing the specified type of + * slab-allocated item, and a pointer to an object of that type, for use + * in the macros below. + */ +#define SLAB_ITEM_TYPE_DEFINE(type) \ + union type ## slab_item { \ + type slab_item; \ + union type ## slab_item *next_free; \ + }; /* * Generate definition of the free list pointer. */ #define SLAB_FREE_LIST_DEFINE(type) \ - type *type ## _free_list = NULL; + union type ## slab_item *type ## _free_list = NULL; /* * Generate an external declaration of the free list pointer. */ #define SLAB_FREE_LIST_DECLARE(type) \ - type *type ## _free_list; + union type ## slab_item *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, type) \ - if(!type ## _free_list){ \ + if(!type ## _free_list){ \ int i; \ - char *tmp; \ - tmp=(char *)g_malloc(NITEMS_PER_SLAB* \ - ((sizeof(*item) > sizeof(freed_item_t)) ? \ - sizeof(*item) : sizeof(freed_item_t))); \ + union type ## slab_item *tmp; \ + tmp=g_malloc(NITEMS_PER_SLAB*sizeof(*tmp)); \ for(i=0;i<NITEMS_PER_SLAB;i++){ \ - item=(void *)tmp; \ - ((freed_item_t *)((void *)item))->next= \ - (freed_item_t *)((void *)type ## _free_list);\ - type ## _free_list=item; \ - tmp+= \ - ((sizeof(*item) > sizeof(freed_item_t)) ?\ - sizeof(*item) : sizeof(freed_item_t));\ + tmp[i].next_free = type ## _free_list; \ + type ## _free_list = &tmp[i]; \ } \ } \ - item=type ## _free_list; \ - type ## _free_list=(void *)(((freed_item_t *)((void *)item))->next); + item = &(type ## _free_list->slab_item); \ + type ## _free_list = type ## _free_list->next_free; -#define SLAB_FREE(item, type) \ -{ \ - ((freed_item_t *)((void *)item))->next= \ - (freed_item_t *)((void *)type ## _free_list); \ - type ## _free_list=item; \ +#define SLAB_FREE(item, type) \ +{ \ + ((union type ## slab_item *)item)->next_free = type ## _free_list; \ + type ## _free_list = (union type ## slab_item *)item; \ } #endif /* slab.h */ |