]> git.pld-linux.org Git - packages/glibc.git/blame - glibc-malloc.patch
- fixed %%install with bzip2ed manuals
[packages/glibc.git] / glibc-malloc.patch
CommitLineData
04d3566f
AM
1diff -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
4@@ -57,7 +57,7 @@
5
6 # The Perl script to analyze the output of the mtrace functions.
7 ifneq ($(PERL),no)
8-install-bin = mtrace
9+install-bin-script = mtrace
10 generated = mtrace
11
12 # The Perl script will print addresses and to do this nicely we must know
13@@ -75,7 +75,7 @@
14 ifneq ($(cross-compiling),yes)
15 # If the gd library is available we build the `memusagestat' program.
16 ifneq ($(LIBGD),no)
17-install-bin += memusagestat memusage
18+install-bin = memusagestat memusage
19 generated += memusagestat memusage
20 extra-objs += memusagestat.o
21 endif
22diff -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
25@@ -19,7 +19,7 @@
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307 USA. */
28
29-/* $Id$
30+/* $Id$
31
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;
36 #ifdef _LIBC
37 s = NULL;
38- {
39- char **runp = _environ;
40- char *envline;
41+ if (_environ != NULL)
42+ {
43+ char **runp = _environ;
44+ char *envline;
45
46- while (__builtin_expect ((envline = next_env_entry (&runp)) != NULL,
47- 0))
48- {
49- size_t len = strcspn (envline, "=");
50+ while (__builtin_expect ((envline = next_env_entry (&runp)) != NULL, 0))
51+ {
52+ size_t len = strcspn (envline, "=");
53
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. */
58- continue;
59-
60- switch (len)
61- {
62- case 6:
63- if (memcmp (envline, "CHECK_", 6) == 0)
64- s = &envline[7];
65- break;
66- case 8:
67- if (! secure && memcmp (envline, "TOP_PAD_", 8) == 0)
68- mALLOPt(M_TOP_PAD, atoi(&envline[9]));
69- break;
70- case 9:
71- if (! secure && memcmp (envline, "MMAP_MAX_", 9) == 0)
72- mALLOPt(M_MMAP_MAX, atoi(&envline[10]));
73- break;
74- case 15:
75- if (! secure)
76- {
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]));
81- }
82- break;
83- default:
84- break;
85- }
86- }
87- }
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. */
92+ continue;
93+
94+ switch (len)
95+ {
96+ case 6:
97+ if (memcmp (envline, "CHECK_", 6) == 0)
98+ s = &envline[7];
99+ break;
100+ case 8:
101+ if (! secure && memcmp (envline, "TOP_PAD_", 8) == 0)
102+ mALLOPt(M_TOP_PAD, atoi(&envline[9]));
103+ break;
104+ case 9:
105+ if (! secure && memcmp (envline, "MMAP_MAX_", 9) == 0)
106+ mALLOPt(M_MMAP_MAX, atoi(&envline[10]));
107+ break;
108+ case 15:
109+ if (! secure)
110+ {
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]));
115+ }
116+ break;
117+ default:
118+ break;
119+ }
120+ }
121+ }
122 #else
123 if (! secure)
124 {
125@@ -2788,13 +2788,15 @@
126 mchunkptr victim;
127
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)) =
131+ __malloc_hook;
132+ if (hook != NULL) {
133 Void_t* result;
134
135 #if defined __GNUC__ && __GNUC__ >= 2
136- result = (*__malloc_hook)(bytes, RETURN_ADDRESS (0));
137+ result = (*hook)(bytes, RETURN_ADDRESS (0));
138 #else
139- result = (*__malloc_hook)(bytes, NULL);
140+ result = (*hook)(bytes, NULL);
141 #endif
142 return result;
143 }
144@@ -3111,11 +3113,14 @@
145 mchunkptr p; /* chunk corresponding to mem */
146
147 #if defined _LIBC || defined MALLOC_HOOKS
148- if (__free_hook != NULL) {
149+ void (*hook) __MALLOC_PMT ((__malloc_ptr_t, __const __malloc_ptr_t)) =
150+ __free_hook;
151+
152+ if (hook != NULL) {
153 #if defined __GNUC__ && __GNUC__ >= 2
154- (*__free_hook)(mem, RETURN_ADDRESS (0));
155+ (*hook)(mem, RETURN_ADDRESS (0));
156 #else
157- (*__free_hook)(mem, NULL);
158+ (*hook)(mem, NULL);
159 #endif
160 return;
161 }
162@@ -3314,13 +3319,16 @@
163 mchunkptr newp; /* chunk to return */
164
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)) =
169+ __realloc_hook;
170+ if (hook != NULL) {
171 Void_t* result;
172
173 #if defined __GNUC__ && __GNUC__ >= 2
174- result = (*__realloc_hook)(oldmem, bytes, RETURN_ADDRESS (0));
175+ result = (*hook)(oldmem, bytes, RETURN_ADDRESS (0));
176 #else
177- result = (*__realloc_hook)(oldmem, bytes, NULL);
178+ result = (*hook)(oldmem, bytes, NULL);
179 #endif
180 return result;
181 }
182@@ -3596,13 +3604,16 @@
183 mchunkptr p;
184
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)) =
189+ __memalign_hook;
190+ if (hook != NULL) {
191 Void_t* result;
192
193 #if defined __GNUC__ && __GNUC__ >= 2
194- result = (*__memalign_hook)(alignment, bytes, RETURN_ADDRESS (0));
195+ result = (*hook)(alignment, bytes, RETURN_ADDRESS (0));
196 #else
197- result = (*__memalign_hook)(alignment, bytes, NULL);
198+ result = (*hook)(alignment, bytes, NULL);
199 #endif
200 return result;
201 }
202@@ -3788,12 +3799,14 @@
203 Void_t* mem;
204
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)) =
208+ __malloc_hook;
209+ if (hook != NULL) {
210 sz = n * elem_size;
211 #if defined __GNUC__ && __GNUC__ >= 2
212- mem = (*__malloc_hook)(sz, RETURN_ADDRESS (0));
213+ mem = (*hook)(sz, RETURN_ADDRESS (0));
214 #else
215- mem = (*__malloc_hook)(sz, NULL);
216+ mem = (*hook)(sz, NULL);
217 #endif
218 if(mem == 0)
219 return 0;
220diff -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
223@@ -181,6 +181,13 @@
224 const char *env = getenv ("MEMUSAGE_PROG_NAME");
225 size_t prog_len = strlen (__progname);
226
227+ initialized = -1;
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");
232+ initialized = 1;
233+
234 if (env != NULL)
235 {
236 /* Check for program name. */
237@@ -198,13 +205,6 @@
238 if (!start_sp)
239 start_sp = GETSP ();
240
241- initialized = -1;
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");
246- initialized = 1;
247-
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 @@
252
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;
259+ if (len > old_len)
260+ {
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;
265+ }
266 /* Remember the size of the request. */
267 if (len < 65536)
268 ++histogram[len / 16];
269diff -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
272@@ -219,6 +219,11 @@
273 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
274 fi
275
276+# Set program name.
277+if test -n "$progname"; then
278+ add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
279+fi
280+
281 # Set buffer size.
282 if test -n "$buffer"; then
283 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
284diff -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
287@@ -97,7 +97,7 @@
288 if (_dl_addr (caller, &info))
289 {
290 char *buf = (char *) "";
291- if (info.dli_sname && info.dli_sname[0])
292+ if (info.dli_sname != NULL)
293 {
294 size_t len = strlen (info.dli_sname);
295 buf = alloca (len + 6 + 2 * sizeof (void *));
296diff -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
299@@ -19,7 +19,7 @@
300 02111-1307 USA. */
301
302 #ifdef HAVE_CONFIG_H
303-#include <config.h>
304+# include <config.h>
305 #endif
306
307 #include "obstack.h"
308@@ -39,40 +39,43 @@
309 files, it is simpler to just do this in the source for each such file. */
310
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
315-#define ELIDE_CODE
316-#endif
317+#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
318+# include <gnu-versions.h>
319+# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
320+# define ELIDE_CODE
321+# endif
322 #endif
323
324+#if defined _LIBC && defined USE_IN_LIBIO
325+# include <wchar.h>
326+#endif
327
328 #ifndef ELIDE_CODE
329
330
331-#if defined (__STDC__) && __STDC__
332-#define POINTER void *
333-#else
334-#define POINTER char *
335-#endif
336+# if defined __STDC__ && __STDC__
337+# define POINTER void *
338+# else
339+# define POINTER char *
340+# endif
341
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))
353
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
360-#endif
361+# ifndef COPYING_UNIT
362+# define COPYING_UNIT int
363+# endif
364
365
366 /* The functions allocating more room by calling `obstack_chunk_alloc'
367@@ -81,21 +84,21 @@
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;
375-#else
376+# else
377 static void print_and_abort ();
378 void (*obstack_alloc_failed_handler) () = print_and_abort;
379-#endif
380+# endif
381
382 /* Exit value used when `print_and_abort' is used. */
383-#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
384-#include <stdlib.h>
385-#endif
386-#ifndef EXIT_FAILURE
387-#define EXIT_FAILURE 1
388-#endif
389+# if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
390+# include <stdlib.h>
391+# endif
392+# ifndef EXIT_FAILURE
393+# define EXIT_FAILURE 1
394+# endif
395 int obstack_exit_failure = EXIT_FAILURE;
396
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. */
401
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)))
409
410-#define CALL_FREEFUN(h, old_chunk) \
411+# define CALL_FREEFUN(h, old_chunk) \
412 do { \
413 if ((h) -> use_extra_arg) \
414 (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
415 else \
416 (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
417 } while (0)
418-#else
419-#define CALL_CHUNKFUN(h, size) \
420+# else
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)))
425
426-#define CALL_FREEFUN(h, old_chunk) \
427+# define CALL_FREEFUN(h, old_chunk) \
428 do { \
429 if ((h) -> use_extra_arg) \
430 (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
431 else \
432 (*(void (*) ()) (h)->freefun) ((old_chunk)); \
433 } while (0)
434-#endif
435+# endif
436
437 \f
438 /* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
439@@ -151,13 +154,13 @@
440 struct obstack *h;
441 int size;
442 int alignment;
443-#if defined (__STDC__) && __STDC__
444+# if defined __STDC__ && __STDC__
445 POINTER (*chunkfun) (long);
446 void (*freefun) (void *);
447-#else
448+# else
449 POINTER (*chunkfun) ();
450 void (*freefun) ();
451-#endif
452+# endif
453 {
454 register struct _obstack_chunk *chunk; /* points to new chunk */
455
456@@ -180,13 +183,13 @@
457 size = 4096 - extra;
458 }
459
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;
464-#else
465+# else
466 h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
467 h->freefun = freefun;
468-#endif
469+# endif
470 h->chunk_size = size;
471 h->alignment_mask = alignment - 1;
472 h->use_extra_arg = 0;
473@@ -209,13 +212,13 @@
474 struct obstack *h;
475 int size;
476 int alignment;
477-#if defined (__STDC__) && __STDC__
478+# if defined __STDC__ && __STDC__
479 POINTER (*chunkfun) (POINTER, long);
480 void (*freefun) (POINTER, POINTER);
481-#else
482+# else
483 POINTER (*chunkfun) ();
484 void (*freefun) ();
485-#endif
486+# endif
487 POINTER arg;
488 {
489 register struct _obstack_chunk *chunk; /* points to new chunk */
490@@ -239,13 +242,13 @@
491 size = 4096 - extra;
492 }
493
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;
498-#else
499+# else
500 h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
501 h->freefun = freefun;
502-#endif
503+# endif
504 h->chunk_size = size;
505 h->alignment_mask = alignment - 1;
506 h->extra_arg = arg;
507@@ -340,11 +343,11 @@
508 This is here for debugging.
509 If you use it in a program, you are probably losing. */
510
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);
516-#endif
517+# endif
518
519 int
520 _obstack_allocated_p (h, obj)
521@@ -369,7 +372,7 @@
522 /* Free objects in obstack H, including OBJ and everything allocate
523 more recently than OBJ. If OBJ is zero, free everything in H. */
524
525-#undef obstack_free
526+# undef obstack_free
527
528 /* This function has two names with identical definitions.
529 This is the first one, called from non-ANSI code. */
433a8abe 530@@ -455,45 +458,45 @@
04d3566f
AM
531 }
532 \f
533 /* Define the error handler. */
534-#ifndef _
535-# if defined HAVE_LIBINTL_H || defined _LIBC
536-# include <libintl.h>
537-# ifndef _
538-# define _(Str) gettext (Str)
539+# ifndef _
540+# if defined HAVE_LIBINTL_H || defined _LIBC
541+# include <libintl.h>
542+# ifndef _
543+# define _(Str) gettext (Str)
544+# endif
545+# else
546+# define _(Str) (Str)
547 # endif
548-# else
549-# define _(Str) (Str)
550 # endif
551-#endif
552-#if defined _LIBC && defined USE_IN_LIBIO
553-# include <libio/iolibio.h>
554-# define fputs(s, f) _IO_fputs (s, f)
555-#endif
556+# if defined _LIBC && defined USE_IN_LIBIO
557+# include <libio/iolibio.h>
558+# define fputs(s, f) _IO_fputs (s, f)
559+# endif
560
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 */
568+# endif
569 # endif
570-#endif
571
572 static void
573 __attribute__ ((noreturn))
574 print_and_abort ()
575 {
433a8abe
AF
576 fputs (_("memory exhausted"), stderr);
577 fputc ('\n', stderr);
04d3566f
AM
578 exit (obstack_exit_failure);
579 }
580 \f
581-#if 0
582+# if 0
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. */
585
586 /* Now define the functional versions of the obstack macros.
587 Define them to simply use the corresponding macros to do the job. */
588
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. */
593
594@@ -604,8 +616,8 @@
595 return obstack_copy0 (obstack, address, length);
596 }
597
598-#endif /* __STDC__ */
599+# endif /* __STDC__ */
600
601-#endif /* 0 */
602+# endif /* 0 */
603
604 #endif /* !ELIDE_CODE */
This page took 0.096544 seconds and 4 git commands to generate.