mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-29 00:19:51 +02:00
Bash-5.3-alpha release
This commit is contained in:
+3
-8
@@ -57,11 +57,7 @@ long i00afunc ();
|
||||
#define ADDRESS_FUNCTION(arg) &(arg)
|
||||
#endif /* CRAY && CRAY_STACKSEG_END */
|
||||
|
||||
#if __STDC__
|
||||
typedef void *pointer;
|
||||
#else
|
||||
typedef char *pointer;
|
||||
#endif
|
||||
|
||||
#define NULL 0
|
||||
|
||||
@@ -77,7 +73,7 @@ typedef char *pointer;
|
||||
|
||||
#ifndef emacs
|
||||
#define malloc xmalloc
|
||||
extern pointer xmalloc ();
|
||||
extern pointer xmalloc (size_t);
|
||||
#endif
|
||||
|
||||
/* Define STACK_DIRECTION if you know the direction of stack
|
||||
@@ -102,7 +98,7 @@ static int stack_dir; /* 1 or -1 once known. */
|
||||
#define STACK_DIR stack_dir
|
||||
|
||||
static void
|
||||
find_stack_direction ()
|
||||
find_stack_direction (void)
|
||||
{
|
||||
static char *addr = NULL; /* Address of first `dummy', once known. */
|
||||
auto char dummy; /* To get stack address. */
|
||||
@@ -156,8 +152,7 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
|
||||
implementations of C, for example under Gould's UTX/32. */
|
||||
|
||||
pointer
|
||||
alloca (size)
|
||||
size_t size;
|
||||
alloca (size_t size)
|
||||
{
|
||||
auto char probe; /* Probes stack depth: */
|
||||
register char *depth = ADDRESS_FUNCTION (probe);
|
||||
|
||||
+4
-16
@@ -1,6 +1,6 @@
|
||||
/* imalloc.h -- internal malloc definitions shared by source files. */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -39,11 +39,7 @@
|
||||
|
||||
/* Generic pointer type. */
|
||||
#ifndef PTR_T
|
||||
# if defined (__STDC__)
|
||||
# define PTR_T void *
|
||||
# else
|
||||
# define PTR_T char *
|
||||
# endif
|
||||
# define PTR_T void *
|
||||
#endif
|
||||
|
||||
#if !defined (NULL)
|
||||
@@ -72,14 +68,6 @@
|
||||
# endif /* HAVE_BCOPY */
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
#if !defined (PARAMS)
|
||||
# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) || defined (PROTOTYPES)
|
||||
# define PARAMS(protos) protos
|
||||
# else
|
||||
# define PARAMS(protos) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Use Duff's device for good zeroing/copying performance. DO NOT call the
|
||||
Duff's device macros with NBYTES == 0. */
|
||||
|
||||
@@ -172,7 +160,7 @@ do { \
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
extern void _malloc_block_signals PARAMS((sigset_t *, sigset_t *));
|
||||
extern void _malloc_unblock_signals PARAMS((sigset_t *, sigset_t *));
|
||||
extern void _malloc_block_signals (sigset_t *, sigset_t *);
|
||||
extern void _malloc_unblock_signals (sigset_t *, sigset_t *);
|
||||
|
||||
#endif /* _IMALLOC_H */
|
||||
|
||||
+63
-135
@@ -1,6 +1,6 @@
|
||||
/* malloc.c - dynamic memory allocation for bash. */
|
||||
|
||||
/* Copyright (C) 1985-2021 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1985-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -299,7 +299,7 @@ static const unsigned long binsizes[NBUCKETS] = {
|
||||
};
|
||||
|
||||
/* binsizes[x] == (1 << ((x) + 5)) */
|
||||
#define binsize(x) binsizes[(x)]
|
||||
#define binsize(x) binsizes[(size_t) (x)]
|
||||
|
||||
#define MAXALLOC_SIZE binsizes[NBUCKETS-1]
|
||||
|
||||
@@ -308,33 +308,33 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
/* Declarations for internal functions */
|
||||
static PTR_T internal_malloc PARAMS((size_t, const char *, int, int));
|
||||
static PTR_T internal_realloc PARAMS((PTR_T, size_t, const char *, int, int));
|
||||
static void internal_free PARAMS((PTR_T, const char *, int, int));
|
||||
static PTR_T internal_memalign PARAMS((size_t, size_t, const char *, int, int));
|
||||
static PTR_T internal_malloc (size_t, const char *, int, int);
|
||||
static PTR_T internal_realloc (PTR_T, size_t, const char *, int, int);
|
||||
static void internal_free (PTR_T, const char *, int, int);
|
||||
static PTR_T internal_memalign (size_t, size_t, const char *, int, int);
|
||||
#ifndef NO_CALLOC
|
||||
static PTR_T internal_calloc PARAMS((size_t, size_t, const char *, int, int));
|
||||
static void internal_cfree PARAMS((PTR_T, const char *, int, int));
|
||||
static PTR_T internal_calloc (size_t, size_t, const char *, int, int);
|
||||
static void internal_cfree (PTR_T, const char *, int, int);
|
||||
#endif
|
||||
#ifndef NO_VALLOC
|
||||
static PTR_T internal_valloc PARAMS((size_t, const char *, int, int));
|
||||
static PTR_T internal_valloc (size_t, const char *, int, int);
|
||||
#endif
|
||||
static PTR_T internal_remap PARAMS((PTR_T, size_t, int, int));
|
||||
static PTR_T internal_remap (PTR_T, size_t, int, int);
|
||||
|
||||
#if defined (botch)
|
||||
extern void botch ();
|
||||
extern void botch (const char *, ...);
|
||||
#else
|
||||
static void botch PARAMS((const char *, const char *, int));
|
||||
static void botch (const char *, const char *, int);
|
||||
#endif
|
||||
static void xbotch PARAMS((PTR_T, int, const char *, const char *, int));
|
||||
static void xbotch (PTR_T, int, const char *, const char *, int);
|
||||
|
||||
#if !HAVE_DECL_SBRK
|
||||
extern char *sbrk ();
|
||||
extern char *sbrk (int);
|
||||
#endif /* !HAVE_DECL_SBRK */
|
||||
|
||||
#ifdef SHELL
|
||||
extern int running_trap;
|
||||
extern int signal_is_trapped PARAMS((int));
|
||||
extern int signal_is_trapped (int);
|
||||
#endif
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
@@ -353,16 +353,13 @@ int malloc_mmap_threshold = MMAP_THRESHOLD;
|
||||
char _malloc_trace_buckets[NBUCKETS];
|
||||
|
||||
/* These should really go into a header file. */
|
||||
extern void mtrace_alloc PARAMS((const char *, PTR_T, size_t, const char *, int));
|
||||
extern void mtrace_free PARAMS((PTR_T, int, const char *, int));
|
||||
extern void mtrace_alloc (const char *, PTR_T, size_t, const char *, int);
|
||||
extern void mtrace_free (PTR_T, int, const char *, int);
|
||||
#endif
|
||||
|
||||
#if !defined (botch)
|
||||
static void
|
||||
botch (s, file, line)
|
||||
const char *s;
|
||||
const char *file;
|
||||
int line;
|
||||
botch (const char *s, const char *file, int line)
|
||||
{
|
||||
fprintf (stderr, _("malloc: failed assertion: %s\n"), s);
|
||||
(void)fflush (stderr);
|
||||
@@ -373,12 +370,7 @@ botch (s, file, line)
|
||||
/* print the file and line number that caused the assertion failure and
|
||||
call botch() to do whatever the application wants with the information */
|
||||
static void
|
||||
xbotch (mem, e, s, file, line)
|
||||
PTR_T mem;
|
||||
int e;
|
||||
const char *s;
|
||||
const char *file;
|
||||
int line;
|
||||
xbotch (PTR_T mem, int e, const char *s, const char *file, int line)
|
||||
{
|
||||
fprintf (stderr, _("\r\nmalloc: %s:%d: assertion botched\r\n"),
|
||||
file ? file : _("unknown"), line);
|
||||
@@ -395,8 +387,7 @@ xbotch (mem, e, s, file, line)
|
||||
assumed to not be busy; the caller (morecore()) checks for this.
|
||||
BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
bcoalesce (nu)
|
||||
register int nu;
|
||||
bcoalesce (int nu)
|
||||
{
|
||||
register union mhead *mp, *mp1, *mp2;
|
||||
register int nbuck;
|
||||
@@ -464,8 +455,7 @@ bcoalesce (nu)
|
||||
is assumed to be empty. Must be called with signals blocked (e.g.,
|
||||
by morecore()). BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
bsplit (nu)
|
||||
register int nu;
|
||||
bsplit (int nu)
|
||||
{
|
||||
register union mhead *mp;
|
||||
int nbuck, nblks, split_max;
|
||||
@@ -529,9 +519,7 @@ bsplit (nu)
|
||||
/* Take the memory block MP and add it to a chain < NU. NU is the right bucket,
|
||||
but is busy. This avoids memory orphaning. */
|
||||
static void
|
||||
xsplit (mp, nu)
|
||||
union mhead *mp;
|
||||
int nu;
|
||||
xsplit (union mhead *mp, int nu)
|
||||
{
|
||||
union mhead *nh;
|
||||
int nbuck, nblks, split_max;
|
||||
@@ -570,8 +558,7 @@ xsplit (mp, nu)
|
||||
}
|
||||
|
||||
void
|
||||
_malloc_block_signals (setp, osetp)
|
||||
sigset_t *setp, *osetp;
|
||||
_malloc_block_signals (sigset_t *setp, sigset_t *osetp)
|
||||
{
|
||||
#ifdef HAVE_POSIX_SIGNALS
|
||||
sigfillset (setp);
|
||||
@@ -585,8 +572,7 @@ _malloc_block_signals (setp, osetp)
|
||||
}
|
||||
|
||||
void
|
||||
_malloc_unblock_signals (setp, osetp)
|
||||
sigset_t *setp, *osetp;
|
||||
_malloc_unblock_signals (sigset_t *setp, sigset_t *osetp)
|
||||
{
|
||||
#ifdef HAVE_POSIX_SIGNALS
|
||||
sigprocmask (SIG_SETMASK, osetp, (sigset_t *)NULL);
|
||||
@@ -600,10 +586,9 @@ _malloc_unblock_signals (setp, osetp)
|
||||
#if defined (USE_LESSCORE)
|
||||
/* Return some memory to the system by reducing the break. This is only
|
||||
called with NU > pagebucket, so we're always assured of giving back
|
||||
more than one page of memory. */
|
||||
more than one page of memory. NU is the size index we're discarding */
|
||||
static void
|
||||
lesscore (nu) /* give system back some memory */
|
||||
register int nu; /* size index we're discarding */
|
||||
lesscore (int nu)
|
||||
{
|
||||
long siz;
|
||||
|
||||
@@ -622,8 +607,7 @@ lesscore (nu) /* give system back some memory */
|
||||
|
||||
/* Ask system for more memory; add to NEXTF[NU]. BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
morecore (nu)
|
||||
register int nu; /* size index to get more of */
|
||||
morecore (int nu)
|
||||
{
|
||||
register union mhead *mp;
|
||||
register int nblks;
|
||||
@@ -632,7 +616,7 @@ morecore (nu)
|
||||
sigset_t set, oset;
|
||||
int blocked_sigs;
|
||||
|
||||
/* Block all signals in case we are executed from a signal handler. */
|
||||
/* Block signals in case we are executed from a signal handler. */
|
||||
blocked_sigs = 0;
|
||||
#ifdef SHELL
|
||||
# if defined (SIGCHLD)
|
||||
@@ -752,13 +736,13 @@ morecore_done:
|
||||
}
|
||||
|
||||
static void
|
||||
malloc_debug_dummy ()
|
||||
malloc_debug_dummy (void)
|
||||
{
|
||||
write (1, "malloc_debug_dummy\n", 19);
|
||||
}
|
||||
|
||||
static int
|
||||
pagealign ()
|
||||
pagealign (void)
|
||||
{
|
||||
register int nunits;
|
||||
register union mhead *mp;
|
||||
@@ -823,12 +807,10 @@ pagealign ()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* allocate a block of memory */
|
||||
static PTR_T
|
||||
internal_malloc (n, file, line, flags) /* get a block */
|
||||
size_t n;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_malloc (size_t n, const char *file, int line, int flags)
|
||||
{
|
||||
register union mhead *p;
|
||||
register int nunits;
|
||||
@@ -947,10 +929,7 @@ internal_malloc (n, file, line, flags) /* get a block */
|
||||
}
|
||||
|
||||
static void
|
||||
internal_free (mem, file, line, flags)
|
||||
PTR_T mem;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_free (PTR_T mem, const char *file, int line, int flags)
|
||||
{
|
||||
register union mhead *p;
|
||||
register char *ap, *z;
|
||||
@@ -1018,10 +997,13 @@ internal_free (mem, file, line, flags)
|
||||
#if defined (USE_MMAP)
|
||||
if (nunits > malloc_mmap_threshold)
|
||||
{
|
||||
int o;
|
||||
o = errno;
|
||||
munmap (p, binsize (nunits));
|
||||
#if defined (MALLOC_STATS)
|
||||
_mstats.nlesscore[nunits]++;
|
||||
#endif
|
||||
errno = o; /* POSIX says free preserves errno */
|
||||
goto free_return;
|
||||
}
|
||||
#endif
|
||||
@@ -1036,7 +1018,10 @@ internal_free (mem, file, line, flags)
|
||||
there's already a block on the free list. */
|
||||
if ((nunits >= LESSCORE_FRC) || busy[nunits] || nextf[nunits] != 0)
|
||||
{
|
||||
int o;
|
||||
o = errno;
|
||||
lesscore (nunits);
|
||||
errno = o;
|
||||
/* keeps the tracing and registering code in one place */
|
||||
goto free_return;
|
||||
}
|
||||
@@ -1096,11 +1081,7 @@ free_return:
|
||||
new size, call mremap with the new size, and add the bookkeeping and guard
|
||||
information back in. */
|
||||
static PTR_T
|
||||
internal_remap (mem, n, nunits, flags)
|
||||
PTR_T mem;
|
||||
register size_t n;
|
||||
int nunits;
|
||||
int flags;
|
||||
internal_remap (PTR_T mem, register size_t n, int nunits, int flags)
|
||||
{
|
||||
register union mhead *p, *np;
|
||||
char *m, *z;
|
||||
@@ -1143,11 +1124,7 @@ internal_remap (mem, n, nunits, flags)
|
||||
#endif
|
||||
|
||||
static PTR_T
|
||||
internal_realloc (mem, n, file, line, flags)
|
||||
PTR_T mem;
|
||||
register size_t n;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_realloc (PTR_T mem, size_t n, const char *file, int line, int flags)
|
||||
{
|
||||
register union mhead *p;
|
||||
register MALLOC_SIZE_T tocopy;
|
||||
@@ -1294,11 +1271,7 @@ internal_realloc (mem, n, file, line, flags)
|
||||
}
|
||||
|
||||
static PTR_T
|
||||
internal_memalign (alignment, size, file, line, flags)
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_memalign (size_t alignment, size_t size, const char *file, int line, int flags)
|
||||
{
|
||||
register char *ptr;
|
||||
register char *aligned;
|
||||
@@ -1324,9 +1297,7 @@ internal_memalign (alignment, size, file, line, flags)
|
||||
}
|
||||
|
||||
int
|
||||
posix_memalign (memptr, alignment, size)
|
||||
void **memptr;
|
||||
size_t alignment, size;
|
||||
posix_memalign (void **memptr, size_t alignment, size_t size)
|
||||
{
|
||||
void *mem;
|
||||
|
||||
@@ -1346,8 +1317,7 @@ posix_memalign (memptr, alignment, size)
|
||||
}
|
||||
|
||||
size_t
|
||||
malloc_usable_size (mem)
|
||||
void *mem;
|
||||
malloc_usable_size (void *mem)
|
||||
{
|
||||
register union mhead *p;
|
||||
register char *ap;
|
||||
@@ -1376,10 +1346,7 @@ malloc_usable_size (mem)
|
||||
/* This runs into trouble with getpagesize on HPUX, and Multimax machines.
|
||||
Patching out seems cleaner than the ugly fix needed. */
|
||||
static PTR_T
|
||||
internal_valloc (size, file, line, flags)
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_valloc (size_t size, const char *file, int line, int flags)
|
||||
{
|
||||
return internal_memalign (getpagesize (), size, file, line, flags|MALLOC_INTERNAL);
|
||||
}
|
||||
@@ -1387,10 +1354,7 @@ internal_valloc (size, file, line, flags)
|
||||
|
||||
#ifndef NO_CALLOC
|
||||
static PTR_T
|
||||
internal_calloc (n, s, file, line, flags)
|
||||
size_t n, s;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_calloc (size_t n, size_t s, const char *file, int line, int flags)
|
||||
{
|
||||
size_t total;
|
||||
PTR_T result;
|
||||
@@ -1403,10 +1367,7 @@ internal_calloc (n, s, file, line, flags)
|
||||
}
|
||||
|
||||
static void
|
||||
internal_cfree (p, file, line, flags)
|
||||
PTR_T p;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
internal_cfree (PTR_T p, const char *file, int line, int flags)
|
||||
{
|
||||
internal_free (p, file, line, flags|MALLOC_INTERNAL);
|
||||
}
|
||||
@@ -1414,8 +1375,7 @@ internal_cfree (p, file, line, flags)
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
int
|
||||
malloc_free_blocks (size)
|
||||
int size;
|
||||
malloc_free_blocks (int size)
|
||||
{
|
||||
int nfree;
|
||||
register union mhead *p;
|
||||
@@ -1430,58 +1390,38 @@ malloc_free_blocks (size)
|
||||
|
||||
#if defined (MALLOC_WRAPFUNCS)
|
||||
PTR_T
|
||||
sh_malloc (bytes, file, line)
|
||||
size_t bytes;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_malloc (size_t bytes, const char *file, int line)
|
||||
{
|
||||
return internal_malloc (bytes, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
|
||||
PTR_T
|
||||
sh_realloc (ptr, size, file, line)
|
||||
PTR_T ptr;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_realloc (PTR_T ptr, size_t size, const char *file, int line)
|
||||
{
|
||||
return internal_realloc (ptr, size, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
|
||||
void
|
||||
sh_free (mem, file, line)
|
||||
PTR_T mem;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_free (PTR_T mem, const char *file, int line)
|
||||
{
|
||||
internal_free (mem, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
|
||||
PTR_T
|
||||
sh_memalign (alignment, size, file, line)
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_memalign (size_t alignment, size_t size, const char *file, int line)
|
||||
{
|
||||
return internal_memalign (alignment, size, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
|
||||
#ifndef NO_CALLOC
|
||||
PTR_T
|
||||
sh_calloc (n, s, file, line)
|
||||
size_t n, s;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_calloc (size_t n, size_t s, const char *file, int line)
|
||||
{
|
||||
return internal_calloc (n, s, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
|
||||
void
|
||||
sh_cfree (mem, file, line)
|
||||
PTR_T mem;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_cfree (PTR_T mem, const char *file, int line)
|
||||
{
|
||||
internal_cfree (mem, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
@@ -1489,10 +1429,7 @@ sh_cfree (mem, file, line)
|
||||
|
||||
#ifndef NO_VALLOC
|
||||
PTR_T
|
||||
sh_valloc (size, file, line)
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
sh_valloc (size_t size, const char *file, int line)
|
||||
{
|
||||
return internal_valloc (size, file, line, MALLOC_WRAPPER);
|
||||
}
|
||||
@@ -1503,39 +1440,32 @@ sh_valloc (size, file, line)
|
||||
/* Externally-available functions that call their internal counterparts. */
|
||||
|
||||
PTR_T
|
||||
malloc (size)
|
||||
size_t size;
|
||||
malloc (size_t size)
|
||||
{
|
||||
return internal_malloc (size, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
PTR_T
|
||||
realloc (mem, nbytes)
|
||||
PTR_T mem;
|
||||
size_t nbytes;
|
||||
realloc (PTR_T mem, size_t nbytes)
|
||||
{
|
||||
return internal_realloc (mem, nbytes, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
free (mem)
|
||||
PTR_T mem;
|
||||
free (PTR_T mem)
|
||||
{
|
||||
internal_free (mem, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
PTR_T
|
||||
memalign (alignment, size)
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
memalign (size_t alignment, size_t size)
|
||||
{
|
||||
return internal_memalign (alignment, size, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
#ifndef NO_VALLOC
|
||||
PTR_T
|
||||
valloc (size)
|
||||
size_t size;
|
||||
valloc (size_t size)
|
||||
{
|
||||
return internal_valloc (size, (char *)NULL, 0, 0);
|
||||
}
|
||||
@@ -1543,15 +1473,13 @@ valloc (size)
|
||||
|
||||
#ifndef NO_CALLOC
|
||||
PTR_T
|
||||
calloc (n, s)
|
||||
size_t n, s;
|
||||
calloc (size_t n, size_t s)
|
||||
{
|
||||
return internal_calloc (n, s, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
cfree (mem)
|
||||
PTR_T mem;
|
||||
cfree (PTR_T mem)
|
||||
{
|
||||
internal_cfree (mem, (char *)NULL, 0, 0);
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/* mstats.h - definitions for malloc statistics */
|
||||
|
||||
/* Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -104,10 +104,10 @@ struct bucket_stats {
|
||||
int nmmap; /* currently unused */
|
||||
};
|
||||
|
||||
extern struct bucket_stats malloc_bucket_stats PARAMS((int));
|
||||
extern struct _malstats malloc_stats PARAMS((void));
|
||||
extern void print_malloc_stats PARAMS((char *));
|
||||
extern void trace_malloc_stats PARAMS((char *, char *));
|
||||
extern struct bucket_stats malloc_bucket_stats (int);
|
||||
extern struct _malstats malloc_stats (void);
|
||||
extern void print_malloc_stats (char *);
|
||||
extern void trace_malloc_stats (char *, char *);
|
||||
|
||||
#endif /* MALLOC_STATS */
|
||||
|
||||
|
||||
+16
-30
@@ -1,6 +1,7 @@
|
||||
/* Functions (currently) for use by the shell to do malloc debugging and
|
||||
tracking. */
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -21,50 +22,35 @@
|
||||
#ifndef _SH_MALLOC_H
|
||||
#define _SH_MALLOC_H
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus)
|
||||
# define PARAMS(protos) protos
|
||||
# else
|
||||
# define PARAMS(protos) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Generic pointer type. */
|
||||
#ifndef PTR_T
|
||||
|
||||
#if defined (__STDC__)
|
||||
# define PTR_T void *
|
||||
#else
|
||||
# define PTR_T char *
|
||||
#endif
|
||||
|
||||
#endif /* PTR_T */
|
||||
|
||||
extern PTR_T sh_malloc (size_t, const char *, int);
|
||||
extern PTR_T sh_realloc (PTR_T, size_t, const char *, int);
|
||||
extern void sh_free (PTR_T, const char *, int);
|
||||
|
||||
extern PTR_T sh_malloc PARAMS((size_t, const char *, int));
|
||||
extern PTR_T sh_realloc PARAMS((PTR_T, size_t, const char *, int));
|
||||
extern void sh_free PARAMS((PTR_T, const char *, int));
|
||||
extern PTR_T sh_memalign (size_t, size_t, const char *, int);
|
||||
|
||||
extern PTR_T sh_memalign PARAMS((size_t, size_t, const char *, int));
|
||||
extern PTR_T sh_calloc (size_t, size_t, const char *, int);
|
||||
extern void sh_cfree (PTR_T, const char *, int);
|
||||
|
||||
extern PTR_T sh_calloc PARAMS((size_t, size_t, const char *, int));
|
||||
extern void sh_cfree PARAMS((PTR_T, const char *, int));
|
||||
|
||||
extern PTR_T sh_valloc PARAMS((size_t, const char *, int));
|
||||
extern PTR_T sh_valloc (size_t, const char *, int);
|
||||
|
||||
/* trace.c */
|
||||
extern int malloc_set_trace PARAMS((int));
|
||||
extern int malloc_set_trace (int);
|
||||
extern void malloc_set_tracefp (); /* full prototype requires stdio.h */
|
||||
extern void malloc_set_tracefn PARAMS((char *, char *));
|
||||
extern void malloc_set_tracefn (char *, char *);
|
||||
|
||||
/* table.c */
|
||||
extern void mregister_dump_table PARAMS((void));
|
||||
extern void mregister_table_init PARAMS((void));
|
||||
extern int malloc_set_register PARAMS((int));
|
||||
extern void mregister_dump_table (void);
|
||||
extern void mregister_table_init (void);
|
||||
extern int malloc_set_register (int);
|
||||
|
||||
/* stats.c */
|
||||
extern void print_malloc_stats PARAMS((char *));
|
||||
extern void print_malloc_stats (char *);
|
||||
extern void fprint_malloc_stats (); /* full prototype requires stdio.h */
|
||||
extern void trace_malloc_stats PARAMS((char *, char *));
|
||||
extern void trace_malloc_stats (char *, char *);
|
||||
|
||||
#endif
|
||||
|
||||
+10
-22
@@ -1,6 +1,6 @@
|
||||
/* stats.c - malloc statistics */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -34,17 +34,16 @@
|
||||
|
||||
#include "mstats.h"
|
||||
|
||||
extern int malloc_free_blocks PARAMS((int));
|
||||
extern int malloc_free_blocks (int);
|
||||
|
||||
extern int malloc_mmap_threshold;
|
||||
|
||||
extern struct _malstats _mstats;
|
||||
|
||||
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
|
||||
extern FILE *_imalloc_fopen (char *, char *, char *, char *, size_t);
|
||||
|
||||
struct bucket_stats
|
||||
malloc_bucket_stats (size)
|
||||
int size;
|
||||
malloc_bucket_stats (int size)
|
||||
{
|
||||
struct bucket_stats v;
|
||||
|
||||
@@ -75,7 +74,7 @@ malloc_bucket_stats (size)
|
||||
is the total number of bytes in use. These two fields are fairly
|
||||
expensive to compute, so we do it only when asked to. */
|
||||
struct _malstats
|
||||
malloc_stats ()
|
||||
malloc_stats (void)
|
||||
{
|
||||
struct _malstats result;
|
||||
struct bucket_stats v;
|
||||
@@ -93,9 +92,7 @@ malloc_stats ()
|
||||
}
|
||||
|
||||
static void
|
||||
_print_malloc_stats (s, fp)
|
||||
char *s;
|
||||
FILE *fp;
|
||||
_print_malloc_stats (char *s, FILE *fp)
|
||||
{
|
||||
register int i;
|
||||
unsigned long totused, totfree;
|
||||
@@ -128,16 +125,13 @@ _print_malloc_stats (s, fp)
|
||||
}
|
||||
|
||||
void
|
||||
print_malloc_stats (s)
|
||||
char *s;
|
||||
print_malloc_stats (char *s)
|
||||
{
|
||||
_print_malloc_stats (s, stderr);
|
||||
}
|
||||
|
||||
void
|
||||
fprint_malloc_stats (s, fp)
|
||||
char *s;
|
||||
FILE *fp;
|
||||
fprint_malloc_stats (char *s, FILE *fp)
|
||||
{
|
||||
_print_malloc_stats (s, fp);
|
||||
}
|
||||
@@ -145,8 +139,7 @@ fprint_malloc_stats (s, fp)
|
||||
#define TRACEROOT "/var/tmp/maltrace/stats."
|
||||
|
||||
void
|
||||
trace_malloc_stats (s, fn)
|
||||
char *s, *fn;
|
||||
trace_malloc_stats (char *s, char *fn)
|
||||
{
|
||||
FILE *fp;
|
||||
char defname[sizeof (TRACEROOT) + 64];
|
||||
@@ -166,12 +159,7 @@ trace_malloc_stats (s, fn)
|
||||
|
||||
#if defined (MALLOC_STATS) || defined (MALLOC_TRACE)
|
||||
FILE *
|
||||
_imalloc_fopen (s, fn, def, defbuf, defsiz)
|
||||
char *s;
|
||||
char *fn;
|
||||
char *def;
|
||||
char *defbuf;
|
||||
size_t defsiz;
|
||||
_imalloc_fopen (char *s, char *fn, char *def, char *defbuf, size_t defsiz)
|
||||
{
|
||||
char fname[1024];
|
||||
long l;
|
||||
|
||||
+21
-45
@@ -1,6 +1,6 @@
|
||||
/* table.c - bookkeeping functions for allocated memory */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
|
||||
#ifdef SHELL
|
||||
extern int running_trap;
|
||||
extern int signal_is_trapped PARAMS((int));
|
||||
extern int signal_is_trapped (int);
|
||||
#endif
|
||||
|
||||
extern int malloc_register;
|
||||
|
||||
#ifdef MALLOC_REGISTER
|
||||
|
||||
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
|
||||
extern FILE *_imalloc_fopen (char *, char *, char *, char *, size_t);
|
||||
|
||||
#define FIND_ALLOC 0x01 /* find slot for new allocation */
|
||||
#define FIND_EXIST 0x02 /* find slot for existing entry for free() or search */
|
||||
@@ -60,8 +60,7 @@ static ma_table_t mlocation_table[REG_TABLE_SIZE];
|
||||
* NOTE: taken from dmalloc (http://dmalloc.com) and modified.
|
||||
*/
|
||||
static unsigned int
|
||||
mt_hash (key)
|
||||
const PTR_T key;
|
||||
mt_hash (const PTR_T key)
|
||||
{
|
||||
unsigned int a, b, c;
|
||||
unsigned long x;
|
||||
@@ -78,8 +77,7 @@ mt_hash (key)
|
||||
|
||||
#if 0
|
||||
static unsigned int
|
||||
which_bucket (mem)
|
||||
PTR_T mem;
|
||||
which_bucket (PTR_T mem)
|
||||
{
|
||||
return (mt_hash ((unsigned char *)mem) & (REG_TABLE_SIZE-1));
|
||||
}
|
||||
@@ -95,9 +93,7 @@ which_bucket (mem)
|
||||
#endif
|
||||
|
||||
static mr_table_t *
|
||||
find_entry (mem, flags)
|
||||
PTR_T mem;
|
||||
int flags;
|
||||
find_entry (PTR_T mem, int flags)
|
||||
{
|
||||
unsigned int bucket;
|
||||
register mr_table_t *tp;
|
||||
@@ -135,16 +131,13 @@ find_entry (mem, flags)
|
||||
}
|
||||
|
||||
mr_table_t *
|
||||
mr_table_entry (mem)
|
||||
PTR_T mem;
|
||||
mr_table_entry (PTR_T mem)
|
||||
{
|
||||
return (find_entry (mem, FIND_EXIST));
|
||||
}
|
||||
|
||||
void
|
||||
mregister_describe_mem (mem, fp)
|
||||
PTR_T mem;
|
||||
FILE *fp;
|
||||
mregister_describe_mem (PTR_T mem, FILE *fp)
|
||||
{
|
||||
mr_table_t *entry;
|
||||
|
||||
@@ -160,12 +153,7 @@ mregister_describe_mem (mem, fp)
|
||||
}
|
||||
|
||||
void
|
||||
mregister_alloc (tag, mem, size, file, line)
|
||||
const char *tag;
|
||||
PTR_T mem;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
mregister_alloc (const char *tag, PTR_T mem, size_t size, const char *file, int line)
|
||||
{
|
||||
mr_table_t *tentry;
|
||||
sigset_t set, oset;
|
||||
@@ -216,11 +204,7 @@ mregister_alloc (tag, mem, size, file, line)
|
||||
}
|
||||
|
||||
void
|
||||
mregister_free (mem, size, file, line)
|
||||
PTR_T mem;
|
||||
int size;
|
||||
const char *file;
|
||||
int line;
|
||||
mregister_free (PTR_T mem, int size, const char *file, int line)
|
||||
{
|
||||
mr_table_t *tentry;
|
||||
sigset_t set, oset;
|
||||
@@ -268,8 +252,7 @@ mregister_free (mem, size, file, line)
|
||||
|
||||
/* If we ever add more flags, this will require changes. */
|
||||
static char *
|
||||
_entry_flags(x)
|
||||
int x;
|
||||
_entry_flags(int x)
|
||||
{
|
||||
if (x & MT_FREE)
|
||||
return "free";
|
||||
@@ -280,8 +263,7 @@ _entry_flags(x)
|
||||
}
|
||||
|
||||
static void
|
||||
_register_dump_table(fp)
|
||||
FILE *fp;
|
||||
_register_dump_table(FILE *fp)
|
||||
{
|
||||
register int i;
|
||||
mr_table_t entry;
|
||||
@@ -303,13 +285,13 @@ _register_dump_table(fp)
|
||||
}
|
||||
|
||||
void
|
||||
mregister_dump_table()
|
||||
mregister_dump_table(void)
|
||||
{
|
||||
_register_dump_table (stderr);
|
||||
}
|
||||
|
||||
void
|
||||
mregister_table_init ()
|
||||
mregister_table_init (void)
|
||||
{
|
||||
memset (mem_table, 0, sizeof(mr_table_t) * REG_TABLE_SIZE);
|
||||
memset (&mem_overflow, 0, sizeof (mr_table_t));
|
||||
@@ -319,9 +301,7 @@ mregister_table_init ()
|
||||
/* Simple for now */
|
||||
|
||||
static ma_table_t *
|
||||
find_location_entry (file, line)
|
||||
const char *file;
|
||||
int line;
|
||||
find_location_entry (const char *file, int line)
|
||||
{
|
||||
register ma_table_t *tp, *endp;
|
||||
|
||||
@@ -335,9 +315,7 @@ find_location_entry (file, line)
|
||||
}
|
||||
|
||||
void
|
||||
mlocation_register_alloc (file, line)
|
||||
const char *file;
|
||||
int line;
|
||||
mlocation_register_alloc (const char *file, int line)
|
||||
{
|
||||
ma_table_t *lentry;
|
||||
const char *nfile;
|
||||
@@ -372,8 +350,7 @@ mlocation_register_alloc (file, line)
|
||||
}
|
||||
|
||||
static void
|
||||
_location_dump_table (fp)
|
||||
FILE *fp;
|
||||
_location_dump_table (FILE *fp)
|
||||
{
|
||||
register ma_table_t *tp, *endp;
|
||||
|
||||
@@ -385,7 +362,7 @@ _location_dump_table (fp)
|
||||
}
|
||||
|
||||
void
|
||||
mlocation_dump_table ()
|
||||
mlocation_dump_table (void)
|
||||
{
|
||||
_location_dump_table (stderr);
|
||||
}
|
||||
@@ -393,7 +370,7 @@ mlocation_dump_table ()
|
||||
#define LOCROOT "/var/tmp/maltrace/locations."
|
||||
|
||||
void
|
||||
mlocation_write_table ()
|
||||
mlocation_write_table (void)
|
||||
{
|
||||
FILE *fp;
|
||||
char defname[sizeof (LOCROOT) + 64];
|
||||
@@ -406,7 +383,7 @@ mlocation_write_table ()
|
||||
}
|
||||
|
||||
void
|
||||
mlocation_table_init ()
|
||||
mlocation_table_init (void)
|
||||
{
|
||||
memset (mlocation_table, 0, sizeof (ma_table_t) * REG_TABLE_SIZE);
|
||||
mlocation_table[0].file = ""; /* reserve slot 0 for unknown locations */
|
||||
@@ -418,8 +395,7 @@ mlocation_table_init ()
|
||||
#endif /* MALLOC_REGISTER */
|
||||
|
||||
int
|
||||
malloc_set_register(n)
|
||||
int n;
|
||||
malloc_set_register (int n)
|
||||
{
|
||||
int old;
|
||||
|
||||
|
||||
+11
-11
@@ -1,6 +1,6 @@
|
||||
/* table.h - definitions for tables for keeping track of allocated memory */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -57,12 +57,12 @@ typedef struct mr_table {
|
||||
|
||||
#define REG_TABLE_SIZE 8192
|
||||
|
||||
extern mr_table_t *mr_table_entry PARAMS((PTR_T));
|
||||
extern void mregister_alloc PARAMS((const char *, PTR_T, size_t, const char *, int));
|
||||
extern void mregister_free PARAMS((PTR_T, int, const char *, int));
|
||||
extern void mregister_describe_mem ();
|
||||
extern void mregister_dump_table PARAMS((void));
|
||||
extern void mregister_table_init PARAMS((void));
|
||||
extern mr_table_t *mr_table_entry (PTR_T);
|
||||
extern void mregister_alloc (const char *, PTR_T, size_t, const char *, int);
|
||||
extern void mregister_free (PTR_T, int, const char *, int);
|
||||
extern void mregister_describe_mem (PTR_T, FILE *); /* needs stdio.h */
|
||||
extern void mregister_dump_table (void);
|
||||
extern void mregister_table_init (void);
|
||||
|
||||
typedef struct ma_table {
|
||||
const char *file;
|
||||
@@ -70,10 +70,10 @@ typedef struct ma_table {
|
||||
int nalloc;
|
||||
} ma_table_t;
|
||||
|
||||
extern void mlocation_register_alloc PARAMS((const char *, int));
|
||||
extern void mlocation_table_init PARAMS((void));
|
||||
extern void mlocation_dump_table PARAMS((void));
|
||||
extern void mlocation_write_table PARAMS((void));
|
||||
extern void mlocation_register_alloc (const char *, int);
|
||||
extern void mlocation_table_init (void);
|
||||
extern void mlocation_dump_table (void);
|
||||
extern void mlocation_write_table (void);
|
||||
|
||||
/* NOTE: HASH_MIX taken from dmalloc (http://dmalloc.com) */
|
||||
|
||||
|
||||
+8
-22
@@ -1,6 +1,6 @@
|
||||
/* trace.c - tracing functions for malloc */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -35,18 +35,13 @@ static int _mtrace_verbose = 0;
|
||||
|
||||
#ifdef MALLOC_TRACE
|
||||
|
||||
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
|
||||
extern FILE *_imalloc_fopen (char *, char *, char *, char *, size_t);
|
||||
|
||||
FILE *_mtrace_fp = NULL;
|
||||
extern char _malloc_trace_buckets[];
|
||||
|
||||
void
|
||||
mtrace_alloc (tag, mem, size, file, line)
|
||||
const char *tag;
|
||||
PTR_T mem;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
mtrace_alloc (const char *tag, PTR_T mem, size_t size, const char *file, int line)
|
||||
{
|
||||
if (_mtrace_fp == NULL)
|
||||
_mtrace_fp = stderr;
|
||||
@@ -60,11 +55,7 @@ mtrace_alloc (tag, mem, size, file, line)
|
||||
}
|
||||
|
||||
void
|
||||
mtrace_free (mem, size, file, line)
|
||||
PTR_T mem;
|
||||
int size;
|
||||
const char *file;
|
||||
int line;
|
||||
mtrace_free (PTR_T mem, int size, const char *file, int line)
|
||||
{
|
||||
if (_mtrace_fp == NULL)
|
||||
_mtrace_fp = stderr;
|
||||
@@ -79,8 +70,7 @@ mtrace_free (mem, size, file, line)
|
||||
#endif /* MALLOC_TRACE */
|
||||
|
||||
int
|
||||
malloc_set_trace (n)
|
||||
int n;
|
||||
malloc_set_trace (int n)
|
||||
{
|
||||
int old;
|
||||
|
||||
@@ -91,8 +81,7 @@ malloc_set_trace (n)
|
||||
}
|
||||
|
||||
void
|
||||
malloc_set_tracefp (fp)
|
||||
FILE *fp;
|
||||
malloc_set_tracefp (FILE *fp)
|
||||
{
|
||||
#ifdef MALLOC_TRACE
|
||||
_mtrace_fp = fp ? fp : stderr;
|
||||
@@ -100,8 +89,7 @@ malloc_set_tracefp (fp)
|
||||
}
|
||||
|
||||
void
|
||||
malloc_trace_bin (n)
|
||||
int n;
|
||||
malloc_trace_bin (int n)
|
||||
{
|
||||
#ifdef MALLOC_TRACE
|
||||
_malloc_trace_buckets[n] = 1;
|
||||
@@ -111,9 +99,7 @@ malloc_trace_bin (n)
|
||||
#define TRACEROOT "/var/tmp/maltrace/trace."
|
||||
|
||||
void
|
||||
malloc_set_tracefn (s, fn)
|
||||
char *s;
|
||||
char *fn;
|
||||
malloc_set_tracefn (char *s, char *fn)
|
||||
{
|
||||
#ifdef MALLOC_TRACE
|
||||
FILE *fp;
|
||||
|
||||
+5
-15
@@ -1,6 +1,6 @@
|
||||
/* watch.c - watchpoint functions for malloc */
|
||||
|
||||
/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2003, 2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -35,11 +35,7 @@ int _malloc_nwatch;
|
||||
static PTR_T _malloc_watch_list[WATCH_MAX];
|
||||
|
||||
static void
|
||||
watch_warn (addr, file, line, type, data)
|
||||
PTR_T addr;
|
||||
const char *file;
|
||||
int line, type;
|
||||
unsigned long data;
|
||||
watch_warn (PTR_T addr, const char *file, int line, int type, unsigned long data)
|
||||
{
|
||||
char *tag;
|
||||
|
||||
@@ -61,11 +57,7 @@ watch_warn (addr, file, line, type, data)
|
||||
}
|
||||
|
||||
void
|
||||
_malloc_ckwatch (addr, file, line, type, data)
|
||||
PTR_T addr;
|
||||
const char *file;
|
||||
int line, type;
|
||||
unsigned long data;
|
||||
_malloc_ckwatch (PTR_T addr, const char *file, int line, int type, unsigned long data)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -81,8 +73,7 @@ _malloc_ckwatch (addr, file, line, type, data)
|
||||
#endif /* MALLOC_WATCH */
|
||||
|
||||
PTR_T
|
||||
malloc_watch (addr)
|
||||
PTR_T addr;
|
||||
malloc_watch (PTR_T addr)
|
||||
{
|
||||
register int i;
|
||||
PTR_T ret;
|
||||
@@ -117,8 +108,7 @@ malloc_watch (addr)
|
||||
watchpoints. Returns ADDR if everything went OK, NULL if ADDR was
|
||||
not being watched. */
|
||||
PTR_T
|
||||
malloc_unwatch (addr)
|
||||
PTR_T addr;
|
||||
malloc_unwatch (PTR_T addr)
|
||||
{
|
||||
#ifdef MALLOC_WATCH
|
||||
register int i;
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/* watch.h - definitions for tables for keeping track of allocated memory */
|
||||
|
||||
/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne-Again SHell.
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
extern int _malloc_nwatch;
|
||||
|
||||
extern void _malloc_ckwatch PARAMS((PTR_T, const char *, int, int, unsigned long));
|
||||
|
||||
extern void _malloc_ckwatch (PTR_T, const char *, int, int, unsigned long);
|
||||
|
||||
#endif /* MALLOC_WATCH */
|
||||
|
||||
#endif /* _MWATCH_H */
|
||||
|
||||
+5
-16
@@ -1,6 +1,6 @@
|
||||
/* xmalloc.c -- safe versions of malloc and realloc */
|
||||
|
||||
/* Copyright (C) 1991-2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2003, 2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Readline, a library for reading lines
|
||||
of text with interactive input and history editing.
|
||||
@@ -33,13 +33,7 @@
|
||||
|
||||
/* Generic pointer type. */
|
||||
#ifndef PTR_T
|
||||
|
||||
#if defined (__STDC__)
|
||||
# define PTR_T void *
|
||||
#else
|
||||
# define PTR_T char *
|
||||
#endif
|
||||
|
||||
#endif /* PTR_T */
|
||||
|
||||
/* **************************************************************** */
|
||||
@@ -49,8 +43,7 @@
|
||||
/* **************************************************************** */
|
||||
|
||||
static void
|
||||
memory_error_and_abort (fname)
|
||||
char *fname;
|
||||
memory_error_and_abort (char *fname)
|
||||
{
|
||||
fprintf (stderr, "%s: out of virtual memory\n", fname);
|
||||
exit (2);
|
||||
@@ -60,8 +53,7 @@ memory_error_and_abort (fname)
|
||||
to hold BYTES number of bytes. If the memory cannot be allocated,
|
||||
print an error message and abort. */
|
||||
PTR_T
|
||||
xmalloc (bytes)
|
||||
size_t bytes;
|
||||
xmalloc (size_t bytes)
|
||||
{
|
||||
PTR_T temp;
|
||||
|
||||
@@ -72,9 +64,7 @@ xmalloc (bytes)
|
||||
}
|
||||
|
||||
PTR_T
|
||||
xrealloc (pointer, bytes)
|
||||
PTR_T pointer;
|
||||
size_t bytes;
|
||||
xrealloc (PTR_T pointer, size_t bytes)
|
||||
{
|
||||
PTR_T temp;
|
||||
|
||||
@@ -86,8 +76,7 @@ xrealloc (pointer, bytes)
|
||||
}
|
||||
|
||||
void
|
||||
xfree (string)
|
||||
PTR_T string;
|
||||
xfree (PTR_T string)
|
||||
{
|
||||
if (string)
|
||||
free (string);
|
||||
|
||||
Reference in New Issue
Block a user