aboutsummaryrefslogtreecommitdiffstats
path: root/src/gmalloc.c
diff options
context:
space:
mode:
authorEli Zaretskii2013-09-05 11:01:04 +0300
committerEli Zaretskii2013-09-05 11:01:04 +0300
commit41306318777a942420bc4feadbfacf662ea179dc (patch)
tree669e5cca02f95d6064ce73c0d3fbbf91b8c8b563 /src/gmalloc.c
parent141f1ff7a40cda10f0558e891dd196a943a5082e (diff)
parent257b3b03cb1cff917e0b3b7832ad3eab5b59f257 (diff)
downloademacs-41306318777a942420bc4feadbfacf662ea179dc.tar.gz
emacs-41306318777a942420bc4feadbfacf662ea179dc.zip
Merge from trunk after a lot of time.
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r--src/gmalloc.c71
1 files changed, 21 insertions, 50 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 0df050e127a..bc1d85ac5fb 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -1,6 +1,6 @@
1/* Declarations for `malloc' and friends. 1/* Declarations for `malloc' and friends.
2 Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004, 2 Copyright (C) 1990-1993, 1995-1996, 1999, 2002-2007, 2013 Free
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 Software Foundation, Inc.
4 Written May 1989 by Mike Haertel. 4 Written May 1989 by Mike Haertel.
5 5
6This library is free software; you can redistribute it and/or 6This library is free software; you can redistribute it and/or
@@ -14,16 +14,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details. 14General Public License for more details.
15 15
16You should have received a copy of the GNU General Public 16You should have received a copy of the GNU General Public
17License along with this library; see the file COPYING. If 17License along with this library. If not, see <http://www.gnu.org/licenses/>.
18not, write to the Free Software Foundation, Inc., 51 Franklin Street,
19Fifth Floor, Boston, MA 02110-1301, USA.
20 18
21 The author may be reached (Email) at the address mike@ai.mit.edu, 19 The author may be reached (Email) at the address mike@ai.mit.edu,
22 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 20 or (US mail) as Mike Haertel c/o Free Software Foundation. */
23 21
24#ifdef HAVE_CONFIG_H
25#include <config.h> 22#include <config.h>
26#endif
27 23
28#ifdef HAVE_PTHREAD 24#ifdef HAVE_PTHREAD
29#define USE_PTHREAD 25#define USE_PTHREAD
@@ -38,6 +34,10 @@ Fifth Floor, Boston, MA 02110-1301, USA.
38#include <pthread.h> 34#include <pthread.h>
39#endif 35#endif
40 36
37#ifdef WINDOWSNT
38#include <w32heap.h> /* for sbrk */
39#endif
40
41#ifdef __cplusplus 41#ifdef __cplusplus
42extern "C" 42extern "C"
43{ 43{
@@ -290,9 +290,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
290General Public License for more details. 290General Public License for more details.
291 291
292You should have received a copy of the GNU General Public 292You should have received a copy of the GNU General Public
293License along with this library; see the file COPYING. If 293License along with this library. If not, see <http://www.gnu.org/licenses/>.
294not, write to the Free Software Foundation, Inc., 51 Franklin Street,
295Fifth Floor, Boston, MA 02110-1301, USA.
296 294
297 The author may be reached (Email) at the address mike@ai.mit.edu, 295 The author may be reached (Email) at the address mike@ai.mit.edu,
298 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 296 or (US mail) as Mike Haertel c/o Free Software Foundation. */
@@ -462,7 +460,7 @@ get_contiguous_space (ptrdiff_t size, void *position)
462/* This is called when `_heapinfo' and `heapsize' have just 460/* This is called when `_heapinfo' and `heapsize' have just
463 been set to describe a new info table. Set up the table 461 been set to describe a new info table. Set up the table
464 to describe itself and account for it in the statistics. */ 462 to describe itself and account for it in the statistics. */
465static inline void 463static void
466register_heapinfo (void) 464register_heapinfo (void)
467{ 465{
468 size_t block, blocks; 466 size_t block, blocks;
@@ -970,9 +968,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
970General Public License for more details. 968General Public License for more details.
971 969
972You should have received a copy of the GNU General Public 970You should have received a copy of the GNU General Public
973License along with this library; see the file COPYING. If 971License along with this library. If not, see <http://www.gnu.org/licenses/>.
974not, write to the Free Software Foundation, Inc., 51 Franklin Street,
975Fifth Floor, Boston, MA 02110-1301, USA.
976 972
977 The author may be reached (Email) at the address mike@ai.mit.edu, 973 The author may be reached (Email) at the address mike@ai.mit.edu,
978 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 974 or (US mail) as Mike Haertel c/o Free Software Foundation. */
@@ -1284,14 +1280,14 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1284General Public License for more details. 1280General Public License for more details.
1285 1281
1286You should have received a copy of the GNU General Public 1282You should have received a copy of the GNU General Public
1287License along with this library; see the file COPYING. If 1283License along with this library. If not, see <http://www.gnu.org/licenses/>.
1288not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1289Fifth Floor, Boston, MA 02110-1301, USA.
1290 1284
1291 The author may be reached (Email) at the address mike@ai.mit.edu, 1285 The author may be reached (Email) at the address mike@ai.mit.edu,
1292 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1286 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1293 1287
1288#ifndef min
1294#define min(A, B) ((A) < (B) ? (A) : (B)) 1289#define min(A, B) ((A) < (B) ? (A) : (B))
1290#endif
1295 1291
1296/* On Cygwin the dumped emacs may try to realloc storage allocated in 1292/* On Cygwin the dumped emacs may try to realloc storage allocated in
1297 the static heap. We just malloc space in the new heap and copy the 1293 the static heap. We just malloc space in the new heap and copy the
@@ -1483,9 +1479,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1483General Public License for more details. 1479General Public License for more details.
1484 1480
1485You should have received a copy of the GNU General Public 1481You should have received a copy of the GNU General Public
1486License along with this library; see the file COPYING. If 1482License along with this library. If not, see <http://www.gnu.org/licenses/>.
1487not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1488Fifth Floor, Boston, MA 02110-1301, USA.
1489 1483
1490 The author may be reached (Email) at the address mike@ai.mit.edu, 1484 The author may be reached (Email) at the address mike@ai.mit.edu,
1491 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1485 or (US mail) as Mike Haertel c/o Free Software Foundation. */
@@ -1516,9 +1510,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1516GNU General Public License for more details. 1510GNU General Public License for more details.
1517 1511
1518You should have received a copy of the GNU General Public License 1512You should have received a copy of the GNU General Public License
1519along with the GNU C Library; see the file COPYING. If not, write to 1513along with the GNU C Library. If not, see <http://www.gnu.org/licenses/>. */
1520the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
1521MA 02110-1301, USA. */
1522 1514
1523/* uClibc defines __GNU_LIBRARY__, but it is not completely 1515/* uClibc defines __GNU_LIBRARY__, but it is not completely
1524 compatible. */ 1516 compatible. */
@@ -1562,9 +1554,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1562General Public License for more details. 1554General Public License for more details.
1563 1555
1564You should have received a copy of the GNU General Public 1556You should have received a copy of the GNU General Public
1565License along with this library; see the file COPYING. If 1557License along with this library. If not, see <http://www.gnu.org/licenses/>. */
1566not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1567Fifth Floor, Boston, MA 02110-1301, USA. */
1568 1558
1569void *(*__memalign_hook) (size_t size, size_t alignment); 1559void *(*__memalign_hook) (size_t size, size_t alignment);
1570 1560
@@ -1618,7 +1608,7 @@ memalign (size_t alignment, size_t size)
1618 break; 1608 break;
1619 if (l == NULL) 1609 if (l == NULL)
1620 { 1610 {
1621 l = malloc (sizeof (struct alignlist)); 1611 l = malloc (sizeof *l);
1622 if (l != NULL) 1612 if (l != NULL)
1623 { 1613 {
1624 l->next = _aligned_blocks; 1614 l->next = _aligned_blocks;
@@ -1641,14 +1631,6 @@ memalign (size_t alignment, size_t size)
1641 return result; 1631 return result;
1642} 1632}
1643 1633
1644#ifndef ENOMEM
1645#define ENOMEM 12
1646#endif
1647
1648#ifndef EINVAL
1649#define EINVAL 22
1650#endif
1651
1652int 1634int
1653posix_memalign (void **memptr, size_t alignment, size_t size) 1635posix_memalign (void **memptr, size_t alignment, size_t size)
1654{ 1636{
@@ -1682,18 +1664,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1682General Public License for more details. 1664General Public License for more details.
1683 1665
1684You should have received a copy of the GNU General Public 1666You should have received a copy of the GNU General Public
1685License along with this library; see the file COPYING. If 1667License along with this library. If not, see <http://www.gnu.org/licenses/>.
1686not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1687Fifth Floor, Boston, MA 02110-1301, USA.
1688 1668
1689 The author may be reached (Email) at the address mike@ai.mit.edu, 1669 The author may be reached (Email) at the address mike@ai.mit.edu,
1690 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1670 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1691 1671
1692/* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition
1693 on MSDOS, where it conflicts with a system header file. */
1694
1695#ifndef GMALLOC_INHIBIT_VALLOC
1696
1697/* Allocate SIZE bytes on a page boundary. */ 1672/* Allocate SIZE bytes on a page boundary. */
1698extern void *valloc (size_t); 1673extern void *valloc (size_t);
1699 1674
@@ -1714,8 +1689,6 @@ valloc (size_t size)
1714 return memalign (pagesize, size); 1689 return memalign (pagesize, size);
1715} 1690}
1716 1691
1717#endif /* Not ELIDE_VALLOC. */
1718
1719#ifdef GC_MCHECK 1692#ifdef GC_MCHECK
1720 1693
1721/* Standard debugging hooks for `malloc'. 1694/* Standard debugging hooks for `malloc'.
@@ -1733,9 +1706,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1733General Public License for more details. 1706General Public License for more details.
1734 1707
1735You should have received a copy of the GNU General Public 1708You should have received a copy of the GNU General Public
1736License along with this library; see the file COPYING. If 1709License along with this library. If not, see <http://www.gnu.org/licenses/>.
1737not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1738Fifth Floor, Boston, MA 02110-1301, USA.
1739 1710
1740 The author may be reached (Email) at the address mike@ai.mit.edu, 1711 The author may be reached (Email) at the address mike@ai.mit.edu,
1741 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1712 or (US mail) as Mike Haertel c/o Free Software Foundation. */
@@ -1813,7 +1784,7 @@ mallochook (size_t size)
1813 struct hdr *hdr; 1784 struct hdr *hdr;
1814 1785
1815 __malloc_hook = old_malloc_hook; 1786 __malloc_hook = old_malloc_hook;
1816 hdr = malloc (sizeof (struct hdr) + size + 1); 1787 hdr = malloc (sizeof *hdr + size + 1);
1817 __malloc_hook = mallochook; 1788 __malloc_hook = mallochook;
1818 if (hdr == NULL) 1789 if (hdr == NULL)
1819 return NULL; 1790 return NULL;
@@ -1844,7 +1815,7 @@ reallochook (void *ptr, size_t size)
1844 __free_hook = old_free_hook; 1815 __free_hook = old_free_hook;
1845 __malloc_hook = old_malloc_hook; 1816 __malloc_hook = old_malloc_hook;
1846 __realloc_hook = old_realloc_hook; 1817 __realloc_hook = old_realloc_hook;
1847 hdr = realloc (hdr, sizeof (struct hdr) + size + 1); 1818 hdr = realloc (hdr, sizeof *hdr + size + 1);
1848 __free_hook = freehook; 1819 __free_hook = freehook;
1849 __malloc_hook = mallochook; 1820 __malloc_hook = mallochook;
1850 __realloc_hook = reallochook; 1821 __realloc_hook = reallochook;