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.210 2008/06/23 16:05:02 mast Exp $ + || $Id: array.c,v 1.211 2008/07/01 09:36:28 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:522:    struct array *a;      #ifdef PIKE_DEBUG    if(v->refs>2) /* Odd, but has to be two */    Pike_fatal("Array shrink on array with many references.\n");       if(size > v->size)    Pike_fatal("Illegal argument to array_shrink.\n");   #endif    -  if (size == v->size) return v; -  +  /* Ensure that one of the empty arrays are returned if size is zero. */    if( !size )    { -  free_array(v); -  /* FIXME: What about weak markers etc? */ -  add_ref(&empty_array); -  return &empty_array; +  struct array *e = (v->flags & ARRAY_WEAK_FLAG ? +  &weak_empty_array : &empty_array); +  if (e != v) { +  free_array (v); +  add_ref (e);    } -  +  return e; +  }    -  +  if (size == v->size) return v; +     /* Free items outside the new array. */    free_svalues(ITEM(v) + size, v->size - size, v->type_field);    v->size=size;       if(size*4 < v->malloced_size + 4) /* Should we realloc it? */    {    a = array_set_flags(allocate_array_no_init(size, 0), v->flags);    if (a->size) {    a->type_field = v->type_field;    }
pike.git/src/array.c:561:      /**    * Resize an array destructively.    */   PMOD_EXPORT struct array *resize_array(struct array *a, INT32 size)   {   #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(a);   #endif    +  /* Ensure that one of the empty arrays are returned if size is zero. */ +  if (!size) return array_shrink (a, size); +     if(a->size == size) return a;    if(size > a->size)    {    /* We should grow the array */       if((a->malloced_size >= size) &&    ((a->item + size) <= (a->real_item + a->malloced_size)))    {    for(;a->size < size; a->size++)    {