Mercurial > hg > xemacs-beta
comparison src/free-hook.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children | 11054d720c21 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
83 #include <sys/types.h> | 83 #include <sys/types.h> |
84 | 84 |
85 /* System function prototypes don't belong in C source files */ | 85 /* System function prototypes don't belong in C source files */ |
86 /* extern void free (void *); */ | 86 /* extern void free (void *); */ |
87 | 87 |
88 static struct hash_table *pointer_table; | 88 struct hash_table *pointer_table; |
89 | 89 |
90 extern void (*__free_hook) (void *); | 90 extern void (*__free_hook) (void *); |
91 extern void *(*__malloc_hook) (size_t); | 91 extern void *(*__malloc_hook) (size_t); |
92 | 92 |
93 static void *check_malloc (size_t); | 93 static void *check_malloc (size_t); |
94 | 94 |
95 typedef void (*fun_ptr) (void); | 95 typedef void (*fun_ptr) (); |
96 | 96 |
97 /* free_queue is not too useful without backtrace logging */ | 97 /* free_queue is not too useful without backtrace logging */ |
98 #define FREE_QUEUE_LIMIT 1 | 98 #define FREE_QUEUE_LIMIT 1 |
99 #define TRACE_LIMIT 20 | 99 #define TRACE_LIMIT 20 |
100 | 100 |
108 typedef struct { | 108 typedef struct { |
109 void *address; | 109 void *address; |
110 unsigned long length; | 110 unsigned long length; |
111 } free_queue_entry; | 111 } free_queue_entry; |
112 | 112 |
113 static free_queue_entry free_queue[FREE_QUEUE_LIMIT]; | 113 free_queue_entry free_queue[FREE_QUEUE_LIMIT]; |
114 | 114 |
115 static int current_free; | 115 int current_free; |
116 | 116 |
117 static int strict_free_check; | 117 int strict_free_check; |
118 | 118 |
119 static void | 119 static void |
120 check_free (void *ptr) | 120 check_free (void *ptr) |
121 { | 121 { |
122 __free_hook = 0; | 122 __free_hook = 0; |
129 #ifdef UNMAPPED_FREE | 129 #ifdef UNMAPPED_FREE |
130 unsigned long rounded_up_size; | 130 unsigned long rounded_up_size; |
131 #endif | 131 #endif |
132 | 132 |
133 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table, | 133 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table, |
134 (const void **) &size); | 134 (CONST void **) &size); |
135 | 135 |
136 if (!present) | 136 if (!present) |
137 { | 137 { |
138 /* This can only happen if you try to free something that didn't | 138 /* This can only happen if you try to free something that didn't |
139 come from malloc */ | 139 come from malloc */ |
255 EMACS_INT present; | 255 EMACS_INT present; |
256 size_t old_size; | 256 size_t old_size; |
257 void *result = malloc (size); | 257 void *result = malloc (size); |
258 | 258 |
259 if (!ptr) return result; | 259 if (!ptr) return result; |
260 present = (EMACS_INT) gethash (ptr, pointer_table, (const void **) &old_size); | 260 present = (EMACS_INT) gethash (ptr, pointer_table, (CONST void **) &old_size); |
261 if (!present) | 261 if (!present) |
262 { | 262 { |
263 /* This can only happen by reallocing a pointer that didn't | 263 /* This can only happen by reallocing a pointer that didn't |
264 come from malloc. */ | 264 come from malloc. */ |
265 #if !defined(__linux__) | 265 #if !defined(__linux__) |