annotate src/free-hook.c @ 5818:15b0715c204d

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