The AStack module provides a stack container which is fully built on the
program stack.
By being fully on the program stack -which means malloc is never called-
an AStack instance is automatically destroyed when you leave the function
in which it was built.
This container must be used with care:
- Create it in the function you want it to be destroyed
- Add nodes inside the stack only from the function where it was created
-
You can insert elements allocated with:
- bunny_alloca
- alloca
- By being a non static local variable
- Eventually, by being a global variable or a static variable
Never insert elements created by:
The general rule being: do not insert elements that need to be freed.
The Astack module is only available on systems that provide an alloca function.
The astack module header is lapin/container/astack.h.
Description
  This structure is the main data of the AStack container.
  This type cannot be declared on stack. It must be created by a call
to
bunny_new_astack.
Attributes
-
const size_t length:
  The amount of elements in the AStack container.
-
const void * const * const * top:
  A pointer to a node containing the first element of the AStack container,
and the address of its following element if there is one.
This attribute is NULL if there is no element inside the AStack.
INDEX
Description
  This structure is the node in which every single data is referenced
inside the stack.
This type is an inside type of the Astack module and should not be created by you.
Attributes
-
void *data:
  A pointer to a stored data.
-
struct s_bunny_astack_node *next:
  The node following the current one or NULL if there is none.
INDEX
Description
  Create an Astack.
Return value
-
The function returns the address of the created Astack.
This function cannot fail without crashing your program by
stack overflow.
INDEX
k
Description
  Return the amount of elements inside the Astack container.
Return value
-
This function returns the amount of elements inside the Astack container.
INDEX
Description
  Return if the sent Astack container is empty.
Return value
-
This function returns true if the sent Astack is empty.
INDEX
Description
  Return the element that is on top of the sent Astack.
Return value
-
This function returns the top element of the sent Astack or NULL if there
is none.
INDEX
Description
  Push at the top of the Astack the sent data.
Parameters
-
t_bunny_astack *astack:
  The Astack in which the data will be pushed.
-
data:
  A data of any type that will be pushed at the top of the Astack.
INDEX
Description
  Remove the top element from the sent Astack.
Do not attempt to pop an empty stack!
INDEX