perl5.000 patch.0m: [various fixes, hint file updates and documentation]
[p5sagit/p5-mst-13.2.git] / U / mallocsrc.U
1 ?RCS: $Id: mallocsrc.U,v 3.0.1.1 1994/05/06 15:10:46 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?RCS: $Log: mallocsrc.U,v $
12 ?RCS: Revision 3.0.1.1  1994/05/06  15:10:46  ram
13 ?RCS: patch23: added support for MYMALLOC, mainly  for perl5 (ADO)
14 ?RCS:
15 ?RCS: Revision 3.0  1993/08/18  12:09:12  ram
16 ?RCS: Baseline for dist 3.0 netwide release.
17 ?RCS:
18 ?MAKE:mallocsrc mallocobj usemymalloc malloctype d_mymalloc \
19         freetype: Myread \
20         Oldconfig package Guess Setvar rm cat +cc +ccflags Findhdr \
21         i_malloc i_stdlib sed libs
22 ?MAKE:  -pick add $@ %<
23 ?S:usemymalloc:
24 ?S:     This variable contains y if the malloc that comes with this package
25 ?S:     is desired over the system's version of malloc.  People often include
26 ?S:     special versions of malloc for effiency, but such versions are often
27 ?S:     less portable.  See also mallocsrc and mallocobj.
28 ?S:     If this is 'y', then -lmalloc is removed from $libs.
29 ?S:.
30 ?S:mallocsrc:
31 ?S:     This variable contains the name of the malloc.c that comes with
32 ?S:     the package, if that malloc.c is preferred over the system malloc.
33 ?S:     Otherwise the value is null.  This variable is intended for generating
34 ?S:     Makefiles.
35 ?S:.
36 ?S:d_mymalloc:
37 ?S:     This variable conditionally defines MYMALLOC in case other parts
38 ?S:     of the source want to take special action if MYMALLOC is used.
39 ?S:     This may include different sorts of profiling or error detection.
40 ?S:.
41 ?S:mallocobj:
42 ?S:     This variable contains the name of the malloc.o that this package
43 ?S:     generates, if that malloc.o is preferred over the system malloc.
44 ?S:     Otherwise the value is null.  This variable is intended for generating
45 ?S:     Makefiles.  See mallocsrc.
46 ?S:.
47 ?S:freetype:
48 ?S:     This variable contains the return type of free().  It is usually
49 ?S: void, but occasionally int.
50 ?S:.
51 ?S:malloctype:
52 ?S:     This variable contains the kind of ptr returned by malloc and realloc.
53 ?S:.
54 ?C:Free_t:
55 ?C:     This variable contains the return type of free().  It is usually
56 ?C: void, but occasionally int.
57 ?C:.
58 ?C:Malloc_t (MALLOCPTRTYPE):
59 ?C:     This symbol is the type of pointer returned by malloc and realloc.
60 ?C:.
61 ?H:#define Malloc_t $malloctype                 /**/
62 ?H:#define Free_t $freetype                     /**/
63 ?H:.
64 ?C:MYMALLOC:
65 ?C:     This symbol, if defined, indicates that we're using our own malloc.
66 ?C:.
67 ?H:#$d_mymalloc MYMALLOC                        /**/
68 ?H:.
69 ?LINT:change libs
70 ?X: Cannot test for mallocsrc; it is the unit's name and there is a bug in
71 ?X: the interpreter which defines all the names, even though they are not used.
72 @if mallocobj
73 : determine which malloc to compile in
74 echo " "
75 case "$usemymalloc" in
76 ''|y*|true)     dflt='y' ;;
77 n*|false)       dflt='n' ;;
78 *)      dflt="$usemymalloc" ;;
79 esac
80 rp="Do you wish to attempt to use the malloc that comes with $package?"
81 . ./myread
82 usemymalloc="$ans"
83 case "$ans" in
84 y*|true)
85         usemymalloc='y'
86         mallocsrc='malloc.c'
87         mallocobj='malloc.o'
88         d_mymalloc="$define"
89 ?X:     Maybe libs.U should be dependent on mallocsrc.U, but then
90 ?X:     most packages that use dist probably don't supply their own
91 ?X:     malloc, so this is probably an o.k. comprpomise
92         case "$libs" in
93         *-lmalloc*)
94                 : Remove malloc from list of libraries to use
95                 echo "Removing unneeded -lmalloc from library list" >&4
96                 set `echo X $libs | $sed -e 's/-lmalloc / /' -e 's/-lmalloc$//'`
97                 shift
98                 libs="$*"
99                 echo "libs = $libs" >&4
100                 ;;
101         esac
102         ;;
103 *)
104         usemymalloc='n'
105         mallocsrc=''
106         mallocobj=''
107         d_mymalloc="$undef"
108         ;;
109 esac
110
111 @end
112 @if MALLOCPTRTYPE || Malloc_t || Free_t
113 : compute the return types of malloc and free
114 echo " "
115 $cat >malloc.c <<END
116 #$i_malloc I_MALLOC
117 #$i_stdlib I_STDLIB
118 #include <stdio.h>
119 #include <sys/types.h>
120 #ifdef I_MALLOC
121 #include <malloc.h>
122 #endif
123 #ifdef I_STDLIB
124 #include <stdlib.h>
125 #endif
126 #ifdef TRY_MALLOC
127 void *malloc();
128 #endif
129 #ifdef TRY_FREE
130 void free();
131 #endif
132 END
133 @if MALLOCPTRTYPE || Malloc_t
134 case "$malloctype" in
135 '')
136         if $cc $ccflags -c -DTRY_MALLOC malloc.c >/dev/null 2>&1; then
137                 malloctype='void *'
138         else
139                 malloctype='char *'
140         fi
141         ;;
142 esac
143 echo "Your system wants malloc to return '$malloctype', it would seem." >&4
144 @end
145
146 @if Free_t
147 case "$freetype" in
148 '')
149         if $cc $ccflags -c -DTRY_FREE malloc.c >/dev/null 2>&1; then
150                 freetype='void'
151         else
152                 freetype='int'
153         fi
154         ;;
155 esac
156 echo "Your system uses $freetype free(), it would seem." >&4
157 @end
158 $rm -f malloc.[co]
159 @end