Branch: Tag:

1996-12-05

1996-12-05 00:47:58 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

fixed a small memory leak and added _memory_usage

Rev: bin/test_pike.pike:1.3
Rev: src/ChangeLog:1.32
Rev: src/array.c:1.4
Rev: src/array.h:1.2
Rev: src/builtin_functions.c:1.16
Rev: src/builtin_functions.h:1.3
Rev: src/callback.c:1.4
Rev: src/callback.h:1.3
Rev: src/constants.c:1.4
Rev: src/constants.h:1.2
Rev: src/language.yacc:1.15
Rev: src/las.c:1.10
Rev: src/las.h:1.3
Rev: src/mapping.c:1.8
Rev: src/mapping.h:1.2
Rev: src/modules/call_out/call_out.c:1.4
Rev: src/modules/pipe/pipe.c:1.7
Rev: src/multiset.c:1.2
Rev: src/multiset.h:1.2
Rev: src/object.c:1.6
Rev: src/object.h:1.4
Rev: src/program.c:1.11
Rev: src/program.h:1.4
Rev: src/stralloc.c:1.8
Rev: src/stralloc.h:1.4

34:   static struct callback *free_callbacks =0;      #ifdef DEBUG + extern int d_flag; +    static void check_callback_chain(struct callback_list *lst)   { -  int len=0; +  int e,len=0; +  struct callback_block *tmp;    struct callback *foo; -  +  if(d_flag) +  {    for(foo=lst->callbacks;foo;foo=foo->next)    {    if((len & 1024)==1023)
52: Inside #if defined(DEBUG)
   }    len++;    } +  +  for(tmp=callback_chunks;tmp;tmp=tmp->next) +  { +  for(e=0;e<CALLBACK_CHUNK;e++) +  { +  int d; +  struct callback_block *tmp2; +  +  if(tmp->callbacks[e].free_func == (callback_func)remove_callback) +  { +  for(foo=free_callbacks;foo;foo=foo->next) +  if(foo==tmp->callbacks+e) +  break; +  +  if(!foo) +  fatal("Lost track of a struct callback!\n");    } -  +  +  if(tmp->callbacks[e].next) +  { +  d=CALLBACK_CHUNK; +  for(tmp2=callback_chunks;tmp2;tmp2=tmp2->next) +  { +  for(d=0;d<CALLBACK_CHUNK;d++) +  { +  if(tmp2->callbacks+d == tmp->callbacks[e].next) +  break; +  +  if(d < CALLBACK_CHUNK) break; +  } +  } +  +  if(d == CALLBACK_CHUNK) +  fatal("Callback next pointer pointing to Z'ha'dum\n"); +  } +  } +  } +  } + }   #else   #define check_callback_chain(X)   #endif
61:   static struct callback *get_free_callback()   {    struct callback *tmp; -  if(!(tmp=free_callbacks)) +  if(!free_callbacks)    {    int e;    struct callback_block *tmp2;
69:    tmp2->next=callback_chunks;    callback_chunks=tmp2;    -  for(e=0;e<(int)sizeof(CALLBACK_CHUNK);e++) +  for(e=0;e<CALLBACK_CHUNK;e++)    { -  tmp2->callbacks[e].next=tmp; -  tmp=tmp2->callbacks+e; +  tmp2->callbacks[e].next=free_callbacks; +  tmp2->callbacks[e].free_func=(callback_func)remove_callback; +  free_callbacks=tmp2->callbacks+e;    }    } -  +  tmp=free_callbacks;    free_callbacks=tmp->next;    return tmp;   }
103:       if(!l->call)    { +  if(l->free_func) +  l->free_func(l, l->arg, 0); +     *ptr=l->next;    l->next=free_callbacks;    free_callbacks=l; -  + #ifdef DEBUG +  l->free_func=(callback_func)remove_callback; + #endif    }else{    ptr=& l->next;    }
123:    l=get_free_callback();    l->call=call;    l->arg=arg; +  l->free_func=free_func;       l->next=lst->callbacks;    lst->callbacks=l;
138:   void *remove_callback(struct callback *l)   {    l->call=0; +  l->free_func=0;    return l->arg;   }   
149:    ptr=& lst->callbacks;    while(l=*ptr)    { -  if(l->arg && l->free_func) +  if(l->free_func)    l->free_func(l, l->arg, 0);    *ptr=l->next;    l->next=free_callbacks;    free_callbacks=l; -  + #ifdef DEBUG +  l->free_func=(callback_func)remove_callback; + #endif    }   }   
167:    }    free_callbacks=0;   } +  +  + void count_memory_in_callbacks(INT32 *num_, INT32 *size_) + { +  INT32 num=0, size=0; +  struct callback_block *tmp; +  struct callback *tmp2; +  for(tmp=callback_chunks;tmp;tmp=tmp->next) +  { +  num+=CALLBACK_CHUNK; +  size+=sizeof(struct callback_block); +  } +  for(tmp2=free_callbacks;tmp2;tmp2=tmp2->next) num--; +  *num_=num; +  *size_=size; + }