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.169 2004/09/18 20:50:48 nilsson Exp $ + || $Id: array.c,v 1.170 2004/09/22 13:40:27 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:37:    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_CONSTANT_MEMOBJ_INIT(1), -  &weak_shrink_empty_array, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG, +  0, &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), -  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 *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;
pike.git/src/array.c:138:       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 || v == &weak_empty_array || v == &weak_shrink_empty_array) +  if(v == & empty_array || v == &weak_empty_array)    Pike_fatal("Tried to free some *_empty_array.\n");    if (v->refs) {   #ifdef DEBUG_MALLOC    describe_something(v, T_ARRAY, 0,2,0, NULL);   #endif    Pike_fatal("Freeing array with %d refs.\n", v->refs);    }   #endif      #ifdef PIKE_DEBUG
pike.git/src/array.c:176:   {    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:    Pike_fatal("Invalid flags %x\n", flags);    }    }    return a;   }         /*    * Extract an svalue from an array
pike.git/src/array.c:2163:    check_array_for_destruct(a);    check_stack(120 + args + 1);       /* FIXME: Ought to use a better key on the arguments below. */    if (!(cycl = (struct array *)BEGIN_CYCLIC(a, args))) {    BEGIN_AGGREGATE_ARRAY(a->size) {    SET_CYCLIC_RET(Pike_sp[-1].u.array);    for (e=0;e<a->size;e++) {    assign_svalues_no_free(Pike_sp, argp, args, BIT_MIXED);    Pike_sp+=args; +  /* FIXME: Don't throw apply errors from apply_svalue here. */    apply_svalue(ITEM(a)+e,args);    new_types |= 1 << Pike_sp[-1].type;    DO_AGGREGATE_ARRAY(120);    }    }    END_AGGREGATE_ARRAY;       Pike_sp[-1].u.array->type_field = new_types;   #ifdef PIKE_DEBUG    array_check_type_field(Pike_sp[-1].u.array);
pike.git/src/array.c:2309:    if (a == gc_internal_array)    gc_internal_array = a->next;    else {    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; - #ifdef PIKE_DEBUG -  if (a->refs != 1) -  Pike_fatal("Got %d refs to weak shrink array " -  "which we'd like to change the size on.\n", a->refs); - #endif -  t = 0; -  for(e=0;e<a->size;e++) -  if (!gc_mark_weak_svalues(a->item+e, 1)) { -  a->item[d++]=a->item[e]; -  t |= 1 << a->item[e].type; -  } -  a->size=d; -  } -  else +     if (!(t = gc_mark_weak_svalues(a->item, a->size)))    t = a->type_field;       /* Ugly, but we are not allowed to change type_field    * at the same time as the array is being built...    * Actually we just need better primitives for building arrays.    */    if(!(a->type_field & BIT_UNFINISHED) || a->refs!=1)    a->type_field = t;    else
pike.git/src/array.c:2361:    }    }    } GC_LEAVE;   }      void real_gc_cycle_check_array(struct array *a, int weak)   {    GC_CYCLE_ENTER(a, T_ARRAY, weak) {   #ifdef PIKE_DEBUG    if (!gc_destruct_everything && -  (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array)) +  (a == &empty_array || a == &weak_empty_array))    Pike_fatal("Trying to gc cycle check some *_empty_array.\n");   #endif       if (a->type_field & BIT_COMPLEX)    {    TYPE_FIELD t = a->flags & ARRAY_WEAK_FLAG ?    gc_cycle_check_weak_svalues(ITEM(a), a->size) :    gc_cycle_check_svalues(ITEM(a), a->size);    if (t) {    /* In the weak case we should only get here if references to
pike.git/src/array.c:2504: Inside #if defined(PIKE_DEBUG)
   "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 == &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 count_memory_in_arrays(INT32 *num_, INT32 *size_)