annotate src/free-hook.c @ 325:f2b5d7006b0a r21-0-60

Import from CVS: tag r21-0-60
author cvs
date Mon, 13 Aug 2007 10:47:35 +0200
parents c5d627a313b1
children fbbf69b4e8a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 /* Debugging hooks for malloc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* These hooks work with gmalloc to catch allocation errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 In particular, the following is trapped:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Freeing the same pointer twice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * Trying to free a pointer not returned by malloc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * Trying to realloc a pointer not returned by malloc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 In addition, every word of every block freed is set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 0xdeadbeef. This causes many uses of freed storage to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 trapped or recognized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 When you use this, the storage used by the last FREE_QUEUE_LIMIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 calls to free() is not recycled. When you call free for the Nth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 time, the (N - FREE_QUEUE_LIMIT)'th block is actually recycled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 For these last FREE_QUEUE_LIMIT calls to free() a backtrace is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 saved showing where it was called from. The function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 find_backtrace() is provided here to be called from GDB with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 pointer (such as would be passed to free()) as argument, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (gdb) p/a *find_backtrace (0x234000). If SAVE_ARGS is defined,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 the first three arguments to each function are saved as well as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 return addresses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 If UNMAPPED_FREE is defined, instead of setting every word of freed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 storage to 0xdeadbeef, every call to malloc goes on its own page(s).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 When free() is called, the block is read and write protected. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 is very useful when debugging, since it usually generates a bus error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 when the deadbeef hack might only cause some garbage to be printed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 However, this is too slow for everyday use, since it takes an enormous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 number of pages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Some other features that would be useful are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 * Checking for storage leaks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 This could be done by a GC-like facility that would scan the data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 segment looking for pointers to allocated storage and tell you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 about those that are no longer referenced. This could be invoked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 at any time. Another possibility is to report on what allocated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 storage is still in use when the process is exited. Typically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 there will be a large amount, so this might not be very useful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #if defined (EMACS_BTL) && defined (sun4) && !defined (__lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 /* currently only works in this configuration */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 # define SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #include "cadillac-btl.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 void *malloc (unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
80 #if !defined(HAVE_LIBMCHECK)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 #include "hash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #include <sys/mman.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 #include <sys/param.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 #define ROUND_UP_TO_PAGE(i) (((i) + PAGEOFFSET) & PAGEMASK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 /* System function prototypes don't belong in C source files */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 /* extern void free (void *); */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 c_hashtable pointer_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 extern void (*__free_hook) (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 extern void *(*__malloc_hook) (unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 static void *check_malloc (unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 typedef void (*fun_ptr) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #define FREE_QUEUE_LIMIT 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* free_queue is not too useful without backtrace logging */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #define FREE_QUEUE_LIMIT 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #define TRACE_LIMIT 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 typedef struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 fun_ptr return_pc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #ifdef SAVE_ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 void *arg[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 } fun_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 typedef struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 void *address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 unsigned long length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 fun_entry backtrace[TRACE_LIMIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 } free_queue_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 free_queue_entry free_queue[FREE_QUEUE_LIMIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 int current_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 init_frame (FRAME *fptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 FRAME tmp_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 #ifdef sparc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 /* Do the system trap ST_FLUSH_WINDOWS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 asm ("ta 3");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 asm ("st %sp, [%i0+0]");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 asm ("st %fp, [%i0+4]");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 fptr->pc = (char *) init_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 tmp_frame = *fptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 PREVIOUS_FRAME (tmp_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 *fptr = tmp_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #ifdef SAVE_ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 frame_arg (FRAME *fptr, int index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 return ((void *) FRAME_ARG(*fptr, index));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 save_backtrace (FRAME *current_frame_ptr, fun_entry *table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 int i = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 #ifdef SAVE_ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 int j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 FRAME current_frame = *current_frame_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /* Get up and out of free() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 PREVIOUS_FRAME (current_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 /* now do the basic loop adding data until there is no more */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 while (PREVIOUS_FRAME (current_frame) && i < TRACE_LIMIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 table[i].return_pc = (void (*)())FRAME_PC (current_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 #ifdef SAVE_ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 for (j = 0; j < 3; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 table[i].arg[j] = frame_arg (&current_frame, j);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 i++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 memset (&table[i], 0, sizeof (fun_entry) * (TRACE_LIMIT - i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 free_queue_entry *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 find_backtrace (void *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 for (i = 0; i < FREE_QUEUE_LIMIT; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 if (free_queue[i].address == ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 return &free_queue[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 #endif /* SAVE_STACK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 int strict_free_check;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 check_free (void *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 FRAME start_frame;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
207
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 init_frame (&start_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 __free_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 __malloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 if (!pointer_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 pointer_table = make_hashtable (max (100, FREE_QUEUE_LIMIT * 2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 if (ptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 long size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 unsigned long rounded_up_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
222 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
223 (CONST void **) &size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 if (!present)
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 185
diff changeset
226 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 /* This can only happen if you try to free something that didn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 come from malloc */
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
229 #if !defined(__linux__)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
230 /* I originally wrote: "There's really no need to drop core."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
231 I have seen the error of my ways. -slb */
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
232 if (strict_free_check)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
233 abort ();
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
234 #endif
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
235 printf("Freeing unmalloc'ed memory at %p\n", ptr);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
236 __free_hook = check_free;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
237 __malloc_hook = check_malloc;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
238 goto end;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 185
diff changeset
239 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 if (size < 0)
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 185
diff changeset
242 {
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
243 /* This happens when you free twice */
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
244 #if !defined(__linux__)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
245 /* See above comment. */
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
246 if (strict_free_check)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
247 abort ();
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
248 #endif
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
249 printf("Freeing %p twice\n", ptr);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
250 __free_hook = check_free;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
251 __malloc_hook = check_malloc;
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
252 goto end;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 185
diff changeset
253 }
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
254
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 puthash (ptr, (void *)-size, pointer_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 /* Round up size to an even number of pages. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 rounded_up_size = ROUND_UP_TO_PAGE (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 /* Protect the pages freed from all access */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 if (strict_free_check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 mprotect (ptr, rounded_up_size, PROT_NONE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 /* Set every word in the block to 0xdeadbeef */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 if (strict_free_check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 unsigned long long_length = (size + (sizeof (long) - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 / sizeof (long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 unsigned long i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 for (i = 0; i < long_length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ((unsigned long *) ptr)[i] = 0xdeadbeef;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 free_queue[current_free].address = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 free_queue[current_free].length = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 save_backtrace (&start_frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 free_queue[current_free].backtrace);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 current_free++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 if (current_free >= FREE_QUEUE_LIMIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 current_free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 /* Really free this if there's something there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 void *old = free_queue[current_free].address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 if (old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 unsigned long old_len = free_queue[current_free].length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 mprotect (old, old_len, PROT_READ | PROT_WRITE | PROT_EXEC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 free (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 remhash (old, pointer_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 __free_hook = check_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 __malloc_hook = check_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 return;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
304 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 check_malloc (unsigned long size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 unsigned long rounded_up_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 void *result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 __free_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 __malloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (size == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 result = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 goto end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 /* Round up to an even number of pages. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 rounded_up_size = ROUND_UP_TO_PAGE (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 rounded_up_size = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 result = malloc (rounded_up_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 if (!pointer_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 pointer_table = make_hashtable (FREE_QUEUE_LIMIT * 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 puthash (result, (void *)size, pointer_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 __free_hook = check_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 __malloc_hook = check_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 extern void *(*__realloc_hook) (void *, unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 #ifdef MIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 #undef MIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 #define MIN(A, B) ((A) < (B) ? (A) : (B))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 /* Don't optimize realloc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 check_realloc (void * ptr, unsigned long size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 EMACS_INT present;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 unsigned long old_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 void *result = malloc (size);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
350
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
351 if (!ptr) return result;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
352 present = (EMACS_INT) gethash (ptr, pointer_table, (CONST void **) &old_size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if (!present)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
354 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 /* This can only happen by reallocing a pointer that didn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 come from malloc. */
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
357 #if !defined(__linux__)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
358 /* see comment in check_free(). */
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
359 abort ();
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
360 #endif
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
361 printf("Realloc'ing unmalloc'ed pointer at %p\n", ptr);
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
362 }
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
363
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 if (result == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 goto end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 memcpy (result, ptr, MIN (size, old_size));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 free (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
372 void enable_strict_free_check (void);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 enable_strict_free_check (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 strict_free_check = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
379 void disable_strict_free_check (void);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 disable_strict_free_check (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 strict_free_check = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 /* Note: All BLOCK_INPUT stuff removed from this file because it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 completely gone in XEmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 block_input_malloc (unsigned long size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 block_input_free (void* ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 __free_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 __malloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 free (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 __free_hook = block_input_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 __malloc_hook = block_input_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 block_input_malloc (unsigned long size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 void* result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 __free_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 __malloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 result = malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 __free_hook = block_input_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 __malloc_hook = block_input_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 block_input_realloc (void* ptr, unsigned long size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 void* result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 __free_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 __malloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 __realloc_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 result = realloc (ptr, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 __free_hook = block_input_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 __malloc_hook = block_input_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 __realloc_hook = block_input_realloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 void disable_free_hook (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 disable_free_hook (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 __free_hook = block_input_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 __malloc_hook = block_input_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 __realloc_hook = block_input_realloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 init_free_hook (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 __free_hook = check_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 __malloc_hook = check_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 __realloc_hook = check_realloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 current_free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 strict_free_check = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 void really_free_one_entry (void *, int, int *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
452 DEFUN ("really-free", Freally_free, 0, 1, "P", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Actually free the storage held by the free() debug hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 A no-op if the free hook is disabled.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
455 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
456 (arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 int count[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 Lisp_Object lisp_count[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 if ((__free_hook != 0) && pointer_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 count[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 count[1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 __free_hook = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
466 maphash ((maphash_function)really_free_one_entry,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 pointer_table, (void *)&count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 current_free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 __free_hook = check_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 XSETINT (lisp_count[0], count[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 XSETINT (lisp_count[1], count[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 return Fcons (lisp_count[0], lisp_count[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 return Fcons (make_int (0), make_int (0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 really_free_one_entry (void *key, int contents, int *countp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 if (contents < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 free (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 #ifdef UNMAPPED_FREE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 mprotect (key, -contents, PROT_READ | PROT_WRITE | PROT_EXEC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 remhash (key, pointer_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 countp[0]++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 countp[1] += -contents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 syms_of_free_hook (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
497 DEFSUBR (Freally_free);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 void (*__free_hook)() = check_free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 void *(*__malloc_hook)() = check_malloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 void *(*__realloc_hook)() = check_realloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 233
diff changeset
506 #endif /* !defined(HAVE_LIBMCHECK) */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 /* Note: There is no more input blocking in XEmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 typedef enum {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 block_type, unblock_type, totally_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 } blocktype;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
516 struct block_input_history_struct
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
517 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 char *file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 int line;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 blocktype type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 int value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 fun_entry backtrace[TRACE_LIMIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 typedef struct block_input_history_struct block_input_history;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 #ifdef DEBUG_INPUT_BLOCKING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 int blhistptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 #define BLHISTLIMIT 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 block_input_history blhist[BLHISTLIMIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 note_block_input (char *file, int line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 note_block (file, line, block_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 if (interrupt_input_blocked > 2) abort();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 note_unblock_input (char* file, int line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 note_block (file, line, unblock_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 note_totally_unblocked (char* file, int line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 note_block (file, line, totally_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 note_block (char *file, int line, blocktype type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 FRAME start_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 init_frame (&start_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 20
diff changeset
562
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 blhist[blhistptr].file = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 blhist[blhistptr].line = line;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 blhist[blhistptr].type = type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 blhist[blhistptr].value = interrupt_input_blocked;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 save_backtrace (&start_frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 blhist[blhistptr].backtrace);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 blhistptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 if (blhistptr >= BLHISTLIMIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 blhistptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 #ifdef DEBUG_GCPRO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 int gcprohistptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 #define GCPROHISTLIMIT 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 block_input_history gcprohist[GCPROHISTLIMIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 log_gcpro (char *file, int line, struct gcpro *value, blocktype type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 FRAME start_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 if (type == ungcpro_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 if (value == gcprolist) goto OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 if (! gcprolist) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 if (value == gcprolist->next) goto OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 if (! gcprolist->next) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 if (value == gcprolist->next->next) goto OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 if (! gcprolist->next->next) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 if (value == gcprolist->next->next->next) goto OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 OK:;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 init_frame (&start_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 gcprohist[gcprohistptr].file = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 gcprohist[gcprohistptr].line = line;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 gcprohist[gcprohistptr].type = type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 gcprohist[gcprohistptr].value = (int) value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 #ifdef SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 save_backtrace (&start_frame, gcprohist[gcprohistptr].backtrace);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 gcprohistptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 if (gcprohistptr >= GCPROHISTLIMIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 gcprohistptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 debug_gcpro1 (char *file, int line, struct gcpro *gcpro1, Lisp_Object *var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 gcpro1->next = gcprolist; gcpro1->var = var; gcpro1->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 gcprolist = gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 log_gcpro (file, line, gcpro1, gcpro1_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 debug_gcpro2 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 Lisp_Object *var1, Lisp_Object *var2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 gcprolist = gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 log_gcpro (file, line, gcpro2, gcpro2_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 debug_gcpro3 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 struct gcpro *gcpro3, Lisp_Object *var1, Lisp_Object *var2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 Lisp_Object *var3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 gcprolist = gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 log_gcpro (file, line, gcpro3, gcpro3_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 debug_gcpro4 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 struct gcpro *gcpro3, struct gcpro *gcpro4, Lisp_Object *var1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 Lisp_Object *var2, Lisp_Object *var3, Lisp_Object *var4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 log_gcpro (file, line, gcpro4, gcpro4_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 gcprolist = gcpro4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 debug_gcpro5 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 Lisp_Object *var1, Lisp_Object *var2, Lisp_Object *var3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 Lisp_Object *var4, Lisp_Object *var5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 log_gcpro (file, line, gcpro5, gcpro5_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 gcpro5->next = gcpro4; gcpro5->var = var5; gcpro5->nvars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 gcprolist = gcpro5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 debug_ungcpro (char *file, int line, struct gcpro *gcpro1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 log_gcpro (file, line, gcpro1, ungcpro_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 gcprolist = gcpro1->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 show_gcprohist (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 int i, j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 for (i = 0, j = gcprohistptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 i < GCPROHISTLIMIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 i++, j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 if (j >= GCPROHISTLIMIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 j = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 printf ("%3d %s %d %s 0x%x\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 j, gcprohist[j].file, gcprohist[j].line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (gcprohist[j].type == gcpro1_type ? "GCPRO1" :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 gcprohist[j].type == gcpro2_type ? "GCPRO2" :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 gcprohist[j].type == gcpro3_type ? "GCPRO3" :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 gcprohist[j].type == gcpro4_type ? "GCPRO4" :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 gcprohist[j].type == ungcpro_type ? "UNGCPRO" : "???"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 gcprohist[j].value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 #endif