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.649 2008/01/23 19:52:49 grubba Exp $ + || $Id: builtin_functions.c,v 1.650 2008/01/26 22:34:17 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:3935:    arg2 && pike_types_le((*arg2)->type, string_type_string)) {    extern struct program *single_string_replace_program;    replace_compiler = single_string_replace_program;    }    if (replace_compiler && !is_const(*arg0) && is_const(*arg1) &&    (!arg2 || is_const(*arg2))) {    /* The second and third (if any) arguments are constants. */    struct svalue *save_sp = Pike_sp;    JMP_BUF tmp;    if (SETJMP(tmp)) { -  struct svalue thrown = throw_value; +  struct svalue thrown;    struct pike_string *s; -  throw_value.type = T_INT; +  move_svalue (&thrown, &throw_value); +  mark_free_svalue (&throw_value);    pop_n_elems(Pike_sp - save_sp);    yywarning("Optimizer failure in replace().");    s = format_exception_for_error_msg (&thrown);    if (s) {    yywarning ("%S", s);    free_string (s);    }    free_svalue(&thrown);    } else {    INT16 lfun;
pike.git/src/builtin_functions.c:6075:    ITEM(val.u.array)[0].u.integer=i;    val.u.array->type_field = BIT_INT;    mapping_insert(map,ITEM(b)+i,&val);    free_svalue(&val);    if (u) {    (*u)++;    }    }    else    { -  pval->u.array=resize_array(pval->u.array,pval->u.array->size+1); -  pval->u.array->item[pval->u.array->size-1].type=T_INT; -  pval->u.array->item[pval->u.array->size-1].subtype=NUMBER_NUMBER; -  pval->u.array->item[pval->u.array->size-1].u.integer=i; +  struct array *a = pval->u.array= +  resize_array(pval->u.array,pval->u.array->size+1); +  struct svalue *s = ITEM(a) + pval->u.array->size-1; +  s->type=T_INT; +  s->subtype=NUMBER_NUMBER; +  s->u.integer=i;    }    }       res=low_allocate_array(a->size,0);    types = 0;       for (i=0; i<a->size; i++)    {    pval=low_mapping_lookup(map,a->item+i);    if (!pval)
pike.git/src/builtin_functions.c:7526:    }else{    ret=0;    }    pop_n_elems(args);    push_int(!!ret);   }      /*! @module Array    */    + #ifdef HAVE_UNION_INIT + static const struct svalue one = {PIKE_T_INT, NUMBER_NUMBER, {1}}; + #endif +    /*! @decl array uniq(array a)    *!    *! Remove elements that are duplicates.    *!    *! @returns    *! This function returns an copy of the array @[a] with all    *! duplicate values removed. The order of the values is kept in the    *! result; it's always the first of several equal elements that is    *! kept.    *!    *! @note    *! Elements are compared with @[`==]. They are also hashed (see    *! @[lfun::__hash] for further details if the array contains    *! objects).    */   PMOD_EXPORT void f_uniq_array(INT32 args)   {    struct array *a, *b;    struct mapping *m; -  + #ifndef HAVE_UNION_INIT    struct svalue one; -  + #endif    int i, j=0,size=0;       get_all_args("uniq", args, "%a", &a);    push_mapping(m = allocate_mapping(a->size));    push_array(b = allocate_array(a->size));    -  + #ifndef HAVE_UNION_INIT    one.type = T_INT; -  +  one.subtype = NUMBER_NUMBER;    one.u.integer = 1; -  + #endif    for(i =0; i< a->size; i++)    {    mapping_insert(m, ITEM(a)+i, &one);    if(m_sizeof(m) != size)    {    size=m_sizeof(m);    assign_svalue_no_free(ITEM(b)+ j++, ITEM(a)+i);    }    }    dmalloc_touch_svalue(Pike_sp-1);
pike.git/src/builtin_functions.c:7975:    /* mapping ret =    mkmapping(indices(arr),    map(values(arr),fun,@extra)); */    f_aggregate(args-2);    mysp=Pike_sp;    splice=mysp[-1].u.array->size;       push_svalue(mysp-3); /* arr */    f_values(1);    push_svalue(mysp-2); /* fun */ -  *Pike_sp=mysp[-1]; /* extra */ -  mysp[-1].type=T_INT; +  move_svalue (Pike_sp, mysp-1); /* extra */ +  mark_free_svalue (mysp-1);    dmalloc_touch_svalue(Pike_sp);    push_array_items(Pike_sp->u.array);    f_map(splice+2); /* ... arr fun extra -> ... retval */    stack_pop_2_elems_keep_top(); /* arr fun extra ret -> arr retval */    stack_swap(); /* retval arr */    f_indices(1); /* retval retind */    stack_swap(); /* retind retval */    f_mkmapping(2); /* ret :-) */    return;       case T_MULTISET:    /* multiset ret =    (multiset)(map(indices(arr),fun,@extra)); */    push_svalue(Pike_sp-args); /* take indices from arr */    free_svalue(Pike_sp-args-1); /* move it to top of stack */ -  Pike_sp[-args-1].type=T_INT; +  mark_free_svalue (Pike_sp-args-1);    f_indices(1); /* call f_indices */    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    Pike_sp[-args]=Pike_sp[0]; /* move it back */    f_map(args);       /* FIXME: Handle multisets with values like mappings. */    push_multiset (mkmultiset_2 (Pike_sp[-1].u.array, NULL, NULL));    free_array (Pike_sp[-2].u.array);    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp[-2] = Pike_sp[-1];    Pike_sp--;    return;       case T_STRING:    /* multiset ret =    (string)(map((array)arr,fun,@extra)); */    push_svalue(Pike_sp-args); /* take indices from arr */    free_svalue(Pike_sp-args-1); /* move it to top of stack */ -  Pike_sp[-args-1].type=T_INT; +  mark_free_svalue (Pike_sp-args-1);    o_cast(NULL,T_ARRAY); /* cast the string to an array */    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    Pike_sp[-args]=Pike_sp[0]; /* move it back */    f_map(args);    o_cast(NULL,T_STRING); /* cast the array to a string */    return;       case T_OBJECT:    /* if arr->cast :
pike.git/src/builtin_functions.c:8132:       default:    SIMPLE_BAD_ARG_ERROR("map",1,    "array|mapping|program|function|"    "multiset|string|object");    }       if (UNSAFE_IS_ZERO (Pike_sp-args+1)) {    free_svalue (Pike_sp-args+1);    move_svalue (Pike_sp-args+1, Pike_sp-args); -  Pike_sp[-args].type = T_INT; +  mark_free_svalue (Pike_sp-args);    mega_apply (APPLY_STACK, args-1, 0, 0);    stack_pop_keep_top();    return;    }       f_aggregate(args-2);    mysp=Pike_sp;    splice=mysp[-1].u.array->size;       a=mysp[-3].u.array;
pike.git/src/builtin_functions.c:8393:    return;       case T_MAPPING:    case T_PROGRAM:    case T_FUNCTION:    /* mapping ret =    mkmapping(indices(arr),    map(values(arr),fun,@extra)); */    MEMMOVE(Pike_sp-args+2,Pike_sp-args,args*sizeof(*Pike_sp));    Pike_sp+=2; -  Pike_sp[-args-2].type=T_INT; -  Pike_sp[-args-1].type=T_INT; +  mark_free_svalue (Pike_sp-args-2); +  mark_free_svalue (Pike_sp-args-1);       push_svalue(Pike_sp-args);    f_indices(1);    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    Pike_sp[-args-2]=*Pike_sp;    dmalloc_touch_svalue(Pike_sp);    push_svalue(Pike_sp-args);    f_values(1);    Pike_sp--;
pike.git/src/builtin_functions.c:8431:    for (i=0; i<n; i++)    if (!UNSAFE_IS_ZERO(f->item+i))    mapping_insert(Pike_sp[-1].u.mapping,y->item+i,a->item+i);       stack_pop_n_elems_keep_top(3);    return;       case T_MULTISET:    push_svalue(Pike_sp-args); /* take indices from arr */    free_svalue(Pike_sp-args-1); /* move it to top of stack */ -  Pike_sp[-args-1].type=T_INT; +  mark_free_svalue (Pike_sp-args-1);    f_indices(1); /* call f_indices */    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    Pike_sp[-args]=Pike_sp[0]; /* move it back */    f_filter(args);       /* FIXME: Handle multisets with values like mappings. */    push_multiset (mkmultiset_2 (Pike_sp[-1].u.array, NULL, NULL));    free_array (Pike_sp[-2].u.array);    Pike_sp[-2] = Pike_sp[-1];    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    return;       case T_STRING:    push_svalue(Pike_sp-args); /* take indices from arr */    free_svalue(Pike_sp-args-1); /* move it to top of stack */ -  Pike_sp[-args-1].type=T_INT; +  mark_free_svalue (Pike_sp-args-1);    o_cast(NULL,T_ARRAY); /* cast the string to an array */    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    Pike_sp[-args]=Pike_sp[0]; /* move it back */    f_filter(args);    o_cast(NULL,T_STRING); /* cast the array to a string */    return;       case T_OBJECT:    mysp=Pike_sp+3-args;