pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:16:   #include "pike_types.h"   #include "fsort.h"   #include "builtin_functions.h"   #include "pike_memory.h"   #include "gc.h"   #include "main.h"   #include "security.h"   #include "stuff.h"   #include "bignum.h"    - RCSID("$Id: array.c,v 1.66 2001/02/05 23:42:38 grubba Exp $"); + RCSID("$Id: array.c,v 1.67 2001/06/06 02:22:29 mast Exp $");      struct array empty_array=   {    1, /* Never free */   #ifdef PIKE_SECURITY    0,   #endif -  &empty_array, /* Next */ -  &empty_array, /* previous (circular) */ +  &weak_empty_array, /* Next */ +  &weak_shrink_empty_array, /* previous (circular) */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */   }; -  + struct array weak_empty_array= + { +  1, + #ifdef PIKE_SECURITY +  0, + #endif +  &weak_shrink_empty_array, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG + }; + struct array weak_shrink_empty_array= + { +  1, + #ifdef PIKE_SECURITY +  0, + #endif +  &empty_array, &weak_empty_array, 0, 0, 0, ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK + };            /* Allocate an array, this might be changed in the future to    * allocate linked lists or something    * NOTE: the new array have zero references    */      struct array *low_allocate_array(INT32 size,INT32 extra_space)   {
pike.git/src/array.c:106:       GC_FREE();   }      /*    * Free an array, call this when the array has zero references    */   void really_free_array(struct array *v)   {   #ifdef PIKE_DEBUG -  if(v == & empty_array) -  fatal("Tried to free the empty_array.\n"); +  if(v == & empty_array || v == &weak_empty_array || v == &weak_shrink_empty_array) +  fatal("Tried to free some *_empty_array.\n");   #endif      #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(v);   #endif       add_ref(v);    FREE_PROT(v);    free_svalues(ITEM(v), v->size, v->type_field);    v->refs--;    array_free_no_free(v);   }      void do_free_array(struct array *a)   {    free_array(a);   }    -  + struct array *array_set_flags(struct array *a, int flags) + { +  if (a->size) +  a->flags = flags; +  else { +  free_array(a); +  switch (flags) { +  case 0: +  add_ref(a = &empty_array); break; +  case ARRAY_WEAK_FLAG: +  add_ref(a = &weak_empty_array); break; +  case ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK: +  add_ref(a = &weak_shrink_empty_array); break; +  default: +  fatal("Invalid flags %x\n", flags); +  } +  } +  return a; + } +    /*    * Extract an svalue from an array    */   void array_index_no_free(struct svalue *s,struct array *v,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>=v->size)    fatal("Illegal index in low level index routine.\n");   #endif   
pike.git/src/array.c:1945:      void zap_all_arrays(void)   {    struct array *a,*next;       a=&empty_array;    do    {      #if defined(PIKE_DEBUG) && defined(DEBUG_MALLOC) -  if(verbose_debug_exit && a!=&empty_array) +  if(verbose_debug_exit && a!=&empty_array && +  a!=&weak_empty_array && a!=&weak_shrink_empty_array)    describe(a);   #endif       add_ref(a);    free_svalues(ITEM(a), a->size, a->type_field);    a->size=0;       if(!(next=a->next))    fatal("Null pointer in array list.\n");   
pike.git/src/array.c:1973:    free_array(a);    a=next;    } while (a != & empty_array);   }         void count_memory_in_arrays(INT32 *num_, INT32 *size_)   {    INT32 num=0, size=0;    struct array *m; -  for(m=empty_array.next;m!=&empty_array;m=m->next) +  for(m=empty_array.next;m!=&weak_empty_array;m=m->next)    {    num++;    size+=sizeof(struct array)+    sizeof(struct svalue) * (m->malloced_size - 1);    }    *num_=num;    *size_=size;   }      struct array *explode_array(struct array *a, struct array *b)