diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2005-10-01 10:36:57 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2005-10-01 10:36:57 +0000 |
commit | 9860d26c68a0d54f376bab33c397306ad7c42fb3 (patch) | |
tree | e2f92215a02b310d3cd324f2255c1e82240c39b1 /epan/emem.h | |
parent | 6f5e84b2d7c179e574bd413faea17b7f0f8d7240 (diff) |
emem.[ch]:
Add a simple stack implememtation that uses ep_alloc
Add ep_new() ep_new0() macros
tpg.[ch]:
use the stack in tpg helpers
svn path=/trunk/; revision=16061
Diffstat (limited to 'epan/emem.h')
-rw-r--r-- | epan/emem.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/epan/emem.h b/epan/emem.h index 81f2307294..69fa82c51b 100644 --- a/epan/emem.h +++ b/epan/emem.h @@ -46,9 +46,11 @@ void ep_init_chunk(void); /* Allocate memory with a packet lifetime scope */ void *ep_alloc(size_t size); +#define ep_new(type) ((type*)ep_alloc(sizeof(type))) /* Allocate memory with a packet lifetime scope and fill it with zeros*/ void* ep_alloc0(size_t size); +#define ep_new0(type) ((type*)ep_alloc0(sizeof(type))) /* Duplicate a string with a packet lifetime scope */ gchar* ep_strdup(const gchar* src); @@ -79,7 +81,35 @@ gchar** ep_strsplit(const gchar* string, const gchar* delimiter, int max_tokens) void ep_free_all(void); +/* a stack implemented using ephemeral allocators */ +typedef struct _ep_stack_frame_t** ep_stack_t; + +struct _ep_stack_frame_t { + void* payload; + struct _ep_stack_frame_t* below; + struct _ep_stack_frame_t* above; +}; + +/* + * creates an empty stack with a packet lifetime scope + */ +ep_stack_t ep_stack_new(void); + +/* + * pushes item into stack, returns item + */ +void* ep_stack_push(ep_stack_t stack, void* item); + +/* + * pops an item from the stack + */ +void* ep_stack_pop(ep_stack_t stack); + +/* + * returns the item on top of the stack without popping it + */ +#define ep_stack_peek(stack) ((*(stack))->payload) /* Functions for handling memory allocation and garbage collection with |