- o->op->stack[++(o->op->stackp)].lenb = o->bp;
- o->op->stack[o->op->stackp].len_offset = odr_tell(o);
-#ifdef ODR_DEBUG
- fprintf(stderr, "[cons_begin(%d)]", o->op->stackp);
-#endif
+ else if (o->op->stack_top && !o->op->stack_top->next)
+ {
+ /* must allocate new entry (not first) */
+ int sz = 0;
+ struct odr_constack *st;
+ /* check size first */
+ for (st = o->op->stack_top; st; st = st->prev)
+ sz++;
+
+ if (sz >= ODR_MAX_STACK)
+ {
+ odr_seterror(o, OSTACK, 30);
+ return 0;
+ }
+ o->op->stack_top->next = (struct odr_constack *)
+ odr_malloc(o, sizeof(*o->op->stack_top));
+ o->op->stack_top->next->prev = o->op->stack_top;
+ o->op->stack_top->next->next = 0;
+
+ o->op->stack_top = o->op->stack_top->next;
+ }
+ else if (!o->op->stack_top)
+ {
+ /* stack empty */
+ if (!o->op->stack_first)
+ {
+ /* first item must be allocated */
+ o->op->stack_first = (struct odr_constack *)
+ odr_malloc(o, sizeof(*o->op->stack_top));
+ o->op->stack_first->prev = 0;
+ o->op->stack_first->next = 0;
+ }
+ o->op->stack_top = o->op->stack_first;
+ assert(o->op->stack_top->prev == 0);
+ }
+ o->op->stack_top->lenb = o->bp;
+ o->op->stack_top->len_offset = odr_tell(o);
+ o->op->stack_top->name = name ? name : "?";