mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-03-22 06:41:04 -07:00
[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'.
This commit is contained in:
parent
9a04a21b32
commit
dc091413d3
1 changed files with 20 additions and 3 deletions
23
src/itree.c
23
src/itree.c
|
|
@ -136,8 +136,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue