diff --git a/src/itree.c b/src/itree.c index 0be8f3503fe..c2c78bb4757 100644 --- a/src/itree.c +++ b/src/itree.c @@ -136,8 +136,8 @@ along with GNU Emacs. If not, see . */ struct itree_stack { struct itree_node **nodes; - size_t size; - size_t length; + ptrdiff_t size; + ptrdiff_t length; }; /* This is just a simple dynamic array with stack semantics. */ @@ -146,8 +146,13 @@ static struct itree_stack* itree_stack_create (intmax_t initial_size) { struct itree_stack *stack = xmalloc (sizeof (struct itree_stack)); +#ifndef HAVE_MPS stack->size = max (0, initial_size); stack->nodes = xmalloc (stack->size * sizeof (struct itree_node*)); +#else + stack->size = max (1, initial_size); + stack->nodes = igc_xalloc_raw_exact (stack->size); +#endif stack->length = 0; return stack; } @@ -158,7 +163,13 @@ itree_stack_destroy (struct itree_stack *stack) if (! stack) return; if (stack->nodes) - xfree (stack->nodes); + { +#ifndef HAVE_MPS + xfree (stack->nodes); +#else + igc_xfree (stack->nodes); +#endif + } xfree (stack); } @@ -167,9 +178,15 @@ itree_stack_ensure_space (struct itree_stack *stack, uintmax_t nelements) { if (nelements > stack->size) { +#ifndef HAVE_MPS stack->size = (nelements + 1) * 2; stack->nodes = xrealloc (stack->nodes, stack->size * sizeof (*stack->nodes)); +#else + igc_xpalloc_raw_exact (&stack->nodes, &stack->size, + nelements - stack->size, -1, + "itree stack"); +#endif } }