Commit d0baac98 authored by Paul Eggert's avatar Paul Eggert
Browse files

Modernize and clean up gmalloc.c to assume C89 (Bug#9119).

* gmalloc.c: (_MALLOC_INTERNAL, _MALLOC_H, _PP, __ptr_t)
(__malloc_size_t, __malloc_ptrdiff_t):
Remove.  All uses removed, replaced by the definiens if needed,
since we can assume C89 or better now.
Include <stdint.h>, for PTRDIFF_MAX, uintptr_t.
(protect_malloc_state, align, get_contiguous_space)
(malloc_atfork_handler_prepare, malloc_atfork_handler_parent)
(malloc_atfork_handler_child, malloc_enable_thread)
(malloc_initialize_1, __malloc_initialize, morecore_nolock)
(_malloc_internal_nolock, _malloc_internal, malloc, _malloc)
(_free, _realloc, _free_internal_nolock, _free_internal, free, cfree)
(special_realloc, _realloc_internal_nolock, _realloc_internal)
(realloc, calloc, __default_morecore, memalign, valloc, checkhdr)
(freehook, mallochook, reallochook, mabort, mcheck, mprobe):
Define using prototypes, not old style.
(align, _malloc_internal_nolock, _free_internal_nolock, memalign):
Don't assume ptrdiff_t and uintptr_t are no wider than unsigned long.
(align): Don't assume that signed integer overflow wraps around.
Omit unused local var.
(malloc_initialize_1, morecore_nolock, _malloc_internal_nolock)
(_free_internal_nolock, memalign, mallochook, reallochook):
Omit no-longer-needed casts.
(valloc): Use getpagesize, not __getpagesize.
(MAGICWORD, MAGICFREE): Now randomish size_t values, not 32-bit.
(struct hdr): The 'magic' member is now size_t, not unsigned long.
parent eeddc531
2012-04-22 Paul Eggert <eggert@cs.ucla.edu>
Modernize and clean up gmalloc.c to assume C89 (Bug#9119).
* gmalloc.c: (_MALLOC_INTERNAL, _MALLOC_H, _PP, __ptr_t)
(__malloc_size_t, __malloc_ptrdiff_t):
Remove. All uses removed, replaced by the definiens if needed,
since we can assume C89 or better now.
Include <stdint.h>, for PTRDIFF_MAX, uintptr_t.
(protect_malloc_state, align, get_contiguous_space)
(malloc_atfork_handler_prepare, malloc_atfork_handler_parent)
(malloc_atfork_handler_child, malloc_enable_thread)
(malloc_initialize_1, __malloc_initialize, morecore_nolock)
(_malloc_internal_nolock, _malloc_internal, malloc, _malloc)
(_free, _realloc, _free_internal_nolock, _free_internal, free, cfree)
(special_realloc, _realloc_internal_nolock, _realloc_internal)
(realloc, calloc, __default_morecore, memalign, valloc, checkhdr)
(freehook, mallochook, reallochook, mabort, mcheck, mprobe):
Define using prototypes, not old style.
(align, _malloc_internal_nolock, _free_internal_nolock, memalign):
Don't assume ptrdiff_t and uintptr_t are no wider than unsigned long.
(align): Don't assume that signed integer overflow wraps around.
Omit unused local var.
(malloc_initialize_1, morecore_nolock, _malloc_internal_nolock)
(_free_internal_nolock, memalign, mallochook, reallochook):
Omit no-longer-needed casts.
(valloc): Use getpagesize, not __getpagesize.
(MAGICWORD, MAGICFREE): Now randomish size_t values, not 32-bit.
(struct hdr): The 'magic' member is now size_t, not unsigned long.
* dbusbind.c (XD_DBUS_VALIDATE_OBJECT): Define only if needed.
2012-04-22 Michael Albinus <michael.albinus@gmx.de>
......
/* This file is no longer automatically generated from libc. */
#define _MALLOC_INTERNAL
/* The malloc headers and source files from the C library follow here. */
/* Declarations for `malloc' and friends.
Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004,
2005, 2006, 2007 Free Software Foundation, Inc.
......@@ -27,12 +21,6 @@ Fifth Floor, Boston, MA 02110-1301, USA.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
#ifndef _MALLOC_H
#define _MALLOC_H 1
#ifdef _MALLOC_INTERNAL
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
......@@ -41,62 +29,44 @@ Fifth Floor, Boston, MA 02110-1301, USA.
#define USE_PTHREAD
#endif
#undef PP
#define PP(args) args
#undef __ptr_t
#define __ptr_t void *
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include <unistd.h>
#ifdef USE_PTHREAD
#include <pthread.h>
#endif
#endif /* _MALLOC_INTERNAL. */
#ifdef __cplusplus
extern "C"
{
#endif
#include <stddef.h>
#define __malloc_size_t size_t
#define __malloc_ptrdiff_t ptrdiff_t
/* Allocate SIZE bytes of memory. */
extern __ptr_t malloc PP ((__malloc_size_t __size));
extern void *malloc (size_t size);
/* Re-allocate the previously allocated block
in __ptr_t, making the new block SIZE bytes long. */
extern __ptr_t realloc PP ((__ptr_t __ptr, __malloc_size_t __size));
in ptr, making the new block SIZE bytes long. */
extern void *realloc (void *ptr, size_t size);
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
extern __ptr_t calloc PP ((__malloc_size_t __nmemb, __malloc_size_t __size));
extern void *calloc (size_t nmemb, size_t size);
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
extern void free PP ((__ptr_t __ptr));
extern void free (void *ptr);
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
#if !defined (_MALLOC_INTERNAL) || defined (MSDOS) /* Avoid conflict. */
extern __ptr_t memalign PP ((__malloc_size_t __alignment,
__malloc_size_t __size));
extern int posix_memalign PP ((__ptr_t *, __malloc_size_t,
__malloc_size_t size));
#endif
/* Allocate SIZE bytes on a page boundary. */
#if ! (defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC))
extern __ptr_t valloc PP ((__malloc_size_t __size));
#ifdef MSDOS
extern void *memalign (size_t, size_t);
extern int posix_memalign (void **, size_t, size_t);
#endif
#ifdef USE_PTHREAD
/* Set up mutexes and make malloc etc. thread-safe. */
extern void malloc_enable_thread PP ((void));
extern void malloc_enable_thread (void);
#endif
#ifdef _MALLOC_INTERNAL
/* The allocator divides the heap into blocks of fixed size; large
requests receive one or more whole blocks, and small requests
receive a fragment of a block. Fragment sizes are powers of two,
......@@ -128,22 +98,22 @@ typedef union
{
struct
{
__malloc_size_t nfree; /* Free frags in a fragmented block. */
__malloc_size_t first; /* First free fragment of the block. */
size_t nfree; /* Free frags in a fragmented block. */
size_t first; /* First free fragment of the block. */
} frag;
/* For a large object, in its first block, this has the number
of blocks in the object. In the other blocks, this has a
negative number which says how far back the first block is. */
__malloc_ptrdiff_t size;
ptrdiff_t size;
} info;
} busy;
/* Heap information for a free block
(that may be the first of a free cluster). */
struct
{
__malloc_size_t size; /* Size (in blocks) of a free cluster. */
__malloc_size_t next; /* Index of next free cluster. */
__malloc_size_t prev; /* Index of previous free cluster. */
size_t size; /* Size (in blocks) of a free cluster. */
size_t next; /* Index of next free cluster. */
size_t prev; /* Index of previous free cluster. */
} free;
} malloc_info;
......@@ -155,13 +125,13 @@ extern malloc_info *_heapinfo;
/* Address to block number and vice versa. */
#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
#define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase))
#define ADDRESS(B) ((void *) (((B) - 1) * BLOCKSIZE + _heapbase))
/* Current search index for the heap table. */
extern __malloc_size_t _heapindex;
extern size_t _heapindex;
/* Limit of valid info table indices. */
extern __malloc_size_t _heaplimit;
extern size_t _heaplimit;
/* Doubly linked lists of free fragments. */
struct list
......@@ -177,26 +147,26 @@ extern struct list _fraghead[];
struct alignlist
{
struct alignlist *next;
__ptr_t aligned; /* The address that memaligned returned. */
__ptr_t exact; /* The address that malloc returned. */
void *aligned; /* The address that memaligned returned. */
void *exact; /* The address that malloc returned. */
};
extern struct alignlist *_aligned_blocks;
/* Instrumentation. */
extern __malloc_size_t _chunks_used;
extern __malloc_size_t _bytes_used;
extern __malloc_size_t _chunks_free;
extern __malloc_size_t _bytes_free;
extern size_t _chunks_used;
extern size_t _bytes_used;
extern size_t _chunks_free;
extern size_t _bytes_free;
/* Internal versions of `malloc', `realloc', and `free'
used when these functions need to call each other.
They are the same but don't call the hooks. */
extern __ptr_t _malloc_internal PP ((__malloc_size_t __size));
extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size));
extern void _free_internal PP ((__ptr_t __ptr));
extern __ptr_t _malloc_internal_nolock PP ((__malloc_size_t __size));
extern __ptr_t _realloc_internal_nolock PP ((__ptr_t __ptr, __malloc_size_t __size));
extern void _free_internal_nolock PP ((__ptr_t __ptr));
extern void *_malloc_internal (size_t);
extern void *_realloc_internal (void *, size_t);
extern void _free_internal (void *);
extern void *_malloc_internal_nolock (size_t);
extern void *_realloc_internal_nolock (void *, size_t);
extern void _free_internal_nolock (void *);
#ifdef USE_PTHREAD
extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
......@@ -228,39 +198,36 @@ extern int _malloc_thread_enabled_p;
#define UNLOCK_ALIGNED_BLOCKS()
#endif
#endif /* _MALLOC_INTERNAL. */
/* Given an address in the middle of a malloc'd object,
return the address of the beginning of the object. */
extern __ptr_t malloc_find_object_address PP ((__ptr_t __ptr));
extern void *malloc_find_object_address (void *ptr);
/* Underlying allocation function; successive calls should
return contiguous pieces of memory. */
extern __ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size));
extern void *(*__morecore) (ptrdiff_t size);
/* Default value of `__morecore'. */
extern __ptr_t __default_morecore PP ((__malloc_ptrdiff_t __size));
extern void *__default_morecore (ptrdiff_t size);
/* If not NULL, this function is called after each time
`__morecore' is called to increase the data size. */
extern void (*__after_morecore_hook) PP ((void));
extern void (*__after_morecore_hook) (void);
/* Number of extra blocks to get each time we ask for more core.
This reduces the frequency of calling `(*__morecore)'. */
extern __malloc_size_t __malloc_extra_blocks;
extern size_t __malloc_extra_blocks;
/* Nonzero if `malloc' has been called and done its initialization. */
extern int __malloc_initialized;
/* Function called to initialize malloc data structures. */
extern int __malloc_initialize PP ((void));
extern int __malloc_initialize (void);
/* Hooks for debugging versions. */
extern void (*__malloc_initialize_hook) PP ((void));
extern void (*__free_hook) PP ((__ptr_t __ptr));
extern __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size));
extern __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size));
extern __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size,
__malloc_size_t __alignment));
extern void (*__malloc_initialize_hook) (void);
extern void (*__free_hook) (void *ptr);
extern void *(*__malloc_hook) (size_t size);
extern void *(*__realloc_hook) (void *ptr, size_t size);
extern void *(*__memalign_hook) (size_t size, size_t alignment);
/* Return values for `mprobe': these are the kinds of inconsistencies that
`mcheck' enables detection of. */
......@@ -277,52 +244,37 @@ enum mcheck_status
before `malloc' is ever called. ABORTFUNC is called with an error code
(see enum above) when an inconsistency is detected. If ABORTFUNC is
null, the standard function prints on stderr and then calls `abort'. */
extern int mcheck PP ((void (*__abortfunc) PP ((enum mcheck_status))));
extern int mcheck (void (*abortfunc) (enum mcheck_status));
/* Check for aberrations in a particular malloc'd block. You must have
called `mcheck' already. These are the same checks that `mcheck' does
when you free or reallocate a block. */
extern enum mcheck_status mprobe PP ((__ptr_t __ptr));
extern enum mcheck_status mprobe (void *ptr);
/* Activate a standard collection of tracing hooks. */
extern void mtrace PP ((void));
extern void muntrace PP ((void));
extern void mtrace (void);
extern void muntrace (void);
/* Statistics available to the user. */
struct mstats
{
__malloc_size_t bytes_total; /* Total size of the heap. */
__malloc_size_t chunks_used; /* Chunks allocated by the user. */
__malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */
__malloc_size_t chunks_free; /* Chunks in the free list. */
__malloc_size_t bytes_free; /* Byte total of chunks in the free list. */
size_t bytes_total; /* Total size of the heap. */
size_t chunks_used; /* Chunks allocated by the user. */
size_t bytes_used; /* Byte total of user-allocated chunks. */
size_t chunks_free; /* Chunks in the free list. */
size_t bytes_free; /* Byte total of chunks in the free list. */
};
/* Pick up the current statistics. */
extern struct mstats mstats PP ((void));
extern struct mstats mstats (void);
/* Call WARNFUN with a warning message when memory usage is high. */
extern void memory_warnings PP ((__ptr_t __start,
void (*__warnfun) PP ((const char *))));
/* Relocating allocator. */
/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
extern __ptr_t r_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
/* Free the storage allocated in HANDLEPTR. */
extern void r_alloc_free PP ((__ptr_t *__handleptr));
/* Adjust the block at HANDLEPTR to be SIZE bytes long. */
extern __ptr_t r_re_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
extern void memory_warnings (void *start, void (*warnfun) (const char *));
#ifdef __cplusplus
}
#endif
#endif /* malloc.h */
/* Memory allocator `malloc'.
Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
......@@ -345,10 +297,6 @@ Fifth Floor, Boston, MA 02110-1301, USA.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
#ifndef _MALLOC_INTERNAL
#define _MALLOC_INTERNAL
#include <malloc.h>
#endif
#include <errno.h>
/* On Cygwin there are two heaps. temacs uses the static heap
......@@ -362,15 +310,15 @@ Fifth Floor, Boston, MA 02110-1301, USA.
this is changed in the future, we'll have to similarly deal with
reinitializing ralloc. */
#ifdef CYGWIN
extern __ptr_t bss_sbrk PP ((ptrdiff_t __size));
extern void *bss_sbrk (ptrdiff_t size);
extern int bss_sbrk_did_unexec;
char *bss_sbrk_heapbase; /* _heapbase for static heap */
malloc_info *bss_sbrk_heapinfo; /* _heapinfo for static heap */
#endif
__ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = __default_morecore;
void *(*__morecore) (ptrdiff_t size) = __default_morecore;
/* Debugging hook for `malloc'. */
__ptr_t (*__malloc_hook) PP ((__malloc_size_t __size));
void *(*__malloc_hook) (size_t size);
/* Pointer to the base of the first block. */
char *_heapbase;
......@@ -379,30 +327,30 @@ char *_heapbase;
malloc_info *_heapinfo;
/* Number of info entries. */
static __malloc_size_t heapsize;
static size_t heapsize;
/* Search index in the info table. */
__malloc_size_t _heapindex;
size_t _heapindex;
/* Limit of valid info table indices. */
__malloc_size_t _heaplimit;
size_t _heaplimit;
/* Free lists for each fragment size. */
struct list _fraghead[BLOCKLOG];
/* Instrumentation. */
__malloc_size_t _chunks_used;
__malloc_size_t _bytes_used;
__malloc_size_t _chunks_free;
__malloc_size_t _bytes_free;
size_t _chunks_used;
size_t _bytes_used;
size_t _chunks_free;
size_t _bytes_free;
/* Are you experienced? */
int __malloc_initialized;
__malloc_size_t __malloc_extra_blocks;
size_t __malloc_extra_blocks;
void (*__malloc_initialize_hook) PP ((void));
void (*__after_morecore_hook) PP ((void));
void (*__malloc_initialize_hook) (void);
void (*__after_morecore_hook) (void);
#if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE
......@@ -419,12 +367,11 @@ void (*__after_morecore_hook) PP ((void));
#include <sys/mman.h>
static int state_protected_p;
static __malloc_size_t last_state_size;
static size_t last_state_size;
static malloc_info *last_heapinfo;
void
protect_malloc_state (protect_p)
int protect_p;
protect_malloc_state (int protect_p)
{
/* If _heapinfo has been relocated, make sure its old location
isn't left read-only; it will be reused by malloc. */
......@@ -453,29 +400,25 @@ protect_malloc_state (protect_p)
/* Aligned allocation. */
static __ptr_t align PP ((__malloc_size_t));
static __ptr_t
align (size)
__malloc_size_t size;
static void *
align (size_t size)
{
__ptr_t result;
unsigned long int adj;
void *result;
ptrdiff_t adj;
/* align accepts an unsigned argument, but __morecore accepts a
signed one. This could lead to trouble if SIZE overflows a
signed int type accepted by __morecore. We just punt in that
signed one. This could lead to trouble if SIZE overflows the
ptrdiff_t type accepted by __morecore. We just punt in that
case, since they are requesting a ludicrous amount anyway. */
if ((__malloc_ptrdiff_t)size < 0)
if (PTRDIFF_MAX < size)
result = 0;
else
result = (*__morecore) (size);
adj = (unsigned long int) ((unsigned long int) ((char *) result -
(char *) NULL)) % BLOCKSIZE;
adj = (uintptr_t) result % BLOCKSIZE;
if (adj != 0)
{
__ptr_t new;
adj = BLOCKSIZE - adj;
new = (*__morecore) (adj);
(*__morecore) (adj);
result = (char *) result + adj;
}
......@@ -488,14 +431,11 @@ align (size)
/* Get SIZE bytes, if we can get them starting at END.
Return the address of the space we got.
If we cannot get space at END, fail and return 0. */
static __ptr_t get_contiguous_space PP ((__malloc_ptrdiff_t, __ptr_t));
static __ptr_t
get_contiguous_space (size, position)
__malloc_ptrdiff_t size;
__ptr_t position;
static void *
get_contiguous_space (ptrdiff_t size, void *position)
{
__ptr_t before;
__ptr_t after;
void *before;
void *after;
before = (*__morecore) (0);
/* If we can tell in advance that the break is at the wrong place,
......@@ -525,7 +465,7 @@ get_contiguous_space (size, position)
static inline void
register_heapinfo (void)
{
__malloc_size_t block, blocks;
size_t block, blocks;
block = BLOCK (_heapinfo);
blocks = BLOCKIFY (heapsize * sizeof (malloc_info));
......@@ -548,21 +488,21 @@ pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
int _malloc_thread_enabled_p;
static void
malloc_atfork_handler_prepare ()
malloc_atfork_handler_prepare (void)
{
LOCK ();
LOCK_ALIGNED_BLOCKS ();
}
static void
malloc_atfork_handler_parent ()
malloc_atfork_handler_parent (void)
{
UNLOCK_ALIGNED_BLOCKS ();
UNLOCK ();
}
static void
malloc_atfork_handler_child ()
malloc_atfork_handler_child (void)
{
UNLOCK_ALIGNED_BLOCKS ();
UNLOCK ();
......@@ -570,7 +510,7 @@ malloc_atfork_handler_child ()
/* Set up mutexes and make malloc etc. thread-safe. */
void
malloc_enable_thread ()
malloc_enable_thread (void)
{
if (_malloc_thread_enabled_p)
return;
......@@ -589,7 +529,7 @@ malloc_enable_thread ()
#endif
static void
malloc_initialize_1 ()
malloc_initialize_1 (void)
{
#ifdef GC_MCHECK
mcheck (NULL);
......@@ -609,7 +549,7 @@ malloc_initialize_1 ()
(*__malloc_initialize_hook) ();
heapsize = HEAP / BLOCKSIZE;
_heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
_heapinfo = align (heapsize * sizeof (malloc_info));
if (_heapinfo == NULL)
return;
memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
......@@ -630,7 +570,7 @@ malloc_initialize_1 ()
main will call malloc which calls this function. That is before any threads
or signal handlers has been set up, so we don't need thread protection. */
int
__malloc_initialize ()
__malloc_initialize (void)
{
if (__malloc_initialized)
return 0;
......@@ -644,14 +584,12 @@ static int morecore_recursing;
/* Get neatly aligned memory, initializing or
growing the heap info table as necessary. */
static __ptr_t morecore_nolock PP ((__malloc_size_t));
static __ptr_t
morecore_nolock (size)
__malloc_size_t size;
static void *
morecore_nolock (size_t size)
{
__ptr_t result;
void *result;
malloc_info *newinfo, *oldinfo;
__malloc_size_t newsize;
size_t newsize;
if (morecore_recursing)
/* Avoid recursion. The caller will know how to handle a null return. */
......@@ -664,7 +602,7 @@ morecore_nolock (size)
PROTECT_MALLOC_STATE (0);
/* Check if we need to grow the info table. */
if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize)
if ((size_t) BLOCK ((char *) result + size) > heapsize)
{
/* Calculate the new _heapinfo table size. We do not account for the
added blocks in the table itself, as we hope to place them in
......@@ -673,7 +611,7 @@ morecore_nolock (size)
newsize = heapsize;
do
newsize *= 2;
while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize);
while ((size_t) BLOCK ((char *) result + size) > newsize);
/* We must not reuse existing core for the new info table when called
from realloc in the case of growing a large block, because the
......@@ -689,8 +627,8 @@ morecore_nolock (size)
`morecore_recursing' flag and return null. */
int save = errno; /* Don't want to clobber errno with ENOMEM. */
morecore_recursing = 1;
newinfo = (malloc_info *) _realloc_internal_nolock
(_heapinfo, newsize * sizeof (malloc_info));
newinfo = _realloc_internal_nolock (_heapinfo,
newsize * sizeof (malloc_info));
morecore_recursing = 0;
if (newinfo == NULL)
errno = save;
......@@ -710,7 +648,7 @@ morecore_nolock (size)
/* Allocate new space for the malloc info table. */
while (1)
{
newinfo = (malloc_info *) align (newsize * sizeof (malloc_info));
newinfo = align (newsize * sizeof (malloc_info));
/* Did it fail? */
if (newinfo == NULL)
......@@ -721,8 +659,8 @@ morecore_nolock (size)
/* Is it big enough to record status for its own space?
If so, we win. */
if ((__malloc_size_t) BLOCK ((char *) newinfo
+ newsize * sizeof (malloc_info))
if ((size_t) BLOCK ((char *) newinfo
+ newsize * sizeof (malloc_info))
< newsize)
break;
......@@ -759,13 +697,12 @@ morecore_nolock (size)
}
/* Allocate memory from the heap. */
__ptr_t
_malloc_internal_nolock (size)
__malloc_size_t size;
void *
_malloc_internal_nolock (size_t size)
{
__ptr_t result;
__malloc_size_t block, blocks, lastblocks, start;
register __malloc_size_t i;
void *result;
size_t block, blocks, lastblocks, start;
register size_t i;
struct list *next;
/* ANSI C allows `malloc (0)' to either return NULL, or to return a
......@@ -790,7 +727,7 @@ _malloc_internal_nolock (size)
{
/* Small allocation to receive a fragment of a block.
Determine the logarithm to base two of the fragment size. */
register __malloc_size_t log = 1;
register size_t log = 1;
--size;
while ((size /= 2) != 0)
++log;
......@@ -803,15 +740,14 @@ _malloc_internal_nolock (size)
/* 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_t) next;
result = next;
next->prev->next = next->next;
if (next->next != NULL)
next->next->prev = next->prev;
block = BLOCK (result);
if (--_heapinfo[block].busy.info.frag.nfree != 0)
_heapinfo[block].busy.info.frag.first = (unsigned long int)
((unsigned long int) ((char *) next->next - (char *) NULL)
% BLOCKSIZE) >> log;
_heapinfo[block].busy.info.frag.first =
(uintptr_t) next->next % BLOCKSIZE >> log;