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.140 2003/04/26 16:22:26 mast Exp $ + || $Id: array.c,v 1.141 2003/04/27 16:17:33 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.140 2003/04/26 16:22:26 mast Exp $"); + RCSID("$Id: array.c,v 1.141 2003/04/27 16:17:33 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:183: 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) + { +  int e; +  struct array *a; +  TYPE_FIELD types = 0; +  +  DECLARE_CYCLIC(); +  +  /* Optimization */ +  if(data->refs == 1) +  { +  /* 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); +  } +  data->type_field = types; +  return data; +  } +  +  if((a=(struct array *)BEGIN_CYCLIC(data,0))) +  { +  add_ref(a); +  }else{ +  push_array(a=allocate_array(data->size)); +  SET_CYCLIC_RET(a); +  +  for(e=0;e<a->size;e++) { +  index_no_free(ITEM(a)+e, ITEM(data)+e, index); +  types |= 1 << ITEM(a)[e].type; +  } +  a->type_field = types; +  +  dmalloc_touch_svalue(Pike_sp-1); +  Pike_sp--; +  } +  END_CYCLIC(); +  +  return a; + } +    PMOD_EXPORT void simple_array_index_no_free(struct svalue *s,    struct array *a,struct svalue *ind)   {    INT32 i;    switch(ind->type)    {    case T_INT:    i=ind->u.integer;    if(i<0) i+=a->size;    if(i<0 || i>=a->size) {
pike.git/src/array.c:207:    index_error(0,0,0,&tmp,ind,"Index %d is out of array range 0 - %d.\n", i, a->size-1);    } else {    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:    { -  check_stack(4); -  ref_push_array(a); -  assign_svalue_no_free(Pike_sp++,ind); -  f_column(2); -  Pike_sp--; -  *s = *Pike_sp; -  dmalloc_touch_svalue(Pike_sp); +  s->type = T_ARRAY; +  s->u.array = array_column (a, ind);    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:1854:    my_putchar('\n');    for(e=2; e<indent; e++) my_putchar(' ');    my_strcat("})");   }      PMOD_EXPORT struct array *aggregate_array(INT32 args)   {    struct array *a;       a=allocate_array_no_init(args,0); +  if (args) {    MEMCPY((char *)ITEM(a),(char *)(Pike_sp-args),args*sizeof(struct svalue)); -  a->type_field=BIT_MIXED; +  array_fix_type_field (a);    Pike_sp-=args;    DO_IF_DMALLOC(while(args--) dmalloc_touch_svalue(Pike_sp + args)); -  +  }    return a;   }      PMOD_EXPORT struct array *append_array(struct array *a, struct svalue *s)   {    a=resize_array(a,a->size+1);    array_set_index(a, a->size-1, s);    return a;   }