pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:15:   #include "pike_error.h"   #include "pike_types.h"   #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.125 2002/05/10 23:35:06 nilsson Exp $"); + RCSID("$Id: array.c,v 1.126 2002/05/28 15:23:03 grubba 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:65:   /* 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;    -  if(size == 0) +  if(size+extra_space == 0)    {    add_ref(&empty_array);    return &empty_array;    }       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");   
pike.git/src/array.c:1928:       ret->type_field=a->type_field;    return ret;   }      PMOD_EXPORT void apply_array(struct array *a, INT32 args)   {    INT32 e;    struct svalue *argp = Pike_sp-args;    TYPE_FIELD new_types = 0; +  struct array *cycl; +  DECLARE_CYCLIC();       check_array_for_destruct(a);    check_stack(120 + args + 1);    -  +  /* FIXME: Ought to use a better key on the arguments below. */ +  if (!(cycl = (struct array *)BEGIN_CYCLIC(a, args))) {    BEGIN_AGGREGATE_ARRAY(a->size) { -  +  SET_CYCLIC_RET(Pike_sp[-1].u.array);    for (e=0;e<a->size;e++) {    assign_svalues_no_free(Pike_sp, argp, args, BIT_MIXED);    Pike_sp+=args;    apply_svalue(ITEM(a)+e,args);    new_types |= 1 << Pike_sp[-1].type;    DO_AGGREGATE_ARRAY(120);    }    } END_AGGREGATE_ARRAY;       Pike_sp[-1].u.array->type_field = new_types;   #ifdef PIKE_DEBUG    array_check_type_field(Pike_sp[-1].u.array);   #endif -  +  } else { +  ref_push_array(cycl); +  } +  END_CYCLIC();    stack_pop_n_elems_keep_top(args);   }      PMOD_EXPORT struct array *reverse_array(struct array *a)   {    INT32 e;    struct array *ret;       if(a->refs == 1)    /* Reverse in-place. */