2 tre-stack.h: Stack definitions
4 This software is released under a BSD-style license.
5 See the file LICENSE for details and copyright.
15 typedef struct tre_stack_rec tre_stack_t
;
17 /* Creates a new stack object. `size' is initial size in bytes, `max_size'
18 is maximum size, and `increment' specifies how much more space will be
19 allocated with realloc() if all space gets used up. Returns the stack
20 object or NULL if out of memory. */
21 __private_extern__ tre_stack_t
*
22 tre_stack_new(int size
, int max_size
, int increment
);
24 /* Frees the stack object. */
25 __private_extern__
void
26 tre_stack_destroy(tre_stack_t
*s
);
28 /* Returns the current number of objects in the stack. */
29 __private_extern__
int
30 tre_stack_num_objects(tre_stack_t
*s
);
32 /* Each tre_stack_push_*(tre_stack_t *s, <type> value) function pushes
33 `value' on top of stack `s'. Returns REG_ESPACE if out of memory.
34 This tries to realloc() more space before failing if maximum size
35 has not yet been reached. Returns REG_OK if successful. */
36 #define declare_pushf(typetag, type) \
37 __private_extern__ reg_errcode_t tre_stack_push_ ## typetag(tre_stack_t *s, \
40 declare_pushf(voidptr
, void *);
41 declare_pushf(int, int);
43 /* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost
44 element off of stack `s' and returns it. The stack must not be
46 #define declare_popf(typetag, type) \
47 __private_extern__ type tre_stack_pop_ ## typetag(tre_stack_t *s)
49 declare_popf(voidptr
, void *);
50 declare_popf(int, int);
52 /* Just to save some typing. */
53 #define STACK_PUSH(s, typetag, value) \
56 status = tre_stack_push_ ## typetag(s, value); \
58 while (/*CONSTCOND*/0)
60 #define STACK_PUSHX(s, typetag, value) \
62 status = tre_stack_push_ ## typetag(s, value); \
63 if (status != REG_OK) \
67 #define STACK_PUSHR(s, typetag, value) \
69 reg_errcode_t _status; \
70 _status = tre_stack_push_ ## typetag(s, value); \
71 if (_status != REG_OK) \
75 #endif /* TRE_STACK_H */