=== modified file 'include/obstack.h' --- include/obstack.h 2011-10-22 01:35:29 +0000 +++ include/obstack.h 2012-05-30 01:18:36 +0000 @@ -538,6 +538,40 @@ __extension__ \ #endif /* not __GNUC__ or not __STDC__ */ + +/* The MARK operation allows you to save the state of the obstack by pushing + a special marker onto the stack. When you RELEASE that marker the obstack + returns to its previous state which means all memory allocated after the + marker is free'd, and most importantly if you were growing an object before + pushing the marker, you can now continue growing it. Needless to say that + the marker is destroyed if you release/free an earlier marker/object. */ +static inline void *obstack_mark (struct obstack *o) +{ + void **old_base, **p; + + /* Rellocation may happen when growing...*/ + obstack_blank (o, sizeof (void *)); + /* ...so save object_base afterwards... */ + old_base = (void **) o->object_base; + /* ...and save the end of the previous object to return it. */ + p = (void **) & o->next_free [-1 * sizeof (void *)]; + + /* Finally make it possible to start growing new objects */ + obstack_finish (o); + /* and store saved state in the new space we grew. */ + *p = old_base; + + return p; +} + +static inline void obstack_release (struct obstack *o, void *p) +{ + void *old_base = *(void **) p; + obstack_free (o, p); + o->object_base = (char *) old_base; +} + + #ifdef __cplusplus } /* C++ */ #endif