comparison src/alloc.c @ 386:4af0ddfb7c5b r21-2-8

Import from CVS: tag r21-2-8
author cvs
date Mon, 13 Aug 2007 11:08:50 +0200
parents 064ab7fed2e0
children 1f50e6fe4f3f
comparison
equal deleted inserted replaced
385:bc48d89bf15c 386:4af0ddfb7c5b
374 #endif 374 #endif
375 375
376 void * 376 void *
377 xmalloc (size_t size) 377 xmalloc (size_t size)
378 { 378 {
379 void *val = (void *) malloc (size); 379 void *val = malloc (size);
380 380
381 if (!val && (size != 0)) memory_full (); 381 if (!val && (size != 0)) memory_full ();
382 return val; 382 return val;
383 } 383 }
384 384
385 static void * 385 static void *
386 xcalloc (size_t nelem, size_t elsize) 386 xcalloc (size_t nelem, size_t elsize)
387 { 387 {
388 void *val = (void *) calloc (nelem, elsize); 388 void *val = calloc (nelem, elsize);
389 389
390 if (!val && (nelem != 0)) memory_full (); 390 if (!val && (nelem != 0)) memory_full ();
391 return val; 391 return val;
392 } 392 }
393 393
404 void * 404 void *
405 xrealloc (void *block, size_t size) 405 xrealloc (void *block, size_t size)
406 { 406 {
407 /* We must call malloc explicitly when BLOCK is 0, since some 407 /* We must call malloc explicitly when BLOCK is 0, since some
408 reallocs don't do this. */ 408 reallocs don't do this. */
409 void *val = (void *) (block ? realloc (block, size) : malloc (size)); 409 void *val = block ? realloc (block, size) : malloc (size);
410 410
411 if (!val && (size != 0)) memory_full (); 411 if (!val && (size != 0)) memory_full ();
412 return val; 412 return val;
413 } 413 }
414 414
3376 dumping out initialized variables (ie can't set xxx_type_index to -1 3376 dumping out initialized variables (ie can't set xxx_type_index to -1
3377 because that would make xxx_type_index read-only in a dumped emacs. */ 3377 because that would make xxx_type_index read-only in a dumped emacs. */
3378 if (type_index < 0 || type_index > max_lrecord_type 3378 if (type_index < 0 || type_index > max_lrecord_type
3379 || lrecord_implementations_table[type_index] != implementation) 3379 || lrecord_implementations_table[type_index] != implementation)
3380 { 3380 {
3381 if (last_lrecord_type_index_assigned == max_lrecord_type) 3381 assert (last_lrecord_type_index_assigned < max_lrecord_type);
3382 abort ();
3383 type_index = ++last_lrecord_type_index_assigned; 3382 type_index = ++last_lrecord_type_index_assigned;
3384 lrecord_implementations_table[type_index] = implementation; 3383 lrecord_implementations_table[type_index] = implementation;
3385 *(implementation->lrecord_type_index) = type_index; 3384 *(implementation->lrecord_type_index) = type_index;
3386 } 3385 }
3387 return type_index; 3386 return type_index;
3395 int bytes_in_use; 3394 int bytes_in_use;
3396 int instances_freed; 3395 int instances_freed;
3397 int bytes_freed; 3396 int bytes_freed;
3398 int instances_on_free_list; 3397 int instances_on_free_list;
3399 } lcrecord_stats [countof (lrecord_implementations_table)]; 3398 } lcrecord_stats [countof (lrecord_implementations_table)];
3400
3401
3402 static void
3403 reset_lcrecord_stats (void)
3404 {
3405 int i;
3406 for (i = 0; i < countof (lcrecord_stats); i++)
3407 {
3408 lcrecord_stats[i].instances_in_use = 0;
3409 lcrecord_stats[i].bytes_in_use = 0;
3410 lcrecord_stats[i].instances_freed = 0;
3411 lcrecord_stats[i].bytes_freed = 0;
3412 lcrecord_stats[i].instances_on_free_list = 0;
3413 }
3414 }
3415 3399
3416 static void 3400 static void
3417 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p) 3401 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
3418 { 3402 {
3419 CONST struct lrecord_implementation *implementation = 3403 CONST struct lrecord_implementation *implementation =
3450 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used) 3434 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
3451 { 3435 {
3452 struct lcrecord_header *header; 3436 struct lcrecord_header *header;
3453 int num_used = 0; 3437 int num_used = 0;
3454 /* int total_size = 0; */ 3438 /* int total_size = 0; */
3455 reset_lcrecord_stats (); 3439
3440 xzero (lcrecord_stats); /* Reset all statistics to 0. */
3456 3441
3457 /* First go through and call all the finalize methods. 3442 /* First go through and call all the finalize methods.
3458 Then go through and free the objects. There used to 3443 Then go through and free the objects. There used to
3459 be only one loop here, with the call to the finalizer 3444 be only one loop here, with the call to the finalizer
3460 occurring directly before the xfree() below. That 3445 occurring directly before the xfree() below. That