Mercurial > hg > xemacs-beta
comparison src/free-hook.c @ 185:3d6bfa290dbd r20-3b19
Import from CVS: tag r20-3b19
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:55:28 +0200 |
parents | 859a2309aef8 |
children | 52952cbfc5b5 |
comparison
equal
deleted
inserted
replaced
184:bcd2674570bf | 185:3d6bfa290dbd |
---|---|
201 static void | 201 static void |
202 check_free (void *ptr) | 202 check_free (void *ptr) |
203 { | 203 { |
204 #ifdef SAVE_STACK | 204 #ifdef SAVE_STACK |
205 FRAME start_frame; | 205 FRAME start_frame; |
206 | 206 |
207 init_frame (&start_frame); | 207 init_frame (&start_frame); |
208 #endif | 208 #endif |
209 | 209 |
210 __free_hook = 0; | 210 __free_hook = 0; |
211 __malloc_hook = 0; | 211 __malloc_hook = 0; |
216 long size; | 216 long size; |
217 #ifdef UNMAPPED_FREE | 217 #ifdef UNMAPPED_FREE |
218 unsigned long rounded_up_size; | 218 unsigned long rounded_up_size; |
219 #endif | 219 #endif |
220 | 220 |
221 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table, (void *) &size); | 221 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table, |
222 (void **) &size); | |
222 | 223 |
223 if (!present) | 224 if (!present) |
224 /* This can only happen if you try to free something that didn't | 225 /* This can only happen if you try to free something that didn't |
225 come from malloc */ | 226 come from malloc */ |
226 if (strict_free_check) | 227 if (strict_free_check) |
289 __free_hook = check_free; | 290 __free_hook = check_free; |
290 __malloc_hook = check_malloc; | 291 __malloc_hook = check_malloc; |
291 | 292 |
292 end: | 293 end: |
293 return; | 294 return; |
294 } | 295 } |
295 | 296 |
296 static void * | 297 static void * |
297 check_malloc (unsigned long size) | 298 check_malloc (unsigned long size) |
298 { | 299 { |
299 unsigned long rounded_up_size; | 300 unsigned long rounded_up_size; |
335 check_realloc (void * ptr, unsigned long size) | 336 check_realloc (void * ptr, unsigned long size) |
336 { | 337 { |
337 EMACS_INT present; | 338 EMACS_INT present; |
338 unsigned long old_size; | 339 unsigned long old_size; |
339 void *result = malloc (size); | 340 void *result = malloc (size); |
340 | 341 |
341 present = (EMACS_INT) gethash (ptr, pointer_table, (void *) &old_size); | 342 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size); |
342 if (!present) | 343 if (!present) |
343 /* This can only happen by reallocing a pointer that didn't | 344 /* This can only happen by reallocing a pointer that didn't |
344 come from malloc. */ | 345 come from malloc. */ |
345 abort (); | 346 abort (); |
346 if (result == 0) | 347 if (result == 0) |
349 free (ptr); | 350 free (ptr); |
350 end: | 351 end: |
351 return result; | 352 return result; |
352 } | 353 } |
353 | 354 |
354 void enable_strict_free_check (void); | 355 void enable_strict_free_check (void); |
355 void | 356 void |
356 enable_strict_free_check (void) | 357 enable_strict_free_check (void) |
357 { | 358 { |
358 strict_free_check = 1; | 359 strict_free_check = 1; |
359 } | 360 } |
360 | 361 |
361 void disable_strict_free_check (void); | 362 void disable_strict_free_check (void); |
362 void | 363 void |
363 disable_strict_free_check (void) | 364 disable_strict_free_check (void) |
364 { | 365 { |
365 strict_free_check = 0; | 366 strict_free_check = 0; |
366 } | 367 } |
443 if ((__free_hook != 0) && pointer_table) | 444 if ((__free_hook != 0) && pointer_table) |
444 { | 445 { |
445 count[0] = 0; | 446 count[0] = 0; |
446 count[1] = 0; | 447 count[1] = 0; |
447 __free_hook = 0; | 448 __free_hook = 0; |
448 maphash ((maphash_function)really_free_one_entry, | 449 maphash ((maphash_function)really_free_one_entry, |
449 pointer_table, (void *)&count); | 450 pointer_table, (void *)&count); |
450 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT); | 451 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT); |
451 current_free = 0; | 452 current_free = 0; |
452 __free_hook = check_free; | 453 __free_hook = check_free; |
453 XSETINT (lisp_count[0], count[0]); | 454 XSETINT (lisp_count[0], count[0]); |
492 typedef enum { | 493 typedef enum { |
493 block_type, unblock_type, totally_type, | 494 block_type, unblock_type, totally_type, |
494 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type | 495 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type |
495 } blocktype; | 496 } blocktype; |
496 | 497 |
497 struct block_input_history_struct { | 498 struct block_input_history_struct |
499 { | |
498 char *file; | 500 char *file; |
499 int line; | 501 int line; |
500 blocktype type; | 502 blocktype type; |
501 int value; | 503 int value; |
502 #ifdef SAVE_STACK | 504 #ifdef SAVE_STACK |
537 #ifdef SAVE_STACK | 539 #ifdef SAVE_STACK |
538 FRAME start_frame; | 540 FRAME start_frame; |
539 | 541 |
540 init_frame (&start_frame); | 542 init_frame (&start_frame); |
541 #endif | 543 #endif |
542 | 544 |
543 blhist[blhistptr].file = file; | 545 blhist[blhistptr].file = file; |
544 blhist[blhistptr].line = line; | 546 blhist[blhistptr].line = line; |
545 blhist[blhistptr].type = type; | 547 blhist[blhistptr].type = type; |
546 blhist[blhistptr].value = interrupt_input_blocked; | 548 blhist[blhistptr].value = interrupt_input_blocked; |
547 | 549 |