/*
- * $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>
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
ftype_t *ft;
FvalueNewFunc new_value;
- SLAB_ALLOC(fv, fvalue_free_list);
+ SLAB_ALLOC(fv, fvalue_t);
FTYPE_LOOKUP(ftype, ft);
fv->ftype = ft;
/* 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>
/* 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) \
#define FVALUE_FREE(fv) \
{ \
FVALUE_CLEANUP(fv) \
- SLAB_FREE(fv, fvalue_free_list); \
+ SLAB_FREE(fv, fvalue_t); \
}
/* 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>
/* 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)
* 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.
/* 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>
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* \
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 */