1 diff -urN glibc-2.2.4.org/malloc/Makefile glibc-2.2.4/malloc/Makefile
2 --- glibc-2.2.4.org/malloc/Makefile Mon Jul 23 19:54:38 2001
3 +++ glibc-2.2.4/malloc/Makefile Fri Sep 28 20:50:18 2001
6 # The Perl script to analyze the output of the mtrace functions.
9 +install-bin-script = mtrace
12 # The Perl script will print addresses and to do this nicely we must know
14 ifneq ($(cross-compiling),yes)
15 # If the gd library is available we build the `memusagestat' program.
17 -install-bin += memusagestat memusage
18 +install-bin = memusagestat memusage
19 generated += memusagestat memusage
20 extra-objs += memusagestat.o
22 diff -urN glibc-2.2.4.org/malloc/malloc.c glibc-2.2.4/malloc/malloc.c
23 --- glibc-2.2.4.org/malloc/malloc.c Sun Aug 12 03:28:49 2001
24 +++ glibc-2.2.4/malloc/malloc.c Fri Sep 28 20:50:18 2001
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
32 This work is mainly derived from malloc-2.6.4 by Doug Lea
33 <dl@cs.oswego.edu>, which is available from:
34 @@ -1766,49 +1766,49 @@
35 secure = __libc_enable_secure;
39 - char **runp = _environ;
41 + if (_environ != NULL)
43 + char **runp = _environ;
46 - while (__builtin_expect ((envline = next_env_entry (&runp)) != NULL,
49 - size_t len = strcspn (envline, "=");
50 + while (__builtin_expect ((envline = next_env_entry (&runp)) != NULL, 0))
52 + size_t len = strcspn (envline, "=");
54 - if (envline[len] != '=')
55 - /* This is a "MALLOC_" variable at the end of the string
56 - without a '=' character. Ignore it since otherwise we
57 - will access invalid memory below. */
63 - if (memcmp (envline, "CHECK_", 6) == 0)
67 - if (! secure && memcmp (envline, "TOP_PAD_", 8) == 0)
68 - mALLOPt(M_TOP_PAD, atoi(&envline[9]));
71 - if (! secure && memcmp (envline, "MMAP_MAX_", 9) == 0)
72 - mALLOPt(M_MMAP_MAX, atoi(&envline[10]));
77 - if (memcmp (envline, "TRIM_THRESHOLD_", 15) == 0)
78 - mALLOPt(M_TRIM_THRESHOLD, atoi(&envline[16]));
79 - else if (memcmp (envline, "MMAP_THRESHOLD_", 15) == 0)
80 - mALLOPt(M_MMAP_THRESHOLD, atoi(&envline[16]));
88 + if (envline[len] != '=')
89 + /* This is a "MALLOC_" variable at the end of the string
90 + without a '=' character. Ignore it since otherwise we
91 + will access invalid memory below. */
97 + if (memcmp (envline, "CHECK_", 6) == 0)
101 + if (! secure && memcmp (envline, "TOP_PAD_", 8) == 0)
102 + mALLOPt(M_TOP_PAD, atoi(&envline[9]));
105 + if (! secure && memcmp (envline, "MMAP_MAX_", 9) == 0)
106 + mALLOPt(M_MMAP_MAX, atoi(&envline[10]));
111 + if (memcmp (envline, "TRIM_THRESHOLD_", 15) == 0)
112 + mALLOPt(M_TRIM_THRESHOLD, atoi(&envline[16]));
113 + else if (memcmp (envline, "MMAP_THRESHOLD_", 15) == 0)
114 + mALLOPt(M_MMAP_THRESHOLD, atoi(&envline[16]));
125 @@ -2788,13 +2788,15 @@
128 #if defined _LIBC || defined MALLOC_HOOKS
129 - if (__malloc_hook != NULL) {
130 + __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
132 + if (hook != NULL) {
135 #if defined __GNUC__ && __GNUC__ >= 2
136 - result = (*__malloc_hook)(bytes, RETURN_ADDRESS (0));
137 + result = (*hook)(bytes, RETURN_ADDRESS (0));
139 - result = (*__malloc_hook)(bytes, NULL);
140 + result = (*hook)(bytes, NULL);
144 @@ -3111,11 +3113,14 @@
145 mchunkptr p; /* chunk corresponding to mem */
147 #if defined _LIBC || defined MALLOC_HOOKS
148 - if (__free_hook != NULL) {
149 + void (*hook) __MALLOC_PMT ((__malloc_ptr_t, __const __malloc_ptr_t)) =
152 + if (hook != NULL) {
153 #if defined __GNUC__ && __GNUC__ >= 2
154 - (*__free_hook)(mem, RETURN_ADDRESS (0));
155 + (*hook)(mem, RETURN_ADDRESS (0));
157 - (*__free_hook)(mem, NULL);
158 + (*hook)(mem, NULL);
162 @@ -3314,13 +3319,16 @@
163 mchunkptr newp; /* chunk to return */
165 #if defined _LIBC || defined MALLOC_HOOKS
166 - if (__realloc_hook != NULL) {
167 + __malloc_ptr_t (*hook) __MALLOC_PMT ((__malloc_ptr_t, size_t,
168 + __const __malloc_ptr_t)) =
170 + if (hook != NULL) {
173 #if defined __GNUC__ && __GNUC__ >= 2
174 - result = (*__realloc_hook)(oldmem, bytes, RETURN_ADDRESS (0));
175 + result = (*hook)(oldmem, bytes, RETURN_ADDRESS (0));
177 - result = (*__realloc_hook)(oldmem, bytes, NULL);
178 + result = (*hook)(oldmem, bytes, NULL);
182 @@ -3596,13 +3604,16 @@
185 #if defined _LIBC || defined MALLOC_HOOKS
186 - if (__memalign_hook != NULL) {
187 + __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
188 + __const __malloc_ptr_t)) =
190 + if (hook != NULL) {
193 #if defined __GNUC__ && __GNUC__ >= 2
194 - result = (*__memalign_hook)(alignment, bytes, RETURN_ADDRESS (0));
195 + result = (*hook)(alignment, bytes, RETURN_ADDRESS (0));
197 - result = (*__memalign_hook)(alignment, bytes, NULL);
198 + result = (*hook)(alignment, bytes, NULL);
202 @@ -3788,12 +3799,14 @@
205 #if defined _LIBC || defined MALLOC_HOOKS
206 - if (__malloc_hook != NULL) {
207 + __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
209 + if (hook != NULL) {
211 #if defined __GNUC__ && __GNUC__ >= 2
212 - mem = (*__malloc_hook)(sz, RETURN_ADDRESS (0));
213 + mem = (*hook)(sz, RETURN_ADDRESS (0));
215 - mem = (*__malloc_hook)(sz, NULL);
216 + mem = (*hook)(sz, NULL);
220 diff -urN glibc-2.2.4.org/malloc/memusage.c glibc-2.2.4/malloc/memusage.c
221 --- glibc-2.2.4.org/malloc/memusage.c Tue Aug 14 00:00:51 2001
222 +++ glibc-2.2.4/malloc/memusage.c Fri Sep 28 20:50:18 2001
224 const char *env = getenv ("MEMUSAGE_PROG_NAME");
225 size_t prog_len = strlen (__progname);
228 + mallocp = (void *(*) (size_t)) dlsym (RTLD_NEXT, "malloc");
229 + reallocp = (void *(*) (void *, size_t)) dlsym (RTLD_NEXT, "realloc");
230 + callocp = (void *(*) (size_t, size_t)) dlsym (RTLD_NEXT, "calloc");
231 + freep = (void (*) (void *)) dlsym (RTLD_NEXT, "free");
236 /* Check for program name. */
242 - mallocp = (void *(*) (size_t)) dlsym (RTLD_NEXT, "malloc");
243 - reallocp = (void *(*) (void *, size_t)) dlsym (RTLD_NEXT, "realloc");
244 - callocp = (void *(*) (size_t, size_t)) dlsym (RTLD_NEXT, "calloc");
245 - freep = (void (*) (void *)) dlsym (RTLD_NEXT, "free");
248 outname = getenv ("MEMUSAGE_OUTPUT");
249 if (outname != NULL && outname[0] != '\0'
250 && (access (outname, R_OK | W_OK) == 0 || errno == ENOENT))
251 @@ -357,10 +357,13 @@
253 /* Keep track of number of calls. */
254 ++calls[idx_realloc];
255 - /* Keep track of total memory consumption for `realloc'. */
256 - total[idx_realloc] += len;
257 - /* Keep track of total memory requirement. */
258 - grand_total += len;
261 + /* Keep track of total memory consumption for `realloc'. */
262 + total[idx_realloc] += len - old_len;
263 + /* Keep track of total memory requirement. */
264 + grand_total += len - old_len;
266 /* Remember the size of the request. */
268 ++histogram[len / 16];
269 diff -urN glibc-2.2.4.org/malloc/memusage.sh glibc-2.2.4/malloc/memusage.sh
270 --- glibc-2.2.4.org/malloc/memusage.sh Mon Jul 23 19:54:39 2001
271 +++ glibc-2.2.4/malloc/memusage.sh Fri Sep 28 20:50:18 2001
273 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
277 +if test -n "$progname"; then
278 + add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
282 if test -n "$buffer"; then
283 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
284 diff -urN glibc-2.2.4.org/malloc/mtrace.c glibc-2.2.4/malloc/mtrace.c
285 --- glibc-2.2.4.org/malloc/mtrace.c Mon Jul 23 19:54:39 2001
286 +++ glibc-2.2.4/malloc/mtrace.c Fri Sep 28 20:50:18 2001
288 if (_dl_addr (caller, &info))
290 char *buf = (char *) "";
291 - if (info.dli_sname && info.dli_sname[0])
292 + if (info.dli_sname != NULL)
294 size_t len = strlen (info.dli_sname);
295 buf = alloca (len + 6 + 2 * sizeof (void *));
296 diff -urN glibc-2.2.4.org/malloc/obstack.c glibc-2.2.4/malloc/obstack.c
297 --- glibc-2.2.4.org/malloc/obstack.c Mon Jul 23 19:54:39 2001
298 +++ glibc-2.2.4/malloc/obstack.c Fri Sep 28 20:50:18 2001
304 +# include <config.h>
309 files, it is simpler to just do this in the source for each such file. */
311 #include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
312 -#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
313 -#include <gnu-versions.h>
314 -#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
317 +#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
318 +# include <gnu-versions.h>
319 +# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
324 +#if defined _LIBC && defined USE_IN_LIBIO
331 -#if defined (__STDC__) && __STDC__
332 -#define POINTER void *
334 -#define POINTER char *
336 +# if defined __STDC__ && __STDC__
337 +# define POINTER void *
339 +# define POINTER char *
342 /* Determine default alignment. */
343 struct fooalign {char x; double d;};
344 -#define DEFAULT_ALIGNMENT \
345 +# define DEFAULT_ALIGNMENT \
346 ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
347 /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
348 But in fact it might be less smart and round addresses to as much as
349 DEFAULT_ROUNDING. So we prepare for it to do that. */
350 union fooround {long x; double d;};
351 -#define DEFAULT_ROUNDING (sizeof (union fooround))
352 +# define DEFAULT_ROUNDING (sizeof (union fooround))
354 /* When we copy a long block of data, this is the unit to do it with.
355 On some machines, copying successive ints does not work;
356 in such a case, redefine COPYING_UNIT to `long' (if that works)
357 or `char' as a last resort. */
358 -#ifndef COPYING_UNIT
359 -#define COPYING_UNIT int
361 +# ifndef COPYING_UNIT
362 +# define COPYING_UNIT int
366 /* The functions allocating more room by calling `obstack_chunk_alloc'
368 abort gracefully or use longjump - but shouldn't return. This
369 variable by default points to the internal function
370 `print_and_abort'. */
371 -#if defined (__STDC__) && __STDC__
372 +# if defined __STDC__ && __STDC__
373 static void print_and_abort (void);
374 void (*obstack_alloc_failed_handler) (void) = print_and_abort;
377 static void print_and_abort ();
378 void (*obstack_alloc_failed_handler) () = print_and_abort;
382 /* Exit value used when `print_and_abort' is used. */
383 -#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
386 -#ifndef EXIT_FAILURE
387 -#define EXIT_FAILURE 1
389 +# if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
390 +# include <stdlib.h>
392 +# ifndef EXIT_FAILURE
393 +# define EXIT_FAILURE 1
395 int obstack_exit_failure = EXIT_FAILURE;
397 /* The non-GNU-C macros copy the obstack into this global variable
398 @@ -109,33 +112,33 @@
399 For free, do not use ?:, since some compilers, like the MIPS compilers,
400 do not allow (expr) ? void : void. */
402 -#if defined (__STDC__) && __STDC__
403 -#define CALL_CHUNKFUN(h, size) \
404 +# if defined __STDC__ && __STDC__
405 +# define CALL_CHUNKFUN(h, size) \
406 (((h) -> use_extra_arg) \
407 ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
408 : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
410 -#define CALL_FREEFUN(h, old_chunk) \
411 +# define CALL_FREEFUN(h, old_chunk) \
413 if ((h) -> use_extra_arg) \
414 (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
416 (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
419 -#define CALL_CHUNKFUN(h, size) \
421 +# define CALL_CHUNKFUN(h, size) \
422 (((h) -> use_extra_arg) \
423 ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
424 : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
426 -#define CALL_FREEFUN(h, old_chunk) \
427 +# define CALL_FREEFUN(h, old_chunk) \
429 if ((h) -> use_extra_arg) \
430 (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
432 (*(void (*) ()) (h)->freefun) ((old_chunk)); \
438 /* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
439 @@ -151,13 +154,13 @@
443 -#if defined (__STDC__) && __STDC__
444 +# if defined __STDC__ && __STDC__
445 POINTER (*chunkfun) (long);
446 void (*freefun) (void *);
449 POINTER (*chunkfun) ();
454 register struct _obstack_chunk *chunk; /* points to new chunk */
456 @@ -180,13 +183,13 @@
460 -#if defined (__STDC__) && __STDC__
461 +# if defined __STDC__ && __STDC__
462 h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
463 h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
466 h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
467 h->freefun = freefun;
470 h->chunk_size = size;
471 h->alignment_mask = alignment - 1;
472 h->use_extra_arg = 0;
473 @@ -209,13 +212,13 @@
477 -#if defined (__STDC__) && __STDC__
478 +# if defined __STDC__ && __STDC__
479 POINTER (*chunkfun) (POINTER, long);
480 void (*freefun) (POINTER, POINTER);
483 POINTER (*chunkfun) ();
489 register struct _obstack_chunk *chunk; /* points to new chunk */
490 @@ -239,13 +242,13 @@
494 -#if defined(__STDC__) && __STDC__
495 +# if defined __STDC__ && __STDC__
496 h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
497 h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
500 h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
501 h->freefun = freefun;
504 h->chunk_size = size;
505 h->alignment_mask = alignment - 1;
507 @@ -340,11 +343,11 @@
508 This is here for debugging.
509 If you use it in a program, you are probably losing. */
511 -#if defined (__STDC__) && __STDC__
512 +# if defined __STDC__ && __STDC__
513 /* Suppress -Wmissing-prototypes warning. We don't want to declare this in
514 obstack.h because it is just for debugging. */
515 int _obstack_allocated_p (struct obstack *h, POINTER obj);
520 _obstack_allocated_p (h, obj)
522 /* Free objects in obstack H, including OBJ and everything allocate
523 more recently than OBJ. If OBJ is zero, free everything in H. */
526 +# undef obstack_free
528 /* This function has two names with identical definitions.
529 This is the first one, called from non-ANSI code. */
530 @@ -455,45 +458,45 @@
533 /* Define the error handler. */
535 -# if defined HAVE_LIBINTL_H || defined _LIBC
536 -# include <libintl.h>
538 -# define _(Str) gettext (Str)
540 +# if defined HAVE_LIBINTL_H || defined _LIBC
541 +# include <libintl.h>
543 +# define _(Str) gettext (Str)
546 +# define _(Str) (Str)
549 -# define _(Str) (Str)
552 -#if defined _LIBC && defined USE_IN_LIBIO
553 -# include <libio/iolibio.h>
554 -# define fputs(s, f) _IO_fputs (s, f)
556 +# if defined _LIBC && defined USE_IN_LIBIO
557 +# include <libio/iolibio.h>
558 +# define fputs(s, f) _IO_fputs (s, f)
561 -#ifndef __attribute__
562 +# ifndef __attribute__
563 /* This feature is available in gcc versions 2.5 and later. */
564 -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
565 -# define __attribute__(Spec) /* empty */
566 +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
567 +# define __attribute__(Spec) /* empty */
573 __attribute__ ((noreturn))
576 fputs (_("memory exhausted"), stderr);
577 fputc ('\n', stderr);
578 exit (obstack_exit_failure);
583 /* These are now turned off because the applications do not use it
584 and it uses bcopy via obstack_grow, which causes trouble on sysV. */
586 /* Now define the functional versions of the obstack macros.
587 Define them to simply use the corresponding macros to do the job. */
589 -#if defined (__STDC__) && __STDC__
590 +# if defined __STDC__ && __STDC__
591 /* These function definitions do not work with non-ANSI preprocessors;
592 they won't pass through the macro names in parentheses. */
595 return obstack_copy0 (obstack, address, length);
598 -#endif /* __STDC__ */
599 +# endif /* __STDC__ */
604 #endif /* !ELIDE_CODE */