aboutsummaryrefslogtreecommitdiffstats
path: root/lib/malloc
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2004-07-27 13:29:18 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:56 +0000
commitb80f6443b6b7b620c7272664c66ecb0b120a0998 (patch)
tree9f71c98d8fe8fa0f41d95e1eb4227f32a09d43ca /lib/malloc
parent7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (diff)
downloadandroid_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.tar.gz
android_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.tar.bz2
android_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.zip
Imported from ../bash-3.0.tar.gz.
Diffstat (limited to 'lib/malloc')
-rw-r--r--lib/malloc/Makefile.in15
-rw-r--r--lib/malloc/getpagesize.h2
-rw-r--r--lib/malloc/imalloc.h8
-rw-r--r--lib/malloc/malloc.c28
-rw-r--r--lib/malloc/mstats.h2
-rw-r--r--lib/malloc/shmalloc.h3
-rw-r--r--lib/malloc/stats.c48
-rw-r--r--lib/malloc/stub.c2
-rw-r--r--lib/malloc/table.c8
-rw-r--r--lib/malloc/table.h2
-rw-r--r--lib/malloc/trace.c21
-rw-r--r--lib/malloc/watch.c14
-rw-r--r--lib/malloc/watch.h2
-rw-r--r--lib/malloc/xmalloc.c2
14 files changed, 109 insertions, 48 deletions
diff --git a/lib/malloc/Makefile.in b/lib/malloc/Makefile.in
index 91549c9..d013dc7 100644
--- a/lib/malloc/Makefile.in
+++ b/lib/malloc/Makefile.in
@@ -46,9 +46,16 @@ LDFLAGS = @LDFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
+LIBBUILD = ${BUILD_DIR}/lib
+
BASHINCDIR = ${topdir}/include
-INCLUDES = -I. -I../.. -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib
+INTL_LIBSRC = ${topdir}/lib/intl
+INTL_BUILDDIR = ${LIBBUILD}/intl
+INTL_INC = @INTL_INC@
+LIBINTL_H = @LIBINTL_H@
+
+INCLUDES = -I. -I../.. -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib $(INTL_INC)
CCFLAGS = ${PROFILE_FLAGS} ${INCLUDES} $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) \
$(CFLAGS) $(MALLOC_CFLAGS) $(CPPFLAGS)
@@ -116,6 +123,12 @@ trace.o: ${srcdir}/imalloc.h
table.o: ${srcdir}/imalloc.h ${srcdir}/table.h
watch.o: ${srcdir}/imalloc.h ${srcdir}/watch.h
+malloc.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
+stats.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
+trace.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
+table.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
+watch.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
+
# Rules for deficient makes, like SunOS and Solaris
stub.o: stub.c
malloc.o: malloc.c
diff --git a/lib/malloc/getpagesize.h b/lib/malloc/getpagesize.h
index 0bc5ef9..835f5da 100644
--- a/lib/malloc/getpagesize.h
+++ b/lib/malloc/getpagesize.h
@@ -1,5 +1,5 @@
/* Emulation of getpagesize() for systems that need it.
- Copyright (C) 1991 Free Software Foundation, Inc.
+ Copyright (C) 1991-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/lib/malloc/imalloc.h b/lib/malloc/imalloc.h
index 3920ce9..72ba65a 100644
--- a/lib/malloc/imalloc.h
+++ b/lib/malloc/imalloc.h
@@ -1,6 +1,6 @@
/* imalloc.h -- internal malloc definitions shared by source files. */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -159,4 +159,10 @@ do { \
memcpy ((dest), (src), (nbytes)) \
} while(0)
+#if defined (SHELL)
+# include "bashintl.h"
+#else
+# define _(x) x
+#endif
+
#endif /* _IMALLOC_H */
diff --git a/lib/malloc/malloc.c b/lib/malloc/malloc.c
index 0b4c847..60cbfab 100644
--- a/lib/malloc/malloc.c
+++ b/lib/malloc/malloc.c
@@ -1,6 +1,6 @@
/* malloc.c - dynamic memory allocation for bash. */
-/* Copyright (C) 1985, 1987, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1985-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -236,7 +236,7 @@ static unsigned long binsizes[NBUCKETS] = {
8192UL, 16384UL, 32768UL, 65536UL, 131072UL, 262144UL, 524288UL,
1048576UL, 2097152UL, 4194304UL, 8388608UL, 16777216UL, 33554432UL,
67108864UL, 134217728UL, 268435456UL, 536870912UL, 1073741824UL,
- 2147483648UL, 4294967296UL-1
+ 2147483648UL, 4294967295UL
};
/* binsizes[x] == (1 << ((x) + 3)) */
@@ -291,8 +291,11 @@ extern void mtrace_free __P((PTR_T, int, const char *, int));
#if !defined (botch)
static void
botch (s, file, line)
+ const char *s;
+ const char *file;
+ int line;
{
- fprintf (stderr, "malloc: failed assertion: %s\n", s);
+ fprintf (stderr, _("malloc: failed assertion: %s\n"), s);
(void)fflush (stderr);
abort ();
}
@@ -308,7 +311,7 @@ xbotch (mem, e, s, file, line)
const char *file;
int line;
{
- fprintf (stderr, "\r\nmalloc: %s:%d: assertion botched\r\n",
+ fprintf (stderr, _("\r\nmalloc: %s:%d: assertion botched\r\n"),
file ? file : "unknown", line);
#ifdef MALLOC_REGISTER
if (mem != NULL && malloc_register)
@@ -734,7 +737,7 @@ internal_malloc (n, file, line, flags) /* get a block */
/* If not for this check, we would gobble a clobbered free chain ptr
and bomb out on the NEXT allocate of this size block */
if (p->mh_alloc != ISFREE || p->mh_index != nunits)
- xbotch ((PTR_T)(p+1), 0, "malloc: block on free list clobbered", file, line);
+ xbotch ((PTR_T)(p+1), 0, _("malloc: block on free list clobbered"), file, line);
/* Fill in the info, and set up the magic numbers for range checking. */
p->mh_alloc = ISALLOC;
@@ -811,10 +814,10 @@ internal_free (mem, file, line, flags)
{
if (p->mh_alloc == ISFREE)
xbotch (mem, ERR_DUPFREE,
- "free: called with already freed block argument", file, line);
+ _("free: called with already freed block argument"), file, line);
else
xbotch (mem, ERR_UNALLOC,
- "free: called with unallocated block argument", file, line);
+ _("free: called with unallocated block argument"), file, line);
}
ASSERT (p->mh_magic2 == MAGIC2);
@@ -833,13 +836,13 @@ internal_free (mem, file, line, flags)
if (IN_BUCKET(nbytes, nunits) == 0)
xbotch (mem, ERR_UNDERFLOW,
- "free: underflow detected; mh_nbytes out of range", file, line);
+ _("free: underflow detected; mh_nbytes out of range"), file, line);
ap += p->mh_nbytes;
z = mg.s;
*z++ = *ap++, *z++ = *ap++, *z++ = *ap++, *z++ = *ap++;
if (mg.i != p->mh_nbytes)
- xbotch (mem, ERR_ASSERT_FAILED, "free: start and end chunk sizes differ", file, line);
+ xbotch (mem, ERR_ASSERT_FAILED, _("free: start and end chunk sizes differ"), file, line);
#if 1
if (nunits >= LESSCORE_MIN && ((char *)p + binsize(nunits) == memtop))
@@ -879,6 +882,7 @@ internal_free (mem, file, line, flags)
busy[nunits] = 0;
free_return:
+ ; /* Empty statement in case this is the end of the function */
#ifdef MALLOC_STATS
_mstats.nmalloc[nunits]--;
@@ -935,7 +939,7 @@ internal_realloc (mem, n, file, line, flags)
if (p->mh_alloc != ISALLOC)
xbotch (mem, ERR_UNALLOC,
- "realloc: called with unallocated block argument", file, line);
+ _("realloc: called with unallocated block argument"), file, line);
ASSERT (p->mh_magic2 == MAGIC2);
nbytes = ALLOCATED_BYTES(p->mh_nbytes);
@@ -950,13 +954,13 @@ internal_realloc (mem, n, file, line, flags)
original number of bytes requested. */
if (IN_BUCKET(nbytes, nunits) == 0)
xbotch (mem, ERR_UNDERFLOW,
- "realloc: underflow detected; mh_nbytes out of range", file, line);
+ _("realloc: underflow detected; mh_nbytes out of range"), file, line);
m = (char *)mem + (tocopy = p->mh_nbytes);
z = mg.s;
*z++ = *m++, *z++ = *m++, *z++ = *m++, *z++ = *m++;
if (mg.i != p->mh_nbytes)
- xbotch (mem, ERR_ASSERT_FAILED, "realloc: start and end chunk sizes differ", file, line);
+ xbotch (mem, ERR_ASSERT_FAILED, _("realloc: start and end chunk sizes differ"), file, line);
#ifdef MALLOC_WATCH
if (_malloc_nwatch > 0)
diff --git a/lib/malloc/mstats.h b/lib/malloc/mstats.h
index d237635..3153744 100644
--- a/lib/malloc/mstats.h
+++ b/lib/malloc/mstats.h
@@ -1,6 +1,6 @@
/* mstats.h - definitions for malloc statistics */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/lib/malloc/shmalloc.h b/lib/malloc/shmalloc.h
index 85cb5ce..812bb41 100644
--- a/lib/malloc/shmalloc.h
+++ b/lib/malloc/shmalloc.h
@@ -1,6 +1,6 @@
/* Functions (currently) for use by the shell to do malloc debugging and
tracking. */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -53,6 +53,7 @@ extern PTR_T sh_valloc __P((size_t, const char *, int));
/* trace.c */
extern int malloc_set_trace __P((int));
extern void malloc_set_tracefp (); /* full prototype requires stdio.h */
+extern void malloc_set_tracefn __P((char *, char *));
/* table.c */
extern void mregister_dump_table __P((void));
diff --git a/lib/malloc/stats.c b/lib/malloc/stats.c
index 52b23ae..18c3cef 100644
--- a/lib/malloc/stats.c
+++ b/lib/malloc/stats.c
@@ -1,6 +1,6 @@
/* stats.c - malloc statistics */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,6 +35,8 @@ extern int malloc_free_blocks __P((int));
extern struct _malstats _mstats;
+extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
+
struct bucket_stats
malloc_bucket_stats (size)
int size;
@@ -129,14 +131,37 @@ fprint_malloc_stats (s, fp)
_print_malloc_stats (s, fp);
}
-#define TRACEROOT "/var/tmp/maltrace/trace."
-static char mallbuf[1024];
+#define TRACEROOT "/var/tmp/maltrace/stats."
void
trace_malloc_stats (s, fn)
char *s, *fn;
{
+ FILE *fp;
char defname[sizeof (TRACEROOT) + 64];
+ static char mallbuf[1024];
+
+ fp = _imalloc_fopen (s, fn, TRACEROOT, defname, sizeof (defname));
+ if (fp)
+ {
+ setvbuf (fp, mallbuf, _IOFBF, sizeof (mallbuf));
+ _print_malloc_stats (s, fp);
+ fflush(fp);
+ fclose(fp);
+ }
+}
+
+#endif /* MALLOC_STATS */
+
+#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;
+{
char fname[1024];
long l;
FILE *fp;
@@ -144,8 +169,8 @@ trace_malloc_stats (s, fn)
l = (long)getpid ();
if (fn == 0)
{
- sprintf (defname, "%s%ld", TRACEROOT, l);
- fp = fopen(defname, "w");
+ sprintf (defbuf, "%s%ld", def, l);
+ fp = fopen(defbuf, "w");
}
else
{
@@ -171,14 +196,7 @@ trace_malloc_stats (s, fn)
*p = '\0';
fp = fopen (fname, "w");
}
-
- if (fp)
- {
- setvbuf (fp, mallbuf, _IOFBF, sizeof (mallbuf));
- _print_malloc_stats (s, fp);
- fflush(fp);
- fclose(fp);
- }
-}
-#endif /* MALLOC_STATS */
+ return fp;
+}
+#endif /* MALLOC_STATS || MALLOC_TRACE */
diff --git a/lib/malloc/stub.c b/lib/malloc/stub.c
index 94693d8..770e3f9 100644
--- a/lib/malloc/stub.c
+++ b/lib/malloc/stub.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993-2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
diff --git a/lib/malloc/table.c b/lib/malloc/table.c
index 051b573..ee37b3a 100644
--- a/lib/malloc/table.c
+++ b/lib/malloc/table.c
@@ -1,6 +1,6 @@
/* table.c - bookkeeping functions for allocated memory */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -172,14 +172,14 @@ mregister_alloc (tag, mem, size, file, line)
if (tentry == 0)
{
/* oops. table is full. punt. */
- fprintf (stderr, "register_alloc: alloc table is full with FIND_ALLOC?\n");
+ fprintf (stderr, _("register_alloc: alloc table is full with FIND_ALLOC?\n"));
return;
}
if (tentry->flags & MT_ALLOC)
{
/* oops. bad bookkeeping. ignore for now */
- fprintf (stderr, "register_alloc: %p already in table as allocated?\n", mem);
+ fprintf (stderr, _("register_alloc: %p already in table as allocated?\n"), mem);
}
tentry->mem = mem;
@@ -215,7 +215,7 @@ mregister_free (mem, size, file, line)
if (tentry->flags & MT_FREE)
{
/* oops. bad bookkeeping. ignore for now */
- fprintf (stderr, "register_free: %p already in table as free?\n", mem);
+ fprintf (stderr, _("register_free: %p already in table as free?\n"), mem);
}
tentry->flags = MT_FREE;
diff --git a/lib/malloc/table.h b/lib/malloc/table.h
index 9b2cddd..0d22376 100644
--- a/lib/malloc/table.h
+++ b/lib/malloc/table.h
@@ -1,6 +1,6 @@
/* table.h - definitions for tables for keeping track of allocated memory */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/lib/malloc/trace.c b/lib/malloc/trace.c
index ddd62f0..9dc34df 100644
--- a/lib/malloc/trace.c
+++ b/lib/malloc/trace.c
@@ -1,6 +1,6 @@
/* trace.c - tracing functions for malloc */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -29,6 +29,8 @@ extern int malloc_trace;
static int _mtrace_verbose = 0;
+extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
+
#ifdef MALLOC_TRACE
FILE *_mtrace_fp = NULL;
@@ -101,3 +103,20 @@ malloc_trace_bin (n)
_malloc_trace_buckets[n] = 1;
#endif
}
+
+#define TRACEROOT "/var/tmp/maltrace/trace."
+
+void
+malloc_set_tracefn (s, fn)
+ char *s;
+ char *fn;
+{
+#ifdef MALLOC_TRACE
+ FILE *fp;
+ char defname[sizeof (TRACEROOT) + 64];
+
+ fp = _imalloc_fopen (s, fn, TRACEROOT, defname, sizeof (defname));
+ if (fp)
+ malloc_set_tracefp (fp);
+#endif
+}
diff --git a/lib/malloc/watch.c b/lib/malloc/watch.c
index 6594a3f..11ab744 100644
--- a/lib/malloc/watch.c
+++ b/lib/malloc/watch.c
@@ -1,6 +1,6 @@
/* watch.c - watchpoint functions for malloc */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -43,17 +43,17 @@ watch_warn (addr, file, line, type, data)
char *tag;
if (type == W_ALLOC)
- tag = "allocated";
+ tag = _("allocated");
else if (type == W_FREE)
- tag = "freed";
+ tag = _("freed");
else if (type == W_REALLOC)
- tag = "requesting resize";
+ tag = _("requesting resize");
else if (type == W_RESIZED)
- tag = "just resized";
+ tag = _("just resized");
else
- tag = "bug: unknown operation";
+ tag = _("bug: unknown operation");
- fprintf (stderr, "malloc: watch alert: %p %s ", addr, tag);
+ fprintf (stderr, _("malloc: watch alert: %p %s "), addr, tag);
if (data != (unsigned long)-1)
fprintf (stderr, "(size %lu) ", data);
fprintf (stderr, "from '%s:%d'\n", file ? file : "unknown", line);
diff --git a/lib/malloc/watch.h b/lib/malloc/watch.h
index d66d80e..757bbd2 100644
--- a/lib/malloc/watch.h
+++ b/lib/malloc/watch.h
@@ -1,6 +1,6 @@
/* watch.h - definitions for tables for keeping track of allocated memory */
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/lib/malloc/xmalloc.c b/lib/malloc/xmalloc.c
index b037222..ab7c91a 100644
--- a/lib/malloc/xmalloc.c
+++ b/lib/malloc/xmalloc.c
@@ -1,6 +1,6 @@
/* xmalloc.c -- safe versions of malloc and realloc */
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2003 Free Software Foundation, Inc.
This file is part of GNU Readline, a library for reading lines
of text with interactive input and history editing.