pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:413:    FIX_THIS();    {    char *tval = asctime_zone( &THIS->t );    if( tval )    push_text( tval );    else    push_undefined();    }    }    -  PIKEFUN void _sprintf( int flag, mapping options ) +  PIKEFUN string _sprintf( int flag, mapping options )    {    int post_sum = 1;    switch( flag )    {    case 'O':    push_static_text("System.TM(");    post_sum = 1;    /* fallthrough */    case 's':    f_TM_asctime(0);
pike.git/src/builtin.cmod:2083:    */      PMOD_EXPORT   PIKEFUN int random(int i)   {    if(i <= 0) RETURN 0;   #if SIZEOF_INT_TYPE > 4    if(i >> 31)    RETURN my_rand64() % i;   #endif -  RETURN my_rand() % i; +  RETURN my_rand() % i;   }      /*! @decl float random(float max)    *!    *! This function returns a random number in the range @expr{0 .. @[max]-ɛ@}.    *!    *! @seealso    *! @[random_seed()]    */   
pike.git/src/builtin.cmod:2429:    }   #endif    assign_svalue(&THIS->_fun, val);    }       /*! @decl int(0..1) _is_type(string t)    *! This object claims to be an array for backward compatibility.    */    PIKEFUN int(0..1) _is_type(string t)    { -  INT_TYPE res = (t == findstring("array")); -  pop_n_elems(args); -  push_int(res); +  RETURN (t == findstring("array"));    }       static void fill_in_file_and_line()    {    struct pike_string *file = NULL;    assert (THIS->lineno == -1);       if (THIS->pc && THIS->prog) {    file = low_get_line(THIS->pc, THIS->prog, &THIS->lineno);    THIS->pc = NULL;
pike.git/src/builtin.cmod:3297:    tmp.u.string = THIS->ctx.v[i].ind;    res += rec_size_svalue( &tmp, NULL );    tmp.u.string = THIS->ctx.v[i].val;    res += rec_size_svalue( &tmp, NULL );    }    }       RETURN res;    }    -  /*! @decl void create(array(string)|mapping(string:string)|void from, @ -  *! array(string)|string|void to) +  /*! @decl void create() +  *! @decl void create(mapping(string:string)) +  *! @decl void create(array(string) from, array(string)|string to)    */    PIKEFUN void create(array(string)|mapping(string:string)|void from_arg,    array(string)|string|void to_arg)    {    if (THIS->from) {    free_array(THIS->from);    THIS->from = NULL;    }    if (THIS->to) {    free_array(THIS->to);    THIS->to = NULL;    }    if (THIS->ctx.v)    free_replace_many_context(&THIS->ctx);    -  if (!args) { -  push_int(0); +  switch(args) +  { +  case 0:    return; -  } -  if (from_arg && TYPEOF(*from_arg) == T_MAPPING) { -  if (to_arg) { -  Pike_error("Bad number of arguments to create().\n"); -  } +  +  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); -  pop_n_elems(args); -  args = 0; -  } else { -  /* FIXME: Why is from declared |void, when it isn't allowed -  * to be void? -  * /grubba 2004-09-02 -  * -  * It probably has to do with the "if (!args)" above: It should -  * be possible to create an empty instance. /mast -  */ -  if (!from_arg || !to_arg) { -  Pike_error("Bad number of arguments to create().\n"); -  } -  pop_n_elems(args-2); -  args = 2; +  break; +  +  case 2:    if (TYPEOF(*from_arg) != T_ARRAY) {    SIMPLE_BAD_ARG_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) {
pike.git/src/builtin.cmod:3360:    }    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. */ -  pop_n_elems(args); -  push_int(0); +     return;    }       if( (THIS->from->type_field & ~BIT_STRING) &&    (array_fix_type_field(THIS->from) & ~BIT_STRING) )    SIMPLE_BAD_ARG_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");       compile_replace_many(&THIS->ctx, THIS->from, THIS->to, 1); -  -  pop_n_elems(args); -  push_int(0); +     }       /*! @decl string `()(string str)    */    PIKEFUN string `()(string str)    {    if (!THIS->ctx.v) {    /* The result is already on the stack in the correct place... */    return;    }
pike.git/src/builtin.cmod:3414:    push_undefined();    }    f_aggregate(2);    }       /*! @decl void _decode(array(array(string)) encoded)    */    PIKEFUN void _decode(array(array(string)) encoded)    {    INT32 i; -  for (i=0; i < encoded->size; i++) { +  for (i=0; i < encoded->size; i++)    push_svalue(encoded->item + i); -  stack_swap(); -  } -  pop_stack(); +        f_multi_string_replace_create(i);    }       INIT    {    MEMSET(&THIS->ctx, 0, sizeof(struct replace_many_context));    }       EXIT
pike.git/src/builtin.cmod:3606:    }       /*! @decl void _decode(array(string)|int(0..0) encoded)    */    PIKEFUN void _decode(array(string)|int(0..0) encoded_)    {    INT32 i = 0;    if (TYPEOF(*encoded_) == PIKE_T_ARRAY) {    struct array *encoded = encoded_->u.array;    -  for (i=0; i < encoded->size; i++) { +  for (i=0; i < encoded->size; i++)    push_svalue(encoded->item + i); -  stack_swap(); +     } -  } -  pop_stack(); +        f_single_string_replace_create(i);    }   }      /*! @endclass    */      /*! @class Bootstring    *!
pike.git/src/builtin.cmod:4248:    *!    *! This is the function returned by @[_get_setter()].    */    PIKEFUN void `()(mixed val)    flags ID_PROTECTED;    {    if (!THIS->o) {    Pike_error("Uninitialized Setter!\n");    }    object_low_set_index(THIS->o, THIS->f, Pike_sp-1); -  pop_n_elems(args); -  push_int(0); +     } -  +     PIKEFUN string _sprintf(int c, mapping|void opts)    flags ID_PROTECTED;    {    struct program *prog;    if (!THIS->o) {    push_static_text("Setter()");    } else if ((prog = THIS->o->prog)) {    push_static_text("%O->`%s=");    ref_push_object(THIS->o);    ref_push_string(ID_FROM_INT(prog, THIS->f)->name);
pike.git/src/builtin.cmod:4368:    if (fmt == 'O') {    push_static_text("Val.null");    } else {    push_undefined();    }    }       PIKEFUN int __hash()    flags ID_PROTECTED;    { -  pop_n_elems(args); -  push_int(17); +  RETURN 17;    }       PIKEFUN int `==(mixed other)    flags ID_PROTECTED;    { -  if (TYPEOF(*other) != T_OBJECT) { -  pop_stack(); -  push_int(0); -  return; -  } +  if (TYPEOF(*other) != T_OBJECT) +  RETURN 0;       /* Look for the is_val_null constant directly in the program of    * other, without going through its `[]. When this is called in a    * codec, other can be a completely arbitrary object which may not    * have a `[] that works in that context. */    push_int (0);    ref_push_program (other->u.object->prog);    push_constant_text("is_val_null");    if (program_index_no_free (Pike_sp - 3, Pike_sp - 2, Pike_sp - 1) &&    TYPEOF(Pike_sp[-3]) == T_INT && Pike_sp[-3].u.integer) {
pike.git/src/builtin.cmod:4553:    *! @[_serialize()], @[_deserialize_variable()]    */    PIKEFUN void _serialize_variable(function(mixed, string, type:void)    serializer, mixed value,    string symbol, type symbol_type)    flags ID_PROTECTED;    rawtype tFunc(tFunc(tMix tStr tType(tMix), tVoid)    tMix tStr tType(tMix), tVoid);    {    f_call_function(args); -  pop_stack(); -  push_int(0); +     }       /*! @decl protected void _serialize(object o, @    *! function(mixed, string, type:void) serializer)    *!    *! Dispatch function for serialization.    *!    *! @param o    *! Object to serialize. Always a context of the current object.    *!
pike.git/src/builtin.cmod:4602:    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");    }    low_serialize(SUBTYPEOF(Pike_sp[-args]), serializer, 0,    f_Serializable_cq__serialize_variable_fun_num); -  pop_n_elems(args); -  push_int(0); +     }       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));    if (!p || (p->flags & PROGRAM_NEEDS_PARENT) ||    (low_find_lfun(p, LFUN__DESERIALIZE) == -1)) return NULL;    return p;
pike.git/src/builtin.cmod:4698:    struct object *o = clone_object(p, 0);    push_object(o); /* Protection against errors and arg to deserialize. */    ref_push_object(o);    apply_svalue(setter, 1);    pop_stack();    push_svalue(deserializer);    f_deserialize(2);    return;    }    f_call_function(args); -  pop_stack(); -  push_int(0); +     }       /*! @decl protected void _deserialize(object o, @    *! function(function(mixed:void), @    *! string, type: void) deserializer)    *!    *! Dispatch function for deserialization.    *!    *! @param o    *! Object to serialize. Always a context of the current object.
pike.git/src/builtin.cmod:4749:    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");    }    low_serialize(SUBTYPEOF(Pike_sp[-args]), deserializer, 1,    f_Serializable_cq__deserialize_variable_fun_num); -  pop_n_elems(args); -  push_int(0); +     }   }   /*! @endclass    */      /*! @decl void serialize(object o, @    *! function(mixed, string, type:void) serializer)    *!    *! Call @[lfun::_serialize()] in @[o].    *!
pike.git/src/builtin.cmod:5336:    PIKEFUN void append(mixed ... values)    {    struct pike_list_node *node = TAIL_SENTINEL(THIS);    while (args--) {    struct pike_list_node *new_node = alloc_pike_list_node();    new_node->val = *(--Pike_sp);    prepend_list_node(node, new_node);    free_list_node(node = new_node);    THIS->num_elems++;    } -  push_int(0); +     }       /*! @decl void insert(mixed ... values)    *!    *! Insert @[values] at the front of the list.    *!    *! @seealso    *! @[append()]    */    PIKEFUN void insert(mixed ... values)    {    struct pike_list_node *node = THIS->head;    while (args--) {    struct pike_list_node *new_node = alloc_pike_list_node();    new_node->val = *(--Pike_sp);    prepend_list_node(node, new_node);    free_list_node(node = new_node);    THIS->num_elems++;    } -  push_int(0); +     }       /*! @decl void flush()    *!    *! Empties the List.    */    PIKEFUN void flush() {    if (THIS->num_elems) {    while (THIS->head->next) {    if (THIS->head->refs == 2)
pike.git/src/builtin.cmod:5548:   #endif /* PIKE_DEBUG */    /* Detached node. */    gc_recurse_svalues(&THIS->cur->val, 1);    gc_recurse_list_node_tree_forward(THIS->cur->next, THIS->cur->prev);    gc_recurse_list_node_tree_backward(THIS->cur->next, THIS->cur->prev);    }       PIKEFUN int(0..1) `!()    flags ID_PROTECTED;    { -  pop_n_elems(args); -  push_int(!THIS->cur->next || !THIS->cur->prev); +  RETURN (!THIS->cur->next || !THIS->cur->prev);    }       PIKEFUN int(0..) index()    {    pop_n_elems(args);    if (THIS->cur->next && THIS->cur->prev) {    push_int(THIS->ind);    } else {    push_undefined();    }
pike.git/src/builtin.cmod:5628:    *! @seealso    *! @[prev()]    */    PIKEFUN int(0..1) next()    {    struct pike_list_node *next;    if ((next = THIS->cur->next)) {    free_list_node(THIS->cur);    add_ref(THIS->cur = next);    THIS->ind++; -  if (next->next) { -  pop_n_elems(args); -  push_int(1); -  return; +  if (next->next) +  RETURN 1;    } -  +  RETURN 0;    } -  pop_n_elems(args); -  push_int(0); -  } +        /*! @decl int(0..1) prev()    *!    *! Retrace to the previous element in the list.    *!    *! @returns    *! Returns @expr{1@} on success, and @expr{0@} (zero)    *! at the beginning of the list.    *!    *! @seealso    *! @[next()]    */    PIKEFUN int(0..1) prev()    {    struct pike_list_node *prev;    if ((prev = THIS->cur->prev)) {    free_list_node(THIS->cur);    add_ref(THIS->cur = prev);    THIS->ind--; -  if (prev->prev) { -  pop_n_elems(args); -  push_int(1); -  return; +  if (prev->prev) +  RETURN 1;    } -  +  RETURN 0;    } -  pop_n_elems(args); -  push_int(0); -  } +        /*! @decl Iterator `+=(int steps)    *!    *! Advance or retrace the specified number of @[steps].    *!    *! @seealso    *! @[next()], @[prev]    */    PIKEFUN Iterator `+=(int steps)    {
pike.git/src/builtin.cmod:5710:    struct pike_list_node *new_node;    if (!THIS->cur->prev) {    Pike_error("Attempt to insert before the start sentinel.\n");    }    new_node = alloc_pike_list_node();    assign_svalue_no_free(&new_node->val, val);    prepend_list_node(THIS->cur, new_node);    free_list_node(THIS->cur);    THIS->cur = new_node;    List__get_iterator_find_parent()->num_elems++; -  pop_n_elems(args); -  push_int(0); +     }       /*! @decl void append(mixed val)    *!    *! Append @[val] after the current position.    *!    *! @seealso    *! @[insert()], @[delete()], @[set()]    */    PIKEFUN void append(mixed val)    {    struct pike_list_node *new_node;    if (!THIS->cur->next) {    Pike_error("Attempt to append after the end sentinel.\n");    }    new_node = alloc_pike_list_node();    assign_svalue_no_free(&new_node->val, val);    append_list_node(THIS->cur, new_node);    free_list_node(new_node);    List__get_iterator_find_parent()->num_elems++; -  pop_n_elems(args); -  push_int(0); +     }       /*! @decl void delete()    *!    *! Delete the current node.    *!    *! The current position will advance to the next node.    *! This function thus performes the reverse operation    *! of @[insert()].    *!
pike.git/src/builtin.cmod:5765:    if (THIS->cur->refs == 3) {    unlink_list_node(THIS->cur);    } else {    /* There's some other iterator holding references to this node. */    detach_list_node(THIS->cur);    }    List__get_iterator_find_parent()->num_elems--;    }    free_list_node(THIS->cur);    THIS->cur = next; -  pop_n_elems(args); -  push_int(0); +     }       /*! @decl void set(mixed val)    *!    *! Set the value of the current position to @[val].    *!    *! @seealso    *! @[insert()], @[append()], @[delete()]    */    PIKEFUN void set(mixed val)    {    if (!THIS->cur->next || !THIS->cur->prev) {    Pike_error("Attempt to set a sentinel.\n");    }    assign_svalue(&THIS->cur->val, val); -  pop_n_elems(args); -  push_int(0); +     }    }    /*! @endclass    */   }   /*! @endclass    */      /*! @endmodule    */