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.145 2003/04/28 18:08:35 mast Exp $ + || $Id: array.c,v 1.146 2003/04/28 18:32:38 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.145 2003/04/28 18:08:35 mast Exp $"); + RCSID("$Id: array.c,v 1.146 2003/04/28 18:32:38 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:194: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(index<0 || index>=v->size)    Pike_fatal("Illegal index in low level index routine.\n");   #endif       add_ref(v);    assign_svalue(s, ITEM(v) + index);    free_array(v);   }    - /* Is destructive on data if it only has one ref. */ - PMOD_EXPORT struct array *array_column (struct array *data, struct svalue *index) + /* Is destructive on data if destructive is set and it only has one ref. */ + PMOD_EXPORT struct array *array_column (struct array *data, struct svalue *index, +  int destructive)   {    int e;    struct array *a;    TYPE_FIELD types = 0;       DECLARE_CYCLIC();       /* Optimization */ -  if(data->refs == 1) +  if(data->refs == 1 && destructive)    {    /* An array with one ref cannot possibly be cyclic */    struct svalue sval;    data->type_field = BIT_MIXED | BIT_UNFINISHED;    for(e=0;e<data->size;e++)    {    index_no_free(&sval, ITEM(data)+e, index);    types |= 1 << sval.type;    free_svalue(ITEM(data)+e);    move_svalue (ITEM(data) + e, &sval);
pike.git/src/array.c:268:    index_error(0,0,0,&tmp,ind,"Attempt to index the empty array with %d.\n", i);    }    }    array_index_no_free(s,a,i);    break;       case T_STRING:    {    /* Set the type afterwards to avoid a clobbered svalue in case    * array_column throws. */ -  s->u.array = array_column (a, ind); +  s->u.array = array_column (a, ind, 0);    s->type = T_ARRAY;    break;    }       default:    {    struct svalue tmp;    tmp.type=T_ARRAY;    tmp.u.array=a;    index_error(0,0,0,&tmp,ind,"Array index is neither int nor string.\n");
pike.git/src/array.c:1255:   /*    * 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.    * The differance between this routine and the one above is that this takes    * the index as an svalue.    */   PMOD_EXPORT union anything *array_get_item_ptr(struct array *a,    struct svalue *ind,    TYPE_T t)   { -  INT32 i; +  INT_TYPE i;    if(ind->type != T_INT)    Pike_error("Expected integer as array index, got %s.\n",    get_name_of_type (ind->type));    i=ind->u.integer;    if(i<0) i+=a->size;    if(i<0 || i>=a->size) {    if (a->size) { -  Pike_error("Index %d is out of array range 0 - %d.\n", i, a->size-1); +  Pike_error("Index %"PRINTPIKEINT"d is out of " +  "array range 0 - %"PRINTPTRDIFFT"d.\n", i, a->size-1);    } else { -  Pike_error("Attempt to index the empty array with %d.\n", i); +  Pike_error("Attempt to index the empty array with %"PRINTPIKEINT"d.\n", i);    }    }    return low_array_get_item_ptr(a,i,t);   }      /*    * organize an array of INT32 to specify how to zip two arrays together    * to maintain the order.    * the first item in this array is the size of the result    * the rest is n >= 0 for a[ n ]