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.101 2001/01/03 21:35:13 grubba Exp $"); + RCSID("$Id: array.c,v 1.102 2001/06/06 02:22:35 mast Exp $");      PMOD_EXPORT 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 */   }; -  + PMOD_EXPORT struct array weak_empty_array= + { +  1, + #ifdef PIKE_SECURITY +  0, + #endif +  &weak_shrink_empty_array, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG + }; + PMOD_EXPORT 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 + };      struct array *gc_internal_array = &empty_array;   static struct array *gc_mark_array_pos = 0;         /* Allocate an array, this might be changed in the future to    * allocate linked lists or something    * NOTE: the new array have zero references    */   
pike.git/src/array.c:99:       GC_FREE(v);   }      /*    * Free an array, call this when the array has zero references    */   PMOD_EXPORT 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);   }      PMOD_EXPORT void do_free_array(struct array *a)   {    if (a)    free_array(a);   }    -  + PMOD_EXPORT 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    */   PMOD_EXPORT 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:1975:    else    debug_gc_check_svalues(ITEM(a), a->size, T_ARRAY, a);    }   }      void gc_mark_array_as_referenced(struct array *a)   {    int e;    if(gc_mark(a)) {   #ifdef PIKE_DEBUG -  if (a == &empty_array) fatal("Trying to gc mark empty_array.\n"); +  if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) +  fatal("Trying to gc mark some *_empty_array.\n");   #endif       if (a == gc_mark_array_pos)    gc_mark_array_pos = a->next;    if (a == gc_internal_array)    gc_internal_array = a->next;    else {    UNLINK_ARRAY(a);    LINK_ARRAY(a); /* Linked in first. */    }
pike.git/src/array.c:2042:    }    }    }   }      void real_gc_cycle_check_array(struct array *a, int weak)   {    GC_CYCLE_ENTER(a, weak) {    int e;   #ifdef PIKE_DEBUG -  if (a == &empty_array) fatal("Trying to gc cycle check empty_array.\n"); +  if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) +  fatal("Trying to gc cycle check some *_empty_array.\n");   #endif       if (a->type_field & BIT_COMPLEX)    {    if (a->flags & ARRAY_WEAK_FLAG) {    if (gc_cycle_check_weak_svalues(ITEM(a), a->size)) {   #ifdef PIKE_DEBUG    fatal("Didn't expect an svalue zapping now.\n");   #endif    }
pike.git/src/array.c:2104:    gc_check_array(a);    a=a->next;    } while (a != & empty_array);   }         void gc_mark_all_arrays(void)   {    gc_mark_array_pos = gc_internal_array;    gc_mark(&empty_array); +  gc_mark(&weak_empty_array); +  gc_mark(&weak_shrink_empty_array);    while (gc_mark_array_pos != &empty_array) {    struct array *a = gc_mark_array_pos;   #ifdef PIKE_DEBUG    if (!a) fatal("Null pointer in array list.\n");   #endif    gc_mark_array_pos = a->next;    if(gc_is_referenced(a))    gc_mark_array_as_referenced(a);    }   }
pike.git/src/array.c:2139:    gc_mark_array_pos = a->next;    gc_mark_array_as_referenced(a);    }    discard_queue(&gc_mark_queue);   }      void gc_free_all_unreferenced_arrays(void)   {    struct array *a,*next;    -  for (a = gc_internal_array; a != &empty_array; a = next) +  for (a = gc_internal_array; a != &weak_empty_array; a = next)    {   #ifdef PIKE_DEBUG    if (!a)    fatal("Null pointer in array list.\n");   #endif    if(gc_do_free(a))    {    /* Got an extra ref from gc_cycle_pop(). */    free_svalues(ITEM(a), a->size, a->type_field);    a->size=0;
pike.git/src/array.c:2187: Inside #if defined(PIKE_DEBUG)
  {    fprintf(stderr,"Location=%p Refs=%d, next=%p, prev=%p, "    "flags=0x%x, size=%d, malloced_size=%d%s\n",    a,    a->refs,    a->next,    a->prev,    a->flags,    a->size,    a->malloced_size, -  a == &empty_array ? " (the empty_array)" : ""); +  a == &empty_array ? " (the empty_array)" : +  a == &weak_empty_array ? " (the weak_empty_array)" : +  a == &weak_shrink_empty_array ? " (the weak_shrink_empty_array)" : +  "");    fprintf(stderr,"Type field = ");    debug_dump_type_field(a->type_field);    fprintf(stderr,"\n");    simple_describe_array(a);   }   #endif         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");       SET_NEXT_AND_FREE(a,free_array);    } 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;   }      PMOD_EXPORT struct array *explode_array(struct array *a, struct array *b)