pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.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: builtin_functions.c,v 1.702 2010/07/19 15:30:48 mast Exp $ + || $Id: builtin_functions.c,v 1.703 2010/07/27 15:33:37 mast Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin_functions.c:2552:    *! then each element is initialized by copying that value    *! recursively.    *!    *! @seealso    *! @[sizeof()], @[aggregate()], @[arrayp()]    */   PMOD_EXPORT void f_allocate(INT32 args)   {    INT_TYPE size;    struct array *a; -  struct svalue *init; +  struct svalue *init = NULL;       get_all_args("allocate", args, "%+.%*", &size, &init);    if (size > MAX_INT32)    SIMPLE_ARG_ERROR ("allocate", 1, "Integer too large to use as array size.");       a=allocate_array(size);    if(args>1)    {    INT32 e;    push_array (a); -  +  if (init) {    for(e=0;e<size;e++)    copy_svalues_recursively_no_free(a->item+e, init, 1, 0);    a->type_field = 1 << init->type; -  +  } +  else { +  /* It's somewhat quirky that allocate(17) and allocate(17, UNDEFINED) +  * have different behavior, but it's of some use, and it's compatible +  * with previous versions. */ +  for(e=0;e<size;e++) +  ITEM (a)[e] = svalue_undefined; +  a->type_field = BIT_INT; +  }    stack_pop_n_elems_keep_top (args);    }    else {    a->type_field = BIT_INT;    pop_n_elems(args);    push_array(a);    }   }      /*! @decl object this_object(void|int level);