00dcddaaa0
2004-07-08 Frank Ch. Eigler <fche@redhat.com> ANSI C conversion, libmudflap specialization, recursion limiting. * splay-tree.h (splay_tree_{de,}allocate_fn): Remove allocation_data argument and indirection function pointers, update callers. (splay_tree_s): Add statistics and recursion control fields num_keys, max_depth, depth, rebalance_p. * splay-tree.c (splay_tree_splay_helper): Track recursion depth. Back out of search if it exceeds limit. (splay_tree_splay): Manage recursion limiting with rebalancing as needed. (splay_tree_new): More initialization. (splay_tree_rebalance): New function. (splay_tree_foreach): Rewrite using nonrecursive logic. (splay_tree_xmalloc_allocate, splay_tree_xmalloc_deallocate): Remove. Point indirect calls to mf-runtime.c's routines. (splay_tree_compare_ints, splay_tree_compare_pointers): Remove unused functions. (splay_tree_delete, splay_tree_delete_helper): Ditto. * testsuite/heap-scalestress.c: New test based on one from Eyal Lebedinsky <eyal@eyal.emu.id.au>: From-SVN: r84303
80 lines
1.1 KiB
C
80 lines
1.1 KiB
C
/* zz30
|
|
*
|
|
* demonstrate a splay-tree depth problem
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#ifndef SCALE
|
|
#define SCALE 100000
|
|
#endif
|
|
|
|
|
|
struct list
|
|
{
|
|
struct list *next;
|
|
};
|
|
|
|
|
|
int
|
|
main ()
|
|
{
|
|
struct list *head = NULL;
|
|
struct list *tail = NULL;
|
|
struct list *p;
|
|
long n;
|
|
int direction;
|
|
|
|
for (direction = 0; direction < 2; direction++)
|
|
{
|
|
fprintf (stdout, "allocating\n");
|
|
fflush (stdout);
|
|
|
|
for (n = 0; n < SCALE; ++n)
|
|
{
|
|
p = malloc (sizeof *p);
|
|
if (NULL == p)
|
|
{
|
|
fprintf (stdout, "malloc failed\n");
|
|
break;
|
|
}
|
|
if (direction == 0)
|
|
{ /* add at tail */
|
|
p->next = NULL;
|
|
if (NULL != tail)
|
|
tail->next = p;
|
|
else
|
|
head = p;
|
|
tail = p;
|
|
}
|
|
else
|
|
{ /* add at head */
|
|
p->next = head;
|
|
if (NULL == tail)
|
|
tail = p;
|
|
head = p;
|
|
}
|
|
}
|
|
|
|
fprintf (stdout, "freeing\n");
|
|
fflush (stdout);
|
|
|
|
while (NULL != head)
|
|
{
|
|
p = head;
|
|
head = head->next;
|
|
free (p);
|
|
}
|
|
|
|
}
|
|
|
|
fprintf (stdout, "done\n");
|
|
fflush (stdout);
|
|
|
|
return (0);
|
|
}
|
|
|
|
/* { dg-output "allocating.*freeing.*allocating.*freeing.*done" } */
|