pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: array.c,v 1.153 2004/03/09 15:48:51 nilsson Exp $ + || $Id: array.c,v 1.154 2004/03/15 22:23:14 mast Exp $   */      #include "global.h"   #include "svalue.h"   #include "array.h"   #include "object.h"   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "opcodes.h"
pike.git/src/array.c:19:   #include "builtin_functions.h"   #include "pike_memory.h"   #include "gc.h"   #include "main.h"   #include "security.h"   #include "stuff.h"   #include "bignum.h"   #include "cyclic.h"   #include "multiset.h"    - RCSID("$Id: array.c,v 1.153 2004/03/09 15:48:51 nilsson Exp $"); + RCSID("$Id: array.c,v 1.154 2004/03/15 22:23:14 mast Exp $");      PMOD_EXPORT struct array empty_array=   {    PIKE_CONSTANT_MEMOBJ_INIT(1), /* Never free */    &weak_empty_array, /* Next */ -  &weak_shrink_empty_array, /* previous (circular) */ +  0, /* previous */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */    empty_array.real_item, /* Initialize the item pointer. */   #ifdef HAVE_UNION_INIT    {{0, 0, {0}}}, /* Only to avoid warnings. */   #endif   };   PMOD_EXPORT struct array weak_empty_array=
pike.git/src/array.c:47:    PIKE_CONSTANT_MEMOBJ_INIT(1),    &weak_shrink_empty_array, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG,    weak_empty_array.real_item,   #ifdef HAVE_UNION_INIT    {{0, 0, {0}}}, /* Only to avoid warnings. */   #endif   };   PMOD_EXPORT struct array weak_shrink_empty_array=   {    PIKE_CONSTANT_MEMOBJ_INIT(1), -  &empty_array, &weak_empty_array, 0, 0, 0, ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK, +  0, &weak_empty_array, 0, 0, 0, ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK,    weak_shrink_empty_array.real_item,   #ifdef HAVE_UNION_INIT    {{0, 0, {0}}}, /* Only to avoid warnings. */   #endif   };    - struct array *gc_internal_array = &empty_array; + struct array *first_array = &empty_array; + struct array *gc_internal_array = 0;   static struct array *gc_mark_array_pos = 0;      #ifdef TRACE_UNFINISHED_TYPE_FIELDS   PMOD_EXPORT int accept_unfinished_type_fields = 0;   PMOD_EXPORT void dont_accept_unfinished_type_fields (void *orig)   {    accept_unfinished_type_fields = (int) orig;   }   #endif   
pike.git/src/array.c:101:    /* for now, we don't know what will go in here */    v->type_field = BIT_MIXED | BIT_UNFINISHED;    else    v->type_field = 0;    v->flags=0;       v->malloced_size = DO_NOT_WARN((INT32)(size + extra_space));    v->item=v->real_item;    v->size = DO_NOT_WARN((INT32)size);    INIT_PIKE_MEMOBJ(v); -  LINK_ARRAY(v); +  DOUBLELINK (first_array, v);       for(e=0;e<v->size;e++)    {    ITEM(v)[e].type=T_INT;    ITEM(v)[e].subtype=NUMBER_NUMBER;    ITEM(v)[e].u.integer=0;    }       return v;   }      /*    * Free an array without freeing the values inside it    */   static void array_free_no_free(struct array *v)   { -  UNLINK_ARRAY(v); +  DOUBLEUNLINK (first_array, v);       free((char *)v);       GC_FREE(v);   }      /*    * Free an array, call this when the array has zero references    */   PMOD_EXPORT void really_free_array(struct array *v)
pike.git/src/array.c:2209:    ptrdiff_t i = -1;       while((i=array_search(a,from,i+1)) >= 0) array_set_index(a,i,to);   }      #ifdef PIKE_DEBUG   PMOD_EXPORT void check_array(struct array *a)   {    INT32 e;    -  if(a->next->prev != a) -  Pike_fatal("Array check: a->next->prev != a\n"); +  if(a->next && a->next->prev != a) +  Pike_fatal("array->next->prev != array.\n");    -  +  if(a->prev) +  { +  if(a->prev->next != a) +  Pike_fatal("array->prev->next != array.\n"); +  }else{ +  if(first_array != a) +  Pike_fatal("array->prev == 0 but first_array != array.\n"); +  } +     if(a->size > a->malloced_size)    Pike_fatal("Array is larger than malloced block!\n");       if(a->size < 0)    Pike_fatal("Array size is negative!\n");       if(a->malloced_size < 0)    Pike_fatal("Array malloced size is negative!\n");       if(a->item < a->real_item)
pike.git/src/array.c:2245: Inside #if defined(PIKE_DEBUG)
   if(! ( (1 << ITEM(a)[e].type) & (a->type_field) ) && ITEM(a)[e].type<16)    Pike_fatal("Type field lies.\n");       check_svalue(ITEM(a)+e);    }   }      void check_all_arrays(void)   {    struct array *a; -  -  a=&empty_array; -  do -  { +  for (a = first_array; a; a = a->next)    check_array(a); -  -  a=a->next; -  if(!a) -  Pike_fatal("Null pointer in array list.\n"); -  } while (a != & empty_array); +    }   #endif /* PIKE_DEBUG */         static void gc_check_array(struct array *a)   {    GC_ENTER (a, T_ARRAY) {    if(a->type_field & BIT_COMPLEX)    {    if (a->flags & ARRAY_WEAK_FLAG) {
pike.git/src/array.c:2278:    else    gc_check_svalues(ITEM(a), a->size);    }    } GC_LEAVE;   }      void gc_mark_array_as_referenced(struct array *a)   {    if(gc_mark(a))    GC_ENTER (a, T_ARRAY) { - #ifdef PIKE_DEBUG -  if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) -  Pike_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. */ +  DOUBLEUNLINK (first_array, a); +  DOUBLELINK (first_array, a); /* Linked in first. */    }       if (a->type_field & BIT_COMPLEX)    {    if (a->flags & ARRAY_WEAK_FLAG) {    int e;    TYPE_FIELD t;       if(a->flags & ARRAY_WEAK_SHRINK) {    int d=0;
pike.git/src/array.c:2376: Inside #if defined(PIKE_DEBUG)
   else    gc_assert_checked_as_nonweak(a);   #endif    }    } GC_CYCLE_LEAVE;   }      unsigned gc_touch_all_arrays(void)   {    unsigned n = 0; -  struct array *a = &empty_array; -  do { +  struct array *a; +  if (!first_array || first_array->prev) +  Pike_fatal ("error in array link list.\n"); +  for (a = first_array; a; a = a->next) {    debug_gc_touch(a);    n++; -  if (!a->next || a->next->prev != a) +  if (a->next && a->next->prev != a)    Pike_fatal("Error in array link list.\n"); -  a=a->next; -  } while (a != &empty_array); +  }    return n;   }      void gc_check_all_arrays(void)   {    struct array *a; -  a=&empty_array; -  do -  { +  for (a = first_array; a; a = a->next) {   #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(a);   #endif    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) { +  while (gc_mark_array_pos) {    struct array *a = gc_mark_array_pos; - #ifdef PIKE_DEBUG -  if (!a) Pike_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);    }   }      void gc_cycle_check_all_arrays(void)   {    struct array *a; -  for (a = gc_internal_array; a != &empty_array; a = a->next) { +  for (a = gc_internal_array; a; a = a->next) {    real_gc_cycle_check_array(a, 0);    gc_cycle_run_queue();    }   }      void gc_zap_ext_weak_refs_in_arrays(void)   { -  gc_mark_array_pos = empty_array.next; +  gc_mark_array_pos = first_array;    while (gc_mark_array_pos != gc_internal_array && gc_ext_weak_refs) {    struct array *a = gc_mark_array_pos;    gc_mark_array_pos = a->next;    gc_mark_array_as_referenced(a);    }    gc_mark_discard_queue();   }      size_t gc_free_all_unreferenced_arrays(void)   {    struct array *a,*next;    size_t unreferenced = 0;    -  for (a = gc_internal_array; a != &weak_empty_array; a = next) +  for (a = gc_internal_array; a; a = next)    {   #ifdef PIKE_DEBUG    if (!a)    Pike_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:2511: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr,"\n");    simple_describe_array(a);   }   #endif         void count_memory_in_arrays(INT32 *num_, INT32 *size_)   {    INT32 num=0, size=0;    struct array *m; -  for(m=empty_array.next;m!=&weak_empty_array;m=m->next) +  for(m=first_array;m;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)