From dc091413d34855f5cc7dc50fbfcfa567b9df9f3b Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Thu, 19 Mar 2026 20:07:18 +0000 Subject: [PATCH] [MPS] Allocate itree stack nodes ambiguously * src/itree.c (itree_stack_create) [MPS]: Use 'igc_xalloc_raw_exact'. (itree_stack_destroy) [MPS]: Use 'igc_xfree'. (itree_stack_ensure_space) [MPS]: Use 'igc_xpalloc_raw_exact'. --- src/itree.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 } }