Branch: Tag:

2001-02-03

2001-02-03 01:04:48 by Martin Stjernholm <mast@lysator.liu.se>

Don't consume arbitrary amounts of stack in apply_array and
explode_array.

Rev: src/array.c:1.102

23:   #include "stuff.h"   #include "bignum.h"    - RCSID("$Id: array.c,v 1.101 2001/01/03 21:35:13 grubba Exp $"); + RCSID("$Id: array.c,v 1.102 2001/02/03 01:04:48 mast Exp $");      PMOD_EXPORT struct array empty_array=   {
1867:   PMOD_EXPORT void apply_array(struct array *a, INT32 args)   {    INT32 e; -  struct array *ret; -  ptrdiff_t argp; +  struct svalue *argp = Pike_sp-args; +  TYPE_FIELD new_types = 0;    -  argp=Pike_sp-args - Pike_interpreter.evaluator_stack; -  -  check_stack(a->size + args + 1); +     check_array_for_destruct(a); -  for(e=0;e<a->size;e++) -  { -  assign_svalues_no_free(Pike_sp, Pike_interpreter.evaluator_stack + argp, -  args, BIT_MIXED); +  check_stack(120 + args + 1); +  +  BEGIN_AGGREGATE_ARRAY(a->size) { +  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);    } -  ret=aggregate_array(a->size); -  pop_n_elems(args); -  push_array(ret); +  } 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 +  stack_pop_n_elems_keep_top(args);   }      PMOD_EXPORT struct array *reverse_array(struct array *a)
2244:      PMOD_EXPORT struct array *explode_array(struct array *a, struct array *b)   { -  INT32 e,d,q,start; +  INT32 e,d,start;    struct array *tmp;    -  q=start=0; +  start=0;   #if 0    if(!a->size)    {
2256:   #endif    if(b->size)    { +  BEGIN_AGGREGATE_ARRAY(1) {    for(e=0;e<=a->size - b->size;e++)    {    for(d=0;d<b->size;d++)
2267:    {    check_stack(1);    push_array(friendly_slice_array(a, start, e)); -  q++; +  DO_AGGREGATE_ARRAY(120);    e+=b->size-1;    start=e+1;    }    }    check_stack(1);    push_array(friendly_slice_array(a, start, a->size)); -  q++; +  } END_AGGREGATE_ARRAY;    }else{ -  check_stack(a->size); -  for(e=0;e<a->size;e++) push_array(friendly_slice_array(a, e, e+1)); -  q=a->size; +  check_stack(120); +  BEGIN_AGGREGATE_ARRAY(a->size) { +  for(e=0;e<a->size;e++) { +  push_array(friendly_slice_array(a, e, e+1)); +  DO_AGGREGATE_ARRAY(120);    } -  tmp=aggregate_array(q); +  } END_AGGREGATE_ARRAY; +  } +  tmp=(--Pike_sp)->u.array;    if(tmp->size) tmp->type_field=BIT_ARRAY;    return tmp;   }