This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RE: [PATCH Configure] was RE: [PATCH] was RE: Perl_die() /Perl_croak()
[metaconfig.git] / U / modified / mallocsrc.U
1 ?RCS: $Id: mallocsrc.U,v 3.0.1.2 1997/02/28 16:10:26 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.2  1997/02/28  16:10:26  ram
13 ?RCS: patch61: added support for Free_t, the type of free()
14 ?RCS: patch61: replaced .o with $_o all over the place
15 ?RCS:
16 ?RCS: Revision 3.0.1.1  1994/05/06  15:10:46  ram
17 ?RCS: patch23: added support for MYMALLOC, mainly  for perl5 (ADO)
18 ?RCS:
19 ?RCS: Revision 3.0  1993/08/18  12:09:12  ram
20 ?RCS: Baseline for dist 3.0 netwide release.
21 ?RCS:
22 ?MAKE:mallocsrc mallocobj usemallocwrap usemymalloc malloctype d_mymalloc \
23         freetype: Myread \
24         Oldconfig package Guess Setvar rm cat +cc +ccflags Findhdr \
25         i_malloc i_stdlib sed libs _o ptrsize
26 ?MAKE:  -pick add $@ %<
27 ?X: Put near top so that other tests don't erroneously include
28 ?X: -lmalloc.  --AD  22 June 1998
29 ?Y:TOP
30 ?S:usemymalloc:
31 ?S:     This variable contains y if the malloc that comes with this package
32 ?S:     is desired over the system's version of malloc.  People often include
33 ?S:     special versions of malloc for effiency, but such versions are often
34 ?S:     less portable.  See also mallocsrc and mallocobj.
35 ?S:     If this is 'y', then -lmalloc is removed from $libs.
36 ?S:.
37 ?S:usemallocwrap:
38 ?S:     This variable contains y if we are wrapping malloc to prevent
39 ?S:     integer overflow during size calculations.
40 ?S:.
41 ?S:mallocsrc:
42 ?S:     This variable contains the name of the malloc.c that comes with
43 ?S:     the package, if that malloc.c is preferred over the system malloc.
44 ?S:     Otherwise the value is null.  This variable is intended for generating
45 ?S:     Makefiles.
46 ?S:.
47 ?S:d_mymalloc:
48 ?S:     This variable conditionally defines MYMALLOC in case other parts
49 ?S:     of the source want to take special action if MYMALLOC is used.
50 ?S:     This may include different sorts of profiling or error detection.
51 ?S:.
52 ?S:mallocobj:
53 ?S:     This variable contains the name of the malloc.o that this package
54 ?S:     generates, if that malloc.o is preferred over the system malloc.
55 ?S:     Otherwise the value is null.  This variable is intended for generating
56 ?S:     Makefiles.  See mallocsrc.
57 ?S:.
58 ?S:freetype:
59 ?S:     This variable contains the return type of free().  It is usually
60 ?S: void, but occasionally int.
61 ?S:.
62 ?S:malloctype:
63 ?S:     This variable contains the kind of ptr returned by malloc and realloc.
64 ?S:.
65 ?C:Free_t:
66 ?C:     This variable contains the return type of free().  It is usually
67 ?C: void, but occasionally int.
68 ?C:.
69 ?C:Malloc_t (MALLOCPTRTYPE):
70 ?C:     This symbol is the type of pointer returned by malloc and realloc.
71 ?C:.
72 ?H:#define Malloc_t $malloctype                 /**/
73 ?H:#define Free_t $freetype                     /**/
74 ?H:.
75 ?C:PERL_MALLOC_WRAP:
76 ?C:     This symbol, if defined, indicates that we'd like malloc wrap checks.
77 ?C:.
78 ?H:#$usemallocwrap PERL_MALLOC_WRAP             /**/
79 ?H:.
80 ?C:MYMALLOC:
81 ?C:     This symbol, if defined, indicates that we're using our own malloc.
82 ?C:.
83 ?H:#$d_mymalloc MYMALLOC                        /**/
84 ?H:.
85 ?LINT:extern usedevel
86 ?LINT:change usedevel
87 ?LINT:change libs
88 ?X: Cannot test for mallocsrc; it is the unit's name and there is a bug in
89 ?X: the interpreter which defines all the names, even though they are not used.
90 @if mallocobj
91 : determine whether to use malloc wrapping
92 echo " "
93 case "$usemallocwrap" in
94 [yY]*|true|$define)     dflt='y' ;;
95 [nN]*|false|$undef)     dflt='n' ;;
96 *)      case "$usedevel" in
97         [yY]*|true|$define)     dflt='y' ;;
98         *) dflt='n' ;;
99         esac
100         ;;
101 esac
102 rp="Do you wish to wrap malloc calls to protect against potential overflows?"
103 . ./myread
104 usemallocwrap="$ans"
105 case "$ans" in
106 y*|true)
107         usemallocwrap="$define" ;;
108 *)
109         usemallocwrap="$undef" ;;
110 esac
111
112 : determine which malloc to compile in
113 echo " "
114 case "$usemymalloc" in
115 [yY]*|true|$define)     dflt='y' ;;
116 [nN]*|false|$undef)     dflt='n' ;;
117 *)      case "$ptrsize" in
118         4) dflt='y' ;;
119         *) dflt='n' ;;
120         esac
121         ;;
122 esac
123 rp="Do you wish to attempt to use the malloc that comes with $package?"
124 . ./myread
125 usemymalloc="$ans"
126 case "$ans" in
127 y*|true)
128         usemymalloc='y'
129         mallocsrc='malloc.c'
130         mallocobj="malloc$_o"
131         d_mymalloc="$define"
132 ?X:     Maybe libs.U should be dependent on mallocsrc.U, but then
133 ?X:     most packages that use dist probably don't supply their own
134 ?X:     malloc, so this is probably an o.k. comprpomise
135         case "$libs" in
136         *-lmalloc*)
137                 : Remove malloc from list of libraries to use
138                 echo "Removing unneeded -lmalloc from library list" >&4
139                 set `echo X $libs | $sed -e 's/-lmalloc / /' -e 's/-lmalloc$//'`
140                 shift
141                 libs="$*"
142                 echo "libs = $libs" >&4
143                 ;;
144         esac
145         ;;
146 *)
147         usemymalloc='n'
148         mallocsrc=''
149         mallocobj=''
150         d_mymalloc="$undef"
151         ;;
152 esac
153
154 @end
155 @if MALLOCPTRTYPE || Malloc_t || Free_t
156 : compute the return types of malloc and free
157 echo " "
158 $cat >malloc.c <<END
159 #$i_malloc I_MALLOC
160 #$i_stdlib I_STDLIB
161 #include <stdio.h>
162 #include <sys/types.h>
163 #ifdef I_MALLOC
164 #include <malloc.h>
165 #endif
166 #ifdef I_STDLIB
167 #include <stdlib.h>
168 #endif
169 #ifdef TRY_MALLOC
170 void *malloc();
171 #endif
172 #ifdef TRY_FREE
173 void free();
174 #endif
175 END
176 @if MALLOCPTRTYPE || Malloc_t
177 case "$malloctype" in
178 '')
179         if $cc $ccflags -c -DTRY_MALLOC malloc.c >/dev/null 2>&1; then
180                 malloctype='void *'
181         else
182                 malloctype='char *'
183         fi
184         ;;
185 esac
186 echo "Your system wants malloc to return '$malloctype', it would seem." >&4
187 @end
188
189 @if Free_t
190 case "$freetype" in
191 '')
192         if $cc $ccflags -c -DTRY_FREE malloc.c >/dev/null 2>&1; then
193                 freetype='void'
194         else
195                 freetype='int'
196         fi
197         ;;
198 esac
199 echo "Your system uses $freetype free(), it would seem." >&4
200 @end
201 $rm -f malloc.[co]
202 @end