Branch: Tag:

1999-05-02

1999-05-02 08:13:05 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

more debug and fixed a memory leak in interpret.c

Rev: src/backend.c:1.41
Rev: src/backend.h:1.7
Rev: src/block_alloc.h:1.11
Rev: src/block_alloc_h.h:1.4
Rev: src/builtin_functions.c:1.168
Rev: src/callback.c:1.17
Rev: src/callback.h:1.8
Rev: src/configure.in:1.281
Rev: src/constants.c:1.18
Rev: src/dmalloc.h:1.11
Rev: src/error.c:1.35
Rev: src/error.h:1.36
Rev: src/gc.c:1.42
Rev: src/gc.h:1.22
Rev: src/interpret.c:1.122
Rev: src/interpret.h:1.31
Rev: src/interpreter.h:1.5
Rev: src/modules/call_out/call_out.c:1.27
Rev: src/modules/files/file.c:1.152
Rev: src/modules/system/system.c:1.70
Rev: src/pike_memory.c:1.37
Rev: src/program.c:1.123
Rev: src/signal_handler.c:1.129
Rev: src/stralloc.c:1.59
Rev: src/threads.c:1.93

1: - /* $Id: block_alloc.h,v 1.10 1999/04/08 22:27:06 hubbe Exp $ */ + /* $Id: block_alloc.h,v 1.11 1999/05/02 08:11:30 hubbe Exp $ */   #undef PRE_INIT_BLOCK   #undef INIT_BLOCK   #undef EXIT_BLOCK
47:    \    tmp=PIKE_CONCAT3(free_,DATA,s); \    PIKE_CONCAT3(free_,DATA,s)=tmp->next; \ +  DO_IF_DMALLOC( dmalloc_register(tmp,0, __FILE__, __LINE__); ) \    INIT_BLOCK(tmp); \    return tmp; \   } \
54:   void PIKE_CONCAT(really_free_,DATA)(struct DATA *d) \   { \    EXIT_BLOCK(d); \ +  DO_IF_DMALLOC( dmalloc_unregister(d, 1); ) \    d->next=PIKE_CONCAT3(free_,DATA,s); \    PRE_INIT_BLOCK(d); \    PIKE_CONCAT3(free_,DATA,s)=d; \
70:    PIKE_CONCAT(DATA,_blocks)=0; \    PIKE_CONCAT3(free_,DATA,s)=0; \   } \ +  \ +  \ + void PIKE_CONCAT3(count_memory_in_,DATA,s)(INT32 *num_, INT32 *size_) \ + { \ +  INT32 num=0, size=0; \ +  struct PIKE_CONCAT(DATA,_block) *tmp; \ +  struct DATA *tmp2; \ +  for(tmp=PIKE_CONCAT(DATA,_blocks);tmp;tmp=tmp->next) \ +  { \ +  num+=BSIZE; \ +  size+=sizeof(struct PIKE_CONCAT(DATA,_block)); \ +  } \ +  for(tmp2=PIKE_CONCAT3(free_,DATA,s);tmp2;tmp2=tmp2->next) num--; \ +  *num_=num; \ +  *size_=size; \ + }         
108:   } \    \    \ -  \ - struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr, int hval) \ + static void PIKE_CONCAT(DATA,_rehash)() \   { \ -  struct DATA *p; \ -  \ -  DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \ -  fatal("Hash table error!\n"); ) \ -  PIKE_CONCAT(num_,DATA)++; \ -  \ -  if(( PIKE_CONCAT(num_,DATA)>>2 ) >= \ -  PIKE_CONCAT(DATA,_hash_table_size)) \ -  { \ -  /* Time to re-hash */ \ +  /* Time to re-hash */ \    struct DATA **old_hash= PIKE_CONCAT(DATA,_hash_table); \ -  +  struct DATA *p; \ +  int hval; \    int e=PIKE_CONCAT(DATA,_hash_table_size); \    \    PIKE_CONCAT(DATA,_hash_table_size)*=2; \ -  PIKE_CONCAT(DATA,_hash_table_size)++; \ +  PIKE_CONCAT(DATA,_hash_table_size)++; \    if((PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \    malloc(PIKE_CONCAT(DATA,_hash_table_size)* \    sizeof(struct DATA *)))) \    { \    MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \    sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ -  while(e-- >=0) \ +  while(--e >=0) \    { \ -  while((p=old_hash[e])) \ -  { \ -  old_hash[e]=p->next; \ -  hval=(long)(p-> data); \ +  while((p=old_hash[e])) \ +  { \ +  old_hash[e]=p->next; \ +  hval=(long)(p-> data); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    p->next=PIKE_CONCAT(DATA,_hash_table)[hval]; \ -  PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ -  } \ +  PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    } \ -  hval=(long)ptr; \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ -  free((char *)old_hash); \ +  } \ +  free((char *)old_hash); \    }else{ \ -  PIKE_CONCAT(DATA,_hash_table)=old_hash; \ +  PIKE_CONCAT(DATA,_hash_table)=old_hash; \    PIKE_CONCAT(DATA,_hash_table_size)=e; \    } \ -  + } \ +  \ +  \ + struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr, int hval) \ + { \ +  struct DATA *p; \ +  \ +  DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \ +  fatal("Hash table error!\n"); ) \ +  PIKE_CONCAT(num_,DATA)++; \ +  \ +  if(( PIKE_CONCAT(num_,DATA)>>2 ) >= \ +  PIKE_CONCAT(DATA,_hash_table_size)) \ +  { \ +  PIKE_CONCAT(DATA,_rehash)(); \ +  hval=(long)ptr; \ +  hval%=PIKE_CONCAT(DATA,_hash_table_size); \    } \    \ -  p=PIKE_CONCAT(alloc_,DATA)(); \ -  p->data=ptr; \ +  p=PIKE_CONCAT(alloc_,DATA)(); \ +  p->data=ptr; \    p->next=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \
186:   { \    struct DATA *p; \    int hval=(long)ptr; \ -  if(!PIKE_CONCAT(DATA,_hash_table)) return 0; \ +  if(!PIKE_CONCAT(DATA,_hash_table)) return 0; \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \    { \    PIKE_CONCAT(num_,DATA)--; \ -  if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \ +  if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \    PIKE_CONCAT(DATA,_hash_table)[hval]=p->next; \    PIKE_CONCAT(really_free_,DATA)(p); \    return 1; \
206:    PIKE_CONCAT(DATA,_hash_table_size)=hashprimes[my_log2(BSIZE)]; \    \    PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \ -  xalloc(sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ +  malloc(sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ +  if(!PIKE_CONCAT(DATA,_hash_table)) \ +  { \ +  fprintf(stderr,"Fatal: out of memory.\n"); \ +  exit(17); \ +  } \    MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \    sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \   } \
216:    PIKE_CONCAT3(free_all_,DATA,_blocks)(); \    free(PIKE_CONCAT(DATA,_hash_table)); \    PIKE_CONCAT(DATA,_hash_table)=0; \ - } \ + }