The most direct way to allocate an object in an obstack is with
obstack_alloc, which is invoked almost like malloc.
— Function: void * obstack_alloc (struct obstack *obstack-ptr, int size)
This allocates an uninitialized block of size bytes in an obstack
and returns its address. Here obstack-ptr specifies which obstack
to allocate the block in; it is the address of the struct obstack
object which represents the obstack. Each obstack function or macro
requires you to specify an obstack-ptr as the first argument.
This function calls the obstack's obstack_chunk_alloc function if
it needs to allocate a new chunk of memory; it calls
obstack_alloc_failed_handler if allocation of memory by
For example, here is a function that allocates a copy of a string str
in a specific obstack, which is in the variable string_obstack: