From 90889a692076f2c62486607d0354e0fca52364bc Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:40 -0800 Subject: Import Upstream version 5e5 --- gmalloc.c | 101 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) (limited to 'gmalloc.c') diff --git a/gmalloc.c b/gmalloc.c index b9b5e1e..eef1504 100644 --- a/gmalloc.c +++ b/gmalloc.c @@ -1,31 +1,30 @@ -/* 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. +/* "gmalloc.c" Declarations for `malloc' and friends. Copyright 1990, 91, 92, 93, 95, 96 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of +GNU Emacs is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. +General Public License for more details. -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If not, -write to the Free Software Foundation, Inc., 59 Temple Place, Suite -330, Boston, MA 02111, USA. +You should have received a copy of the GNU General Public +License along with GNU Emacs. If not, see +. */ +/* Written May 1989 by Mike Haertel. The author may be reached (Email) at the address mike@ai.mit.edu, or (US mail) as Mike Haertel c/o Free Software Foundation. */ +/* This file is no longer automatically generated from libc. */ + +#define _MALLOC_INTERNAL + +/* The malloc headers and source files from the C library follow here. */ + #ifndef _MALLOC_H #define _MALLOC_H 1 @@ -564,27 +563,27 @@ morecore (size) /* Allocate new space for the malloc info table. */ while (1) - { - newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); - - /* Did it fail? */ - if (newinfo == NULL) - { - (*__morecore) (-size); - return NULL; - } - - /* 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)) - < newsize) - break; - - /* Must try again. First give back most of what we just got. */ - (*__morecore) (- newsize * sizeof (malloc_info)); - newsize *= 2; - } + { + newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); + + /* Did it fail? */ + if (newinfo == NULL) + { + (*__morecore) (-size); + return NULL; + } + + /* 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)) + < newsize) + break; + + /* Must try again. First give back most of what we just got. */ + (*__morecore) (- newsize * sizeof (malloc_info)); + newsize *= 2; + } /* Copy the old table to the beginning of the new, and zero the rest of the new table. */ @@ -736,13 +735,13 @@ _malloc_internal (size) get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE, ADDRESS (block + lastblocks))) { - /* We got it contiguously. Which block we are extending + /* We got it contiguously. Which block we are extending (the `final free block' referred to above) might have changed, if it got combined with a freed info table. */ - block = _heapinfo[0].free.prev; - _heapinfo[block].free.size += (wantblocks - lastblocks); + block = _heapinfo[0].free.prev; + _heapinfo[block].free.size += (wantblocks - lastblocks); _bytes_free += (wantblocks - lastblocks) * BLOCKSIZE; - _heaplimit += wantblocks - lastblocks; + _heaplimit += wantblocks - lastblocks; continue; } result = morecore (wantblocks * BLOCKSIZE); @@ -988,12 +987,12 @@ _free_internal (ptr) It's possible that moving _heapinfo will allow us to return some space to the system. */ - __malloc_size_t info_block = BLOCK (_heapinfo); - __malloc_size_t info_blocks = _heapinfo[info_block].busy.info.size; - __malloc_size_t prev_block = _heapinfo[block].free.prev; - __malloc_size_t prev_blocks = _heapinfo[prev_block].free.size; - __malloc_size_t next_block = _heapinfo[block].free.next; - __malloc_size_t next_blocks = _heapinfo[next_block].free.size; + __malloc_size_t info_block = BLOCK (_heapinfo); + __malloc_size_t info_blocks = _heapinfo[info_block].busy.info.size; + __malloc_size_t prev_block = _heapinfo[block].free.prev; + __malloc_size_t prev_blocks = _heapinfo[prev_block].free.size; + __malloc_size_t next_block = _heapinfo[block].free.next; + __malloc_size_t next_blocks = _heapinfo[next_block].free.size; if (/* Win if this block being freed is last in core, the info table is just before it, the previous free block is just before the @@ -1042,7 +1041,7 @@ _free_internal (ptr) to the system. */ block = _heapinfo[0].free.prev; blocks = _heapinfo[block].free.size; - } + } /* Now see if we can return stuff to the system. */ if (block + blocks == _heaplimit && blocks >= lesscore_threshold) @@ -1668,7 +1667,7 @@ int check_block(block, cont) if (0==type) return 0; prev = ptr = (struct list *) ((char *) ADDRESS (block) + (_heapinfo[block].busy.info.frag.first << type)); - if ((BLOCKSIZE >> type) <= nfree) + if ((BLOCKSIZE >> type) <= nfree) return 1; if (nfree < 0) return 2; -- cgit v1.2.3