pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:659:    */   PMOD_EXPORT   PIKEFUN array(array(int|string)) _describe_program(mixed x)    efun;   {    struct program *p;    struct array *res;    int i;       if (!(p = program_from_svalue(Pike_sp - args))) -  SIMPLE_BAD_ARG_ERROR("_describe_program", 1, "program"); +  SIMPLE_ARG_TYPE_ERROR("_describe_program", 1, "program");       for (i=0; i < (int)p->num_identifier_references;i++) {    struct reference *ref = p->identifier_references + i;    struct identifier *id = ID_FROM_PTR(p, ref);    struct inherit *inh = INHERIT_FROM_PTR(p, ref);    push_int(ref->id_flags);    ref_push_string(id->name);    ref_push_type_value(id->type);    push_int(id->identifier_flags);    if (IDENTIFIER_IS_C_FUNCTION(id->identifier_flags)) {
pike.git/src/builtin.cmod:784:    if(TYPEOF(Pike_sp[-1]) == T_STRING)    {    stack_swap();    pop_stack();    return;    }    Pike_error("Non-string returned from _sprintf()\n");    }    }    if(TYPEOF(*x) != T_INT) -  SIMPLE_BAD_ARG_ERROR("int2char", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("int2char", 1, "int");       c=x->u.integer;       if(c>=0 && c<256)    {    struct pike_string *s;    s=begin_shared_string(1);    s->str[0]=c;    RETURN end_shared_string(s);    }else{
pike.git/src/builtin.cmod:841:    if(TYPEOF(Pike_sp[-1]) == T_STRING)    {    stack_swap();    pop_stack();    return;    }    Pike_error("Non-string returned from _sprintf()\n");    }    }    if(TYPEOF(*x) != T_INT) -  SIMPLE_BAD_ARG_ERROR("int2hex", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("int2hex", 1, "int");       c=x->u.integer;       len=1;    if(c<0) {    len++;    n=(-c)&((unsigned INT_TYPE)(-1));    }else{    n=c;    }
pike.git/src/builtin.cmod:1241:    else { \    GET; \    mapping_string_insert (params, str, &get); \    } \    } while (0)      #define HANDLE_FLOAT_FACTOR(NAME, VAR) \    HANDLE_PARAM (NAME, { \    if (TYPEOF(*set) != T_FLOAT || \    set->u.float_number < 0.0 || set->u.float_number > 1.0) \ -  SIMPLE_BAD_ARG_ERROR ("gc_parameters", 1, \ +  SIMPLE_ARG_TYPE_ERROR ("gc_parameters", 1, \    "float between 0.0 and 1.0 for " NAME); \    VAR = (double) set->u.float_number; \    }, { \    SET_SVAL(get, T_FLOAT, 0, float_number, (FLOAT_TYPE) VAR); \    });       HANDLE_PARAM ("enabled", {    if (TYPEOF(*set) != T_INT || set->u.integer < -1 || set->u.integer > 1) -  SIMPLE_BAD_ARG_ERROR ("gc_parameters", 1, +  SIMPLE_ARG_TYPE_ERROR ("gc_parameters", 1,    "integer in the range -1..1 for 'enabled'");    if (gc_enabled != set->u.integer) {    if (gc_enabled > 0) {    /* Disabling automatic gc - save the old alloc_threshold and set it to    * the maximum value to avoid getting gc_evaluator_callback added. */    saved_alloc_threshold = alloc_threshold;    alloc_threshold = GC_MAX_ALLOC_THRESHOLD;    }    else if (set->u.integer > 0) {    /* Enabling automatic gc - restore the old alloc_threshold. If the
pike.git/src/builtin.cmod:1820:    pop_n_elems(args);    *Pike_sp=s;    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);    }    else if (TYPEOF(*map) == T_OBJECT && (p = map->u.object->prog))    {    int id = FIND_LFUN(p->inherits[SUBTYPEOF(*map)].prog, LFUN__M_DELETE);       if( id == -1 ) -  SIMPLE_BAD_ARG_ERROR("m_delete", 1, "object containing the _m_delete method"); +  SIMPLE_ARG_TYPE_ERROR("m_delete", 1, "object containing the _m_delete method");       apply_low(map->u.object,    id + p->inherits[SUBTYPEOF(*map)].identifier_level, 1);    stack_swap();    pop_stack();    } else { -  SIMPLE_BAD_ARG_ERROR("m_delete", 1, "object|mapping"); +  SIMPLE_ARG_TYPE_ERROR("m_delete", 1, "object|mapping");    }   }      /*! @decl int get_weak_flag(array|mapping|multiset m)    *!    *! Returns the weak flag settings for @[m]. It's a combination of    *! @[Pike.WEAK_INDICES] and @[Pike.WEAK_VALUES].    */   PMOD_EXPORT   PIKEFUN int get_weak_flag(array m)
pike.git/src/builtin.cmod:1901:   PIKEFUN string function_name(program|function func)    efun;    optflags OPT_TRY_OPTIMIZE;   {    int f = -1;    struct program *p = NULL;       switch(TYPEOF(*func))    {    default: -  SIMPLE_BAD_ARG_ERROR("function_name", 1, "function|program"); +  SIMPLE_ARG_TYPE_ERROR("function_name", 1, "function|program");    UNREACHABLE(return);       case PIKE_T_PROGRAM:    {    p = func->u.program;       if(p->parent)    {    int e;    p=p->parent;
pike.git/src/builtin.cmod:2010:    add_ref(o);    pop_n_elems(args);    push_object(o);    return;    }    SET_SVAL(*func, T_OBJECT, 0, object, func->u.object);    return;          default: -  SIMPLE_BAD_ARG_ERROR("function_object",1,"function"); +  SIMPLE_ARG_TYPE_ERROR("function_object",1,"function");    }    pop_n_elems(args);    push_int(0);   }      /*! @decl program function_program(function|program f)    *!    *! Return the program the function @[f] is in.    *!    *! If @[f] is a global function defined in the runtime @expr{0@}
pike.git/src/builtin.cmod:2064:    }    if (p) {    ref_push_program(p);    stack_pop_n_elems_keep_top(args);    return;    }    }    break;       default: -  SIMPLE_BAD_ARG_ERROR("function_program", 1, "function"); +  SIMPLE_ARG_TYPE_ERROR("function_program", 1, "function");    }    pop_n_elems(args);    push_int(0);   }      PIKECLASS RandomInterface   {    CVAR INT64 int_buffer;    CVAR int buffer_bits;   
pike.git/src/builtin.cmod:2156:    }       /*! @decl mixed random(array|multiset x)    *! Returns a random element from @[x].    */       PIKEFUN mixed random(array a)    rawtype tFunc(tArr(tSetvar(0,tMix)),tVar(0));    {    if(!a->size) -  SIMPLE_BAD_ARG_ERROR("random", 1, "array with elements in it"); +  SIMPLE_ARG_TYPE_ERROR("random", 1, "array with elements in it");    push_svalue(a->item + (read_int(a->size)));    }       PIKEFUN mixed random(multiset m)    rawtype tFunc(tSet(tSetvar(1,tMix)),tVar(1));    {    if(multiset_is_empty (m)) -  SIMPLE_BAD_ARG_ERROR("random", 1, "multiset with elements in it"); +  SIMPLE_ARG_TYPE_ERROR("random", 1, "multiset with elements in it");    push_multiset_index (m, multiset_get_nth (m, read_int(multiset_sizeof (m))));    sub_msnode_ref (m);    }       /*! @decl array random(mapping m)    *! Returns a random index-value pair from the mapping.    */    PIKEFUN array random(mapping m)    {    struct keypair *k;    int e, count;       if(!m_sizeof(m)) -  SIMPLE_BAD_ARG_ERROR("random", 1, "mapping with elements in it"); +  SIMPLE_ARG_TYPE_ERROR("random", 1, "mapping with elements in it");       count = read_int( m_sizeof(m) );       /* We could optimize this by not iterating over hash buckets we will    not pick a member from. */       NEW_MAPPING_LOOP(m->data)    {    if(count-- < 1)    {
pike.git/src/builtin.cmod:2752:    pop_n_elems(args - 2);    args = 2;    }       switch(index) {    case 0: /* Filename */    if (THIS->lineno == -1) fill_in_file_and_line();    if (TYPEOF(*value) != PIKE_T_STRING) {    if ((TYPEOF(*value) != PIKE_T_INT) ||    (value->u.integer)) { -  SIMPLE_BAD_ARG_ERROR("`[]=", 2, "string|int(0..0)"); +  SIMPLE_ARG_TYPE_ERROR("`[]=", 2, "string|int(0..0)");    }    if (THIS->filename) {    free_string(THIS->filename);    THIS->filename = NULL;    }    } else {    if (THIS->filename) {    free_string(THIS->filename);    THIS->filename = NULL;    }    copy_shared_string(THIS->filename, value->u.string);    }    break;       case 1: /* Linenumber */    if (THIS->lineno == -1) fill_in_file_and_line();    if (TYPEOF(*value) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("`[]=", 2, "int(1..)"); +  SIMPLE_ARG_TYPE_ERROR("`[]=", 2, "int(1..)");    THIS->lineno = value->u.integer;    break;       case 2: /* Function */    if (THIS->lineno == -1) fill_in_file_and_line();    assign_svalue(&THIS->_fun, value);    break;    default: /* Arguments */    assign_svalue(THIS->args->item + index - 3, value);    break;
pike.git/src/builtin.cmod:3177:    if (args) {    int init_from_arg0 = 0, j;    ptrdiff_t sum = 0;    int shift = 0;    for (j=0; j < args; j++) {    struct pike_string *a;    if (TYPEOF(Pike_sp[j-args]) == PIKE_T_STRING)    a = Pike_sp[j-args].u.string;    else if ((TYPEOF(Pike_sp[j-args]) != PIKE_T_OBJECT) ||    (Pike_sp[j-args].u.object->prog != Buffer_program)) -  SIMPLE_BAD_ARG_ERROR("add", j+1, "string|String.Buffer"); +  SIMPLE_ARG_TYPE_ERROR("add", j+1, "string|String.Buffer");    else {    a = OBJ2_BUFFER(Pike_sp[j-args].u.object)->str.s;    if (!a) continue;    }    sum += a->len;    shift |= a->size_shift;    }    shift |= str->str.known_shift;    shift = shift & ~(shift >> 1);    /* We know it will be a string that really is this wide. */
pike.git/src/builtin.cmod:3437:       case 1:    if (TYPEOF(*from_arg) != T_MAPPING)    Pike_error("Illegal arguments to create().\n");    THIS->from = mapping_indices(from_arg->u.mapping);    THIS->to = mapping_values(from_arg->u.mapping);    break;       case 2:    if (TYPEOF(*from_arg) != T_ARRAY) { -  SIMPLE_BAD_ARG_ERROR("replace", 1, +  SIMPLE_ARG_TYPE_ERROR("replace", 1,    "array(string)|mapping(string:string)");    }    if (TYPEOF(*to_arg) == T_STRING) {    push_int(from_arg->u.array->size);    stack_swap();    f_allocate(2);    }    if (TYPEOF(*to_arg) != T_ARRAY) { -  SIMPLE_BAD_ARG_ERROR("replace", 2, "array(string)|string"); +  SIMPLE_ARG_TYPE_ERROR("replace", 2, "array(string)|string");    }    if (from_arg->u.array->size != to_arg->u.array->size) {    Pike_error("Replace must have equal-sized from and to arrays.\n");    }    add_ref(THIS->from = from_arg->u.array);    add_ref(THIS->to = to_arg->u.array);    }       if (!THIS->from->size) {    /* Enter no-op mode. */    return;    }       if( (THIS->from->type_field & ~BIT_STRING) &&    (array_fix_type_field(THIS->from) & ~BIT_STRING) ) -  SIMPLE_BAD_ARG_ERROR("replace", 1, +  SIMPLE_ARG_TYPE_ERROR("replace", 1,    "array(string)|mapping(string:string)");       if( (THIS->to->type_field & ~BIT_STRING) &&    (array_fix_type_field(THIS->to) & ~BIT_STRING) ) -  SIMPLE_BAD_ARG_ERROR("replace", 2, "array(string)|string"); +  SIMPLE_ARG_TYPE_ERROR("replace", 2, "array(string)|string");       compile_replace_many(&THIS->ctx, THIS->from, THIS->to, 1);    }       /*! @decl string `()(string str)    */    PIKEFUN string `()(string str)    {    if (!THIS->ctx.v) {    /* The result is already on the stack in the correct place... */
pike.git/src/builtin.cmod:3570:    THIS->del = NULL;    }    if (THIS->to) {    free_string(THIS->to);    THIS->to = NULL;    }       if (!del) return;       if (!to) { -  SIMPLE_BAD_ARG_ERROR("replace", 2, "string"); +  SIMPLE_ARG_TYPE_ERROR("replace", 2, "string");    }       if (del == to) {    /* No-op... */    return;    }       copy_shared_string(THIS->del, del);    copy_shared_string(THIS->to, to);   
pike.git/src/builtin.cmod:4677:    *! @seealso    *! @[Serializer.serialize()], @[_serialize_variable()],    *! @[_deserialize()]    */    PIKEFUN void _serialize(object o,    function(mixed, string, type:void) serializer)    flags ID_PROTECTED;    rawtype tFunc(tObj tFunc(tMix tStr tType(tMix), tVoid), tVoid);    {    if (o != Pike_fp->current_object) { -  SIMPLE_BAD_ARG_ERROR("_serialize", 1, "this"); +  SIMPLE_ARG_TYPE_ERROR("_serialize", 1, "this");    }    low_serialize(SUBTYPEOF(Pike_sp[-args]), serializer, 0,    f_Serializable_cq__serialize_variable_fun_num);    }       static void *find_program_from_object_type_cb(struct pike_type *t)    {    struct program *p;    if ((t->type != PIKE_T_OBJECT) || !t->cdr) return NULL;    p = id_to_program(CDR_TO_INT(t));
pike.git/src/builtin.cmod:4820:    *! @[Serializer.deserialize()], @[_deserialize_variable()],    *! @[_serialize()], @[Builtin.Setter]    */    PIKEFUN void _deserialize(object o,    function(function(mixed:void),    string, type: void) deserializer)    flags ID_PROTECTED;    rawtype tFunc(tObj tFunc(tFunc(tMix, tVoid) tStr tType(tMix), tVoid), tVoid);    {    if (o != Pike_fp->current_object) { -  SIMPLE_BAD_ARG_ERROR("_serialize", 1, "this"); +  SIMPLE_ARG_TYPE_ERROR("_serialize", 1, "this");    }    low_serialize(SUBTYPEOF(Pike_sp[-args]), deserializer, 1,    f_Serializable_cq__deserialize_variable_fun_num);    }   }   /*! @endclass    */      /*! @decl void serialize(object o, @    *! function(mixed, string, type:void) serializer)
pike.git/src/builtin.cmod:5368:    push_undefined();    }          /*! @decl mixed `[](mixed key) */    PIKEFUN mixed `[](mixed key)    flags ID_PROTECTED;    {    struct pike_list_node *node;    INT_TYPE n; -  if (TYPEOF(*key) != PIKE_T_INT) SIMPLE_BAD_ARG_ERROR("`[]", 1, "int"); +  if (TYPEOF(*key) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("`[]", 1, "int");       n = key->u.integer;    if (n < 0) n = -(n+1);       if (n >= THIS->num_elems) Pike_error("out of bounds");       if (n >= THIS->num_elems >> 1) { /* use shorter direction */    n = THIS->num_elems - n - 1;    key->u.integer = - key->u.integer - 1;    }