/* Prototypes for local functions */
-static int initialize PARAMS ((struct mdesc *));
-static PTR morecore PARAMS ((struct mdesc *, size_t));
-static PTR align PARAMS ((struct mdesc *, size_t));
+static int initialize (struct mdesc *mdp);
+static void* morecore (struct mdesc *mdp, size_t size);
+static void* align (struct mdesc *mdp, size_t size);
/* Aligned allocation. */
-static PTR
-align (mdp, size)
- struct mdesc *mdp;
- size_t size;
+static void*
+align (struct mdesc *mdp, size_t size)
{
- PTR result;
+ void* result;
unsigned long int adj;
result = mdp -> morecore (mdp, size);
{
adj = BLOCKSIZE - adj;
mdp -> morecore (mdp, adj);
- result = (PTR) result + adj;
+ result = (char*) result + adj;
}
return (result);
}
/* Set everything up and remember that we have. */
static int
-initialize (mdp)
- struct mdesc *mdp;
+initialize (struct mdesc *mdp)
{
mdp -> heapsize = HEAP / BLOCKSIZE;
mdp -> heapinfo = (malloc_info *)
{
return (0);
}
- memset ((PTR)mdp -> heapinfo, 0, mdp -> heapsize * sizeof (malloc_info));
+ memset ((void*)mdp -> heapinfo, 0, mdp -> heapsize * sizeof (malloc_info));
mdp -> heapinfo[0].free.size = 0;
mdp -> heapinfo[0].free.next = mdp -> heapinfo[0].free.prev = 0;
mdp -> heapindex = 0;
- mdp -> heapbase = (PTR) mdp -> heapinfo;
+ mdp -> heapbase = (void*) mdp -> heapinfo;
mdp -> flags |= MMALLOC_INITIALIZED;
return (1);
}
/* Get neatly aligned memory, initializing or
growing the heap info table as necessary. */
-static PTR
-morecore (mdp, size)
- struct mdesc *mdp;
- size_t size;
+static void*
+morecore (struct mdesc *mdp, size_t size)
{
- PTR result;
+ void* result;
malloc_info *newinfo, *oldinfo;
size_t newsize;
}
/* Check if we need to grow the info table. */
- if ((size_t) BLOCK ((PTR) result + size) > mdp -> heapsize)
+ if ((size_t) BLOCK ((char*) result + size) > mdp -> heapsize)
{
newsize = mdp -> heapsize;
- while ((size_t) BLOCK ((PTR) result + size) > newsize)
+ while ((size_t) BLOCK ((char*) result + size) > newsize)
{
newsize *= 2;
}
mdp -> morecore (mdp, -size);
return (NULL);
}
- memset ((PTR) newinfo, 0, newsize * sizeof (malloc_info));
- memcpy ((PTR) newinfo, (PTR) mdp -> heapinfo,
+ memset ((void*) newinfo, 0, newsize * sizeof (malloc_info));
+ memcpy ((void*) newinfo, (void*) mdp -> heapinfo,
mdp -> heapsize * sizeof (malloc_info));
oldinfo = mdp -> heapinfo;
newinfo[BLOCK (oldinfo)].busy.type = 0;
newinfo[BLOCK (oldinfo)].busy.info.size
= BLOCKIFY (mdp -> heapsize * sizeof (malloc_info));
mdp -> heapinfo = newinfo;
- __mmalloc_free (mdp, (PTR)oldinfo);
+ __mmalloc_free (mdp, (void*)oldinfo);
mdp -> heapsize = newsize;
}
- mdp -> heaplimit = BLOCK ((PTR) result + size);
+ mdp -> heaplimit = BLOCK ((char*) result + size);
return (result);
}
/* Allocate memory from the heap. */
-PTR
+void*
mmalloc (md, size)
- PTR md;
+ void* md;
size_t size;
{
struct mdesc *mdp;
- PTR result;
+ void* result;
size_t block, blocks, lastblocks, start;
register size_t i;
struct list *next;
/* There are free fragments of this size.
Pop a fragment out of the fragment list and return it.
Update the block's nfree and first counters. */
- result = (PTR) next;
+ result = (void*) next;
next -> prev -> next = next -> next;
if (next -> next != NULL)
{
/* Link all fragments but the first into the free list. */
for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i)
{
- next = (struct list *) ((PTR) result + (i << log));
+ next = (struct list *) ((char*) result + (i << log));
next -> next = mdp -> fraghead[log].next;
next -> prev = &mdp -> fraghead[log];
next -> prev -> next = next;
the application contains any "hidden" calls to malloc/realloc/free (such
as inside a system library). */
-PTR
-malloc (size)
- size_t size;
+void*
+malloc (size_t size)
{
- PTR result;
- result = mmalloc ((PTR) NULL, size);
+ void* result;
+ result = mmalloc (NULL, size);
return (result);
}