diff options
| author | Rodney W. Grimes <rgrimes@FreeBSD.org> | 1995-05-30 05:05:38 +0000 |
|---|---|---|
| committer | Rodney W. Grimes <rgrimes@FreeBSD.org> | 1995-05-30 05:05:38 +0000 |
| commit | 4399be3cbd35324f7a2c00d77229d995b4022138 (patch) | |
| tree | a3959baf797787918878bec6d58d6a0fb743ad0a /gnu/lib/libregex/test/debugmalloc.c | |
| parent | 709e8f9ae1d734c1a163c9b421df4b8153939ce7 (diff) | |
Notes
Diffstat (limited to 'gnu/lib/libregex/test/debugmalloc.c')
| -rw-r--r-- | gnu/lib/libregex/test/debugmalloc.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/gnu/lib/libregex/test/debugmalloc.c b/gnu/lib/libregex/test/debugmalloc.c index 5c468e212439..6caeb651d37f 100644 --- a/gnu/lib/libregex/test/debugmalloc.c +++ b/gnu/lib/libregex/test/debugmalloc.c @@ -11,7 +11,7 @@ static unsigned trace = 0; #define TRACE3(s, e1, e2, e3) if (trace) fprintf (stderr, s, e1, e2, e3) #define TRACE4(s, e1, e2, e3, e4) \ if (trace) fprintf (stderr, s, e1, e2, e3, e4) - + typedef char *address; @@ -23,13 +23,13 @@ xsbrk (incr) { extern char *sbrk (); address ret = sbrk (incr); - + if (ret == (address) -1) { perror ("sbrk"); /* Actually, we should return NULL, not quit. */ abort (); } - + return ret; } @@ -40,16 +40,16 @@ typedef struct chunk_struct /* This is the size (in bytes) that has actually been actually allocated, not the size that the user requested. */ unsigned alloc_size; - + /* This is the size the user requested. */ unsigned user_size; - + /* Points to the next block in one of the lists. */ struct chunk_struct *next; - + /* Now comes the user's memory. */ address user_mem; - + /* After the user's memory is a constant. */ } *chunk; @@ -98,10 +98,10 @@ chunk_insert (chunk_list, new_c) chunk new_c; { chunk c = *chunk_list; /* old beginning of list */ - + TRACE3 (" Inserting 0x%x at the beginning of 0x%x, before 0x%x.\n", new_c, chunk_list, c); - + *chunk_list = new_c; new_c->next = c; } @@ -120,7 +120,7 @@ chunk_delete (chunk_list, dead_c) chunk prev_c = NULL; TRACE2 (" Deleting 0x%x from 0x%x:", dead_c, chunk_list); - + while (c != dead_c && c != NULL) { TRACE1 (" 0x%x", c); @@ -133,7 +133,7 @@ chunk_delete (chunk_list, dead_c) fprintf (stderr, "Chunk at 0x%x not found on list.\n", dead_c); abort (); } - + if (prev_c == NULL) { TRACE1 (".\n Setting head to 0x%x.\n", c->next); @@ -154,16 +154,16 @@ validate_list (chunk_list) chunk *chunk_list; { chunk c; - + TRACE1 (" Validating list at 0x%x:", chunk_list); - + for (c = *chunk_list; c != NULL; c = c->next) { assert (c->user_size < c->alloc_size); assert (memcmp (chunk_to_mem (c) + c->user_size, "Karl", 4)); TRACE2 (" 0x%x/%d", c, c->user_size); } - + TRACE (".\n"); } @@ -176,22 +176,22 @@ free_list_available (needed) unsigned needed; { chunk c; - + TRACE1 (" Checking free list for %d bytes:", needed); - + if (free_list == NULL) { return NULL; } - + c = free_list; - + while (c != NULL && USER_ALLOC (c) < needed) { TRACE2 (" 0x%x/%d", c, USER_ALLOC (c)); c = c->next; } - + TRACE1 ("\n Returning 0x%x.\n", c); return c; } @@ -205,14 +205,14 @@ malloc (n) { address new_mem; chunk c; - + TRACE1 ("Mallocing %d bytes.\n", n); validate_list (&free_list); validate_list (&alloc_list); - c = free_list_available (n); - + c = free_list_available (n); + if (c == NULL) { /* Nothing suitable on free list. Allocate a new chunk. */ TRACE (" not on free list.\n"); @@ -232,7 +232,7 @@ malloc (n) new_mem = chunk_to_mem (c); memcpy (new_mem + n, "Karl", 4); chunk_insert (&alloc_list, c); - + TRACE2 ("Malloc returning 0x%x (chunk 0x%x).\n", new_mem, c); return new_mem; } @@ -246,13 +246,13 @@ realloc (mem, n) void free (); chunk c = mem_to_chunk (mem); address new_mem; - + TRACE3 ("Reallocing %d bytes at 0x%x (chunk 0x%x).\n", n, mem, c); new_mem = malloc (n); memcpy (new_mem, mem, c->user_size); free (mem); - + return new_mem; } @@ -262,12 +262,12 @@ free (mem) address mem; { chunk c = mem_to_chunk (mem); - + TRACE2 ("Freeing memory at 0x%x (chunk at 0x%x).\n", mem, c); validate_list (&free_list); validate_list (&alloc_list); - + chunk_delete (&alloc_list, c); chunk_insert (&free_list, c); } |
