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.142 2003/04/27 17:46:47 mast Exp $ + || $Id: array.c,v 1.143 2003/04/28 00:32:42 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.142 2003/04/27 17:46:47 mast Exp $"); + RCSID("$Id: array.c,v 1.143 2003/04/28 00:32:42 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, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */
pike.git/src/array.c:57:    &empty_array, &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;   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    -  +    /* Allocate an array, this might be changed in the future to    * allocate linked lists or something    * NOTE: the new array have zero references    */      PMOD_EXPORT struct array *low_allocate_array(ptrdiff_t size, ptrdiff_t extra_space)   {    struct array *v;    ptrdiff_t e;   
pike.git/src/array.c:82:    }       v=(struct array *)malloc(sizeof(struct array)+    (size+extra_space-1)*sizeof(struct svalue));    if(!v)    Pike_error("Couldn't allocate array, out of memory.\n");       GC_ALLOC(v);       +  if (size)    /* for now, we don't know what will go in here */ -  v->type_field=BIT_MIXED | BIT_UNFINISHED; +  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);       for(e=0;e<v->size;e++)    {
pike.git/src/array.c:1164:   /* Maybe I should have a 'clean' flag for this computation */   PMOD_EXPORT void array_fix_type_field(struct array *v)   {    int e;    TYPE_FIELD t;       t=0;       if(v->flags & ARRAY_LVALUE)    { -  v->type_field=BIT_MIXED; +  v->type_field=BIT_MIXED|BIT_UNFINISHED;    return;    }    -  for(e=0; e<v->size; e++) t |= 1 << ITEM(v)[e].type; +  for(e=0; e<v->size; e++) { +  check_svalue (ITEM(v) + e); +  t |= 1 << ITEM(v)[e].type; +  }      #ifdef PIKE_DEBUG    if(t & ~(v->type_field))    {    describe(v);    Pike_fatal("Type field out of order!\n");    }   #endif    v->type_field = t;   }
pike.git/src/array.c:1192: Inside #if defined(PIKE_DEBUG)
  void array_check_type_field(struct array *v)   {    int e;    TYPE_FIELD t;       t=0;       if(v->flags & ARRAY_LVALUE)    return;    + #ifdef TRACE_UNFINISHED_TYPE_FIELDS +  if (v->type_field & BIT_UNFINISHED && !accept_unfinished_type_fields) { +  fputs ("Array got an unfinished type field.\n", stderr); +  describe_something (v, T_ARRAY, 2, 2, 0, NULL); +  } + #endif +     for(e=0; e<v->size; e++)    {    if(ITEM(v)[e].type > MAX_TYPE)    Pike_fatal("Type is out of range.\n");       t |= 1 << ITEM(v)[e].type;    }       if(t & ~(v->type_field))    {
pike.git/src/array.c:1966: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    default: Pike_fatal("Illegal shift.\n");   #endif    }       while((tmp = f(mojt.data, s, (end-s)>> str->size_shift)))    {    if(ret->size == ret->malloced_size)    {    e=ret->size; +  ACCEPT_UNFINISHED_TYPE_FIELDS {    ret=resize_array(ret, e * 2); -  +  } END_ACCEPT_UNFINISHED_TYPE_FIELDS;    ret->size=e;    }       ITEM(ret)[ret->size].u.string=string_slice(str,    (s-str->str)>>str->size_shift,    (tmp-s)>>str->size_shift);    ITEM(ret)[ret->size].type=T_STRING;    ret->size++;       s=tmp+(del->len << str->size_shift);    }       if(ret->size == ret->malloced_size)    {    e=ret->size; -  +  ACCEPT_UNFINISHED_TYPE_FIELDS {    ret=resize_array(ret, e * 2); -  +  } END_ACCEPT_UNFINISHED_TYPE_FIELDS;    ret->size=e;    }       ITEM(ret)[ret->size].u.string=string_slice(str,    (s-str->str)>>str->size_shift,    (end-s)>>str->size_shift);       ITEM(ret)[ret->size].type=T_STRING;    ret->size++;    mojt.vtab->freeme(mojt.data);
pike.git/src/array.c:2135:    *tmp1 = swap;    }       add_ref(a);    return a;    }       ret=allocate_array_no_init(a->size,0);    for(e=0;e<a->size;e++)    assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+a->size+~e); +  ret->type_field = a->type_field;    return ret;   }      void array_replace(struct array *a,    struct svalue *from,    struct svalue *to)   {    ptrdiff_t i = -1;       while((i=array_search(a,from,i+1)) >= 0) array_set_index(a,i,to);