X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/e490694a089a5afd1002a283c27d53a32d684171..ce75f06e9110ceda73c75997a017f7c09dd9dd33:/src/gmalloc.c diff --git a/src/gmalloc.c b/src/gmalloc.c index b1f8513c5f..f1be37ba34 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -110,10 +110,6 @@ extern "C" #define NULL 0 #endif -#ifndef FREE_RETURN_TYPE -#define FREE_RETURN_TYPE void -#endif - /* Allocate SIZE bytes of memory. */ extern __ptr_t malloc PP ((__malloc_size_t __size)); @@ -123,12 +119,14 @@ extern __ptr_t realloc PP ((__ptr_t __ptr, __malloc_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)); /* Free a block allocated by `malloc', `realloc' or `calloc'. */ -extern FREE_RETURN_TYPE free PP ((__ptr_t __ptr)); +extern void free PP ((__ptr_t __ptr)); /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ #if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* 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. */ @@ -582,7 +580,6 @@ register_heapinfo () } #ifdef USE_PTHREAD -static pthread_once_t malloc_init_once_control = PTHREAD_ONCE_INIT; pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER; int _malloc_thread_enabled_p; @@ -656,18 +653,16 @@ malloc_initialize_1 () return; } -/* Set everything up and remember that we have. */ +/* Set everything up and remember that we have. + 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 () { -#ifdef USE_PTHREAD - pthread_once (&malloc_init_once_control, malloc_initialize_1); -#else if (__malloc_initialized) return 0; malloc_initialize_1 (); -#endif return __malloc_initialized; } @@ -817,11 +812,6 @@ _malloc_internal_nolock (size) if (size < sizeof (struct list)) size = sizeof (struct list); -#ifdef SUNOS_LOCALTIME_BUG - if (size < 16) - size = 16; -#endif - /* Determine the allocation policy based on the request size. */ if (size <= BLOCKSIZE / 2) { @@ -921,7 +911,7 @@ _malloc_internal_nolock (size) final free block; if so we don't need to get as much. */ if (_heaplimit != 0 && block + lastblocks == _heaplimit && /* We can't do this if we will have to make the heap info - table bigger to accomodate the new space. */ + table bigger to accommodate the new space. */ block + wantblocks <= heapsize && get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE, ADDRESS (block + lastblocks))) @@ -1088,8 +1078,7 @@ Fifth Floor, Boston, MA 02110-1301, USA. /* Cope with systems lacking `memmove'. */ #ifndef memmove -#if (defined (MEMMOVE_MISSING) || \ - !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) +#if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) #ifdef emacs #undef __malloc_safe_bcopy #define __malloc_safe_bcopy safe_bcopy @@ -1369,7 +1358,7 @@ _free_internal (ptr) /* Return memory to the heap. */ -FREE_RETURN_TYPE +void free (ptr) __ptr_t ptr; { @@ -1422,8 +1411,7 @@ Fifth Floor, Boston, MA 02110-1301, USA. /* Cope with systems lacking `memmove'. */ -#if (defined (MEMMOVE_MISSING) || \ - !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) +#if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) #ifdef emacs #undef __malloc_safe_bcopy @@ -1718,17 +1706,17 @@ MA 02110-1301, USA. */ #include #endif -#ifndef __GNU_LIBRARY__ +/* uClibc defines __GNU_LIBRARY__, but it is not completely + compatible. */ +#if !defined(__GNU_LIBRARY__) || defined(__UCLIBC__) #define __sbrk sbrk -#endif - -#ifdef __GNU_LIBRARY__ +#else /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ /* It is best not to declare this and cast its result on foreign operating systems with potentially hostile include files. */ #include extern __ptr_t __sbrk PP ((ptrdiff_t increment)); -#endif +#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ #ifndef NULL #define NULL 0 @@ -1860,6 +1848,36 @@ memalign (alignment, size) return result; } +#ifndef ENOMEM +#define ENOMEM 12 +#endif + +#ifndef EINVAL +#define EINVAL 22 +#endif + +int +posix_memalign (memptr, alignment, size) + __ptr_t *memptr; + __malloc_size_t alignment; + __malloc_size_t size; +{ + __ptr_t mem; + + if (alignment == 0 + || alignment % sizeof (__ptr_t) != 0 + || (alignment & (alignment - 1)) != 0) + return EINVAL; + + mem = memalign (alignment, size); + if (mem == NULL) + return ENOMEM; + + *memptr = mem; + + return 0; +} + #endif /* Not DJGPP v1 */ /* Allocate memory on a page boundary. Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.