comparison src/free-hook.c @ 384:bbff43aa5eb7 r21-2-7

Import from CVS: tag r21-2-7
author cvs
date Mon, 13 Aug 2007 11:08:24 +0200
parents 8626e4521993
children 6719134a07c2
comparison
equal deleted inserted replaced
383:6a50c6a581a5 384:bbff43aa5eb7
64 64
65 #ifdef emacs 65 #ifdef emacs
66 #include <config.h> 66 #include <config.h>
67 #include "lisp.h" 67 #include "lisp.h"
68 #else 68 #else
69 void *malloc (unsigned long); 69 void *malloc (size_t);
70 #endif 70 #endif
71 71
72 #if !defined(HAVE_LIBMCHECK) 72 #if !defined(HAVE_LIBMCHECK)
73 #include <stdio.h> 73 #include <stdio.h>
74 74
86 /* extern void free (void *); */ 86 /* extern void free (void *); */
87 87
88 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) (unsigned long); 91 extern void *(*__malloc_hook) (size_t);
92 92
93 static void *check_malloc (unsigned long); 93 static void *check_malloc (size_t);
94 94
95 typedef void (*fun_ptr) (); 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
210 end: 210 end:
211 return; 211 return;
212 } 212 }
213 213
214 static void * 214 static void *
215 check_malloc (unsigned long size) 215 check_malloc (size_t size)
216 { 216 {
217 unsigned long rounded_up_size; 217 size_t rounded_up_size;
218 void *result; 218 void *result;
219 219
220 __free_hook = 0; 220 __free_hook = 0;
221 __malloc_hook = 0; 221 __malloc_hook = 0;
222 if (size == 0) 222 if (size == 0)
238 __malloc_hook = check_malloc; 238 __malloc_hook = check_malloc;
239 end: 239 end:
240 return result; 240 return result;
241 } 241 }
242 242
243 extern void *(*__realloc_hook) (void *, unsigned long); 243 extern void *(*__realloc_hook) (void *, size_t);
244 244
245 #ifdef MIN 245 #ifdef MIN
246 #undef MIN 246 #undef MIN
247 #endif 247 #endif
248 #define MIN(A, B) ((A) < (B) ? (A) : (B)) 248 #define MIN(A, B) ((A) < (B) ? (A) : (B))
249 249
250 /* Don't optimize realloc */ 250 /* Don't optimize realloc */
251 251
252 static void * 252 static void *
253 check_realloc (void * ptr, unsigned long size) 253 check_realloc (void * ptr, size_t size)
254 { 254 {
255 EMACS_INT present; 255 EMACS_INT present;
256 unsigned long 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)
293 293
294 /* Note: All BLOCK_INPUT stuff removed from this file because it's 294 /* Note: All BLOCK_INPUT stuff removed from this file because it's
295 completely gone in XEmacs */ 295 completely gone in XEmacs */
296 296
297 static void * 297 static void *
298 block_input_malloc (unsigned long size); 298 block_input_malloc (size_t size);
299 299
300 static void 300 static void
301 block_input_free (void* ptr) 301 block_input_free (void* ptr)
302 { 302 {
303 __free_hook = 0; 303 __free_hook = 0;
306 __free_hook = block_input_free; 306 __free_hook = block_input_free;
307 __malloc_hook = block_input_malloc; 307 __malloc_hook = block_input_malloc;
308 } 308 }
309 309
310 static void * 310 static void *
311 block_input_malloc (unsigned long size) 311 block_input_malloc (size_t size)
312 { 312 {
313 void* result; 313 void* result;
314 __free_hook = 0; 314 __free_hook = 0;
315 __malloc_hook = 0; 315 __malloc_hook = 0;
316 result = malloc (size); 316 result = malloc (size);
319 return result; 319 return result;
320 } 320 }
321 321
322 322
323 static void * 323 static void *
324 block_input_realloc (void* ptr, unsigned long size) 324 block_input_realloc (void* ptr, size_t size)
325 { 325 {
326 void* result; 326 void* result;
327 __free_hook = 0; 327 __free_hook = 0;
328 __malloc_hook = 0; 328 __malloc_hook = 0;
329 __realloc_hook = 0; 329 __realloc_hook = 0;
404 { 404 {
405 DEFSUBR (Freally_free); 405 DEFSUBR (Freally_free);
406 } 406 }
407 407
408 #else 408 #else
409 void (*__free_hook)() = check_free; 409 void (*__free_hook)(void *) = check_free;
410 void *(*__malloc_hook)() = check_malloc; 410 void *(*__malloc_hook)(size_t) = check_malloc;
411 void *(*__realloc_hook)() = check_realloc; 411 void *(*__realloc_hook)(void *, size_t) = check_realloc;
412 #endif 412 #endif
413 413
414 #endif /* !defined(HAVE_LIBMCHECK) */ 414 #endif /* !defined(HAVE_LIBMCHECK) */
415 415
416 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO) 416 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)