annotate src/free-hook.c @ 2850:ad0054aa11f1

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