pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:17:   #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"   #include "cyclic.h"    - RCSID("$Id: array.c,v 1.128 2002/05/31 22:41:19 nilsson Exp $"); + RCSID("$Id: array.c,v 1.129 2002/08/15 14:49:18 marcus 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:119:    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) -  fatal("Tried to free some *_empty_array.\n"); +  Pike_fatal("Tried to free some *_empty_array.\n");    if (v->refs) -  fatal("Freeing array with %d refs.\n", v->refs); +  Pike_fatal("Freeing array with %d refs.\n", v->refs);   #endif      #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(v);   #endif       add_ref(v);    EXIT_PIKE_MEMOBJ(v);    free_svalues(ITEM(v), v->size, v->type_field);    v->refs--;
pike.git/src/array.c:155:    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); +  Pike_fatal("Invalid flags %x\n", flags);    }    }    return a;   }         /*    * Extract an svalue from an array    */   PMOD_EXPORT void array_index(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"); +  Pike_fatal("Illegal index in low level index routine.\n");   #endif       add_ref(v);    assign_svalue(s, ITEM(v) + index);    free_array(v);   }      PMOD_EXPORT void simple_array_index_no_free(struct svalue *s,    struct array *a,struct svalue *ind)   {
pike.git/src/array.c:228:    }   }      /*    * Extract an svalue from an array    */   PMOD_EXPORT void array_free_index(struct array *v,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>=v->size) -  fatal("Illegal index in low level free index routine.\n"); +  Pike_fatal("Illegal index in low level free index routine.\n");   #endif       free_svalue(ITEM(v) + index);   }         PMOD_EXPORT void simple_set_index(struct array *a,struct svalue *ind,struct svalue *s)   {    INT32 i;    switch (ind->type) {
pike.git/src/array.c:283:    }   }      /*    * Insert an svalue into an array, grow the array if nessesary    */   PMOD_EXPORT struct array *array_insert(struct array *v,struct svalue *s,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>v->size) -  fatal("Illegal index in low level insert routine.\n"); +  Pike_fatal("Illegal index in low level insert routine.\n");   #endif       /* Can we fit it into the existing block? */    if(v->refs<=1 && v->malloced_size > v->size)    {    MEMMOVE((char *)(ITEM(v)+index+1),    (char *)(ITEM(v)+index),    (v->size-index) * sizeof(struct svalue));    ITEM(v)[index].type=T_INT;   #ifdef __CHECKER__
pike.git/src/array.c:371:      /*    * Shrink an array destructively    */   PMOD_EXPORT struct array *array_shrink(struct array *v, ptrdiff_t size)   {    struct array *a;      #ifdef PIKE_DEBUG    if(v->refs>2) /* Odd, but has to be two */ -  fatal("Array shrink on array with many references.\n"); +  Pike_fatal("Array shrink on array with many references.\n");       if(size > v->size) -  fatal("Illegal argument to array_shrink.\n"); +  Pike_fatal("Illegal argument to array_shrink.\n");   #endif       if(size*2 < v->malloced_size + 4) /* Should we realloc it? */    {    a=allocate_array_no_init(size,0);    a->type_field = v->type_field;       free_svalues(ITEM(v) + size, v->size - size, v->type_field);    MEMCPY(ITEM(a), ITEM(v), size*sizeof(struct svalue));    v->size=0;
pike.git/src/array.c:403:      /*    * Remove an index from an array and shrink the array    */   PMOD_EXPORT struct array *array_remove(struct array *v,INT32 index)   {    struct array *a;      #ifdef PIKE_DEBUG    if(index<0 || index >= v->size) -  fatal("Illegal argument to array_remove.\n"); +  Pike_fatal("Illegal argument to array_remove.\n");   #endif       array_free_index(v, index);    if(v->size!=1 &&    v->size*2 + 4 < v->malloced_size ) /* Should we realloc it? */    {    a=allocate_array_no_init(v->size-1, 0);    a->type_field = v->type_field;       if(index>0)
pike.git/src/array.c:445:    * Search for in svalue in an array.    * return the index if found, -1 otherwise    */   PMOD_EXPORT ptrdiff_t array_search(struct array *v, struct svalue *s,    ptrdiff_t start)   {    ptrdiff_t e;      #ifdef PIKE_DEBUG    if(start<0) -  fatal("Start of find_index is less than zero.\n"); +  Pike_fatal("Start of find_index is less than zero.\n");   #endif       check_destructed(s);      #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(v);   #endif    /* Why search for something that is not there?    * however, we must explicitly check for searches    * for destructed objects/functions
pike.git/src/array.c:489:    * Slice a pice of an array (nondestructively)    * return an array consisting of v[start..end-1]    */   PMOD_EXPORT struct array *slice_array(struct array *v, ptrdiff_t start,    ptrdiff_t end)   {    struct array *a;      #ifdef PIKE_DEBUG    if(start > end || end>v->size || start<0) -  fatal("Illegal arguments to slice_array()\n"); +  Pike_fatal("Illegal arguments to slice_array()\n");       if(d_flag > 1) array_check_type_field(v);   #endif      #if 1    if(v->refs==1) /* Can we use the same array? */    {    if((end-start) &&    (end-start)*2 >    v->malloced_size+4+(v->item-v->real_item) ) /* don't waste too much memory */
pike.git/src/array.c:536:    * return an array consisting of v[start..end-1]    */   PMOD_EXPORT struct array *friendly_slice_array(struct array *v,    ptrdiff_t start,    ptrdiff_t end)   {    struct array *a;      #ifdef PIKE_DEBUG    if(start > end || end>v->size || start<0) -  fatal("Illegal arguments to slice_array()\n"); +  Pike_fatal("Illegal arguments to slice_array()\n");       if(d_flag > 1) array_check_type_field(v);   #endif       a=allocate_array_no_init(end-start,0);    a->type_field = v->type_field;       assign_svalues_no_free(ITEM(a), ITEM(v)+start, end-start, v->type_field);       return a;
pike.git/src/array.c:1022:    v->type_field=BIT_MIXED;    return;    }       for(e=0; e<v->size; e++) t |= 1 << ITEM(v)[e].type;      #ifdef PIKE_DEBUG    if(t & ~(v->type_field))    {    describe(v); -  fatal("Type field out of order!\n"); +  Pike_fatal("Type field out of order!\n");    }   #endif    v->type_field = t;   }      #ifdef PIKE_DEBUG   /* Maybe I should have a 'clean' flag for this computation */   void array_check_type_field(struct array *v)   {    int e;    TYPE_FIELD t;       t=0;       if(v->flags & ARRAY_LVALUE)    return;       for(e=0; e<v->size; e++)    {    if(ITEM(v)[e].type > MAX_TYPE) -  fatal("Type is out of range.\n"); +  Pike_fatal("Type is out of range.\n");       t |= 1 << ITEM(v)[e].type;    }       if(t & ~(v->type_field))    {    describe(v); -  fatal("Type field out of order!\n"); +  Pike_fatal("Type field out of order!\n");    }   }   #endif      PMOD_EXPORT struct array *compact_array(struct array *v) { return v; }      /*    * Get a pointer to the 'union anything' specified IF it is of the specified    * type. The 'union anything' may be changed, but not the type.    */
pike.git/src/array.c:1808:    del->len,    str->len,    del);       switch(str->size_shift)    {    case 0: f=(explode_searchfunc)mojt.vtab->func0; break;    case 1: f=(explode_searchfunc)mojt.vtab->func1; break;    case 2: f=(explode_searchfunc)mojt.vtab->func2; break;   #ifdef PIKE_DEBUG -  default: fatal("Illegal shift.\n"); +  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;    ret=resize_array(ret, e * 2);    ret->size=e;
pike.git/src/array.c:2004:       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) -  fatal("Array check: a->next->prev != a\n"); +  Pike_fatal("Array check: a->next->prev != a\n");       if(a->size > a->malloced_size) -  fatal("Array is larger than malloced block!\n"); +  Pike_fatal("Array is larger than malloced block!\n");       if(a->size < 0) -  fatal("Array size is negative!\n"); +  Pike_fatal("Array size is negative!\n");       if(a->malloced_size < 0) -  fatal("Array malloced size is negative!\n"); +  Pike_fatal("Array malloced size is negative!\n");       if(a->item < a->real_item)    {   #ifdef DEBUG_MALLOC    describe(a);   #endif -  fatal("Array item pointer is too small!\n"); +  Pike_fatal("Array item pointer is too small!\n");    }       if(a->refs <=0 ) -  fatal("Array has zero refs.\n"); +  Pike_fatal("Array has zero refs.\n");          for(e=0;e<a->size;e++)    {    if(! ( (1 << ITEM(a)[e].type) & (a->type_field) ) && ITEM(a)[e].type<16) -  fatal("Type field lies.\n"); +  Pike_fatal("Type field lies.\n");       check_svalue(ITEM(a)+e);    }   }      void check_all_arrays(void)   {    struct array *a;       a=&empty_array;    do    {    check_array(a);       a=a->next;    if(!a) -  fatal("Null pointer in array list.\n"); +  Pike_fatal("Null pointer in array list.\n");    } while (a != & empty_array);   }   #endif /* PIKE_DEBUG */         static void gc_check_array(struct array *a)   {    if(a->type_field & BIT_COMPLEX)    {    if (a->flags & ARRAY_WEAK_FLAG) {
pike.git/src/array.c:2071:    else    debug_gc_check_svalues(ITEM(a), a->size, T_ARRAY, a);    }   }      void gc_mark_array_as_referenced(struct array *a)   {    if(gc_mark(a)) {   #ifdef PIKE_DEBUG    if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) -  fatal("Trying to gc mark some *_empty_array.\n"); +  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. */    }
pike.git/src/array.c:2093:    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) -  fatal("Got %d refs to weak shrink array " +  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;    }
pike.git/src/array.c:2138:    }    }    }   }      void real_gc_cycle_check_array(struct array *a, int weak)   {    GC_CYCLE_ENTER(a, weak) {   #ifdef PIKE_DEBUG    if (a == &empty_array || a == &weak_empty_array || a == &weak_shrink_empty_array) -  fatal("Trying to gc cycle check some *_empty_array.\n"); +  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    * destructed objects are removed. */
pike.git/src/array.c:2173: Inside #if defined(PIKE_DEBUG)
     #ifdef PIKE_DEBUG   unsigned gc_touch_all_arrays(void)   {    unsigned n = 0;    struct array *a = &empty_array;    do {    debug_gc_touch(a);    n++;    if (!a->next || a->next->prev != a) -  fatal("Error in array link list.\n"); +  Pike_fatal("Error in array link list.\n");    a=a->next;    } while (a != &empty_array);    return n;   }   #endif      void gc_check_all_arrays(void)   {    struct array *a;    a=&empty_array;
pike.git/src/array.c:2204:      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"); +  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;
pike.git/src/array.c:2240:   }      void gc_free_all_unreferenced_arrays(void)   {    struct 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"); +  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;       gc_free_extra_ref(a);    SET_NEXT_AND_FREE(a, free_array);    }
pike.git/src/array.c:2421:    }    ret->type_field|=ITEM(a)[e].u.array->type_field;    assign_svalues_no_free(ITEM(ret)+size,    ITEM(ITEM(a)[e].u.array),    ITEM(a)[e].u.array->size,    ITEM(a)[e].u.array->type_field);    size+=ITEM(a)[e].u.array->size;    }   #ifdef PIKE_DEBUG    if(size != ret->size) -  fatal("Implode_array failed miserably (%d != %d)\n", size, ret->size); +  Pike_fatal("Implode_array failed miserably (%d != %d)\n", size, ret->size);   #endif    return ret;   }