pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:13:   #include "pike_macros.h"   #include "pike_error.h"   #include "pike_memory.h"   #include "pike_types.h"   #include "dynamic_buffer.h"   #include "interpret.h"   #include "las.h"   #include "gc.h"   #include "stralloc.h"   #include "pike_security.h" - #include "block_alloc.h" + #include "block_allocator.h"   #include "opcodes.h"   #include "stuff.h"      #define AVG_LINK_LENGTH 4   #define MIN_LINK_LENGTH 1   #define MAP_SLOTS(X) ((X)?((X)+((X)>>4)+8):0)      struct mapping *first_mapping;      struct mapping *gc_internal_mapping = 0;
pike.git/src/mapping.c:35:      #define unlink_mapping_data(M) do{ \    struct mapping_data *md_=(M); \    if(md_->hardlinks) { md_->hardlinks--; md_->valrefs--; } \    free_mapping_data(M); \   }while(0)      #define MAPPING_DATA_SIZE(HSIZE, KEYPAIRS) \    PTR_TO_INT(MD_KEYPAIRS(0, HSIZE) + KEYPAIRS)    - #undef EXIT_BLOCK - #define EXIT_BLOCK(m) do{ \ - DO_IF_DEBUG( \ -  if(m->refs) { \ -  DO_IF_DMALLOC(describe_something(m, T_MAPPING, 0,2,0, NULL)); \ -  Pike_fatal("really free mapping on mapping with %d refs.\n", m->refs); \ -  } \ - ) \ -  \ -  FREE_PROT(m); \ -  \ -  unlink_mapping_data(m->data); \ -  \ -  DOUBLEUNLINK(first_mapping, m); \ -  \ -  GC_FREE(m); \ - }while(0) + static struct block_allocator mapping_allocator = BA_INIT_PAGES(sizeof(struct mapping), 2); + void count_memory_in_mappings(size_t * num, size_t * size) { +  struct mapping *m; +  double datasize = 0.0; +  ba_count_all(&mapping_allocator, num, size); +  for(m=first_mapping;m;m=m->next) { +  datasize+=MAPPING_DATA_SIZE(m->data->hashsize, m->data->num_keypairs) / (double) m->data->refs; +  } +  *size += (size_t) datasize; + }    -  + void really_free_mapping(struct mapping * m) { + #ifdef PIKE_DEBUG +  if (m->refs) { + # ifdef DEBUG_MALLOC +  describe_something(m, T_MAPPING, 0,2,0, NULL); + # endif +  Pike_fatal("really free mapping on mapping with %d refs.\n", m->refs); +  } + #endif +  FREE_PROT(m); +  unlink_mapping_data(m->data); +  DOUBLEUNLINK(first_mapping, m); +  GC_FREE(m); +  ba_free(&mapping_allocator, m); + }    - #undef COUNT_OTHER + ATTRIBUTE((malloc)) + static struct mapping * alloc_mapping() { +  return ba_alloc(&mapping_allocator); + }    - #define COUNT_OTHER() do{ \ -  struct mapping *m; \ -  double datasize = 0.0; \ -  for(m=first_mapping;m;m=m->next) \ -  { \ -  datasize+=MAPPING_DATA_SIZE(m->data->hashsize, m->data->num_keypairs) / \ -  (double) m->data->refs; \ -  } \ -  size += (size_t) datasize; \ - }while(0) -  - BLOCK_ALLOC_FILL_PAGES(mapping, 2) -  +    #ifndef PIKE_MAPPING_KEYPAIR_LOOP   #define IF_ELSE_KEYPAIR_LOOP(X, Y) Y   #define FREE_KEYPAIR(md, k) do { \    k->next = md->free_list; \    md->free_list = k; \    } while(0)   #else /* PIKE_MAPPING_KEYPAIR_LOOP */   #define IF_ELSE_KEYPAIR_LOOP(X, Y) X   #define FREE_KEYPAIR(md, k) do { \    md->free_list--; \