pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*-   || 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.cmod,v 1.156 2004/04/25 19:50:18 nilsson Exp $ + || $Id: builtin.cmod,v 1.157 2005/03/22 15:42:14 grubba 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.cmod:395:    *! the current thread. To change the level in all threads, pass a    *! nonzero value in this argument.    *!    *! @returns    *! The old trace level in the current thread is returned.    */   PIKEFUN int trace(int level, void|string facility, void|int all_threads)    efun;    optflags OPT_SIDE_EFFECT;   { -  INT32 old_level; +  INT32 old_level = 0;    if (facility) {    struct pike_string *gc_str; -  if (facility->type != T_STRING) -  SIMPLE_BAD_ARG_ERROR("trace", 2, "void|string"); +     MAKE_CONST_STRING(gc_str, "gc"); -  if (facility->u.string == gc_str) { +  if (facility == gc_str) {    old_level = gc_trace;    gc_trace = level;    }    else {    bad_arg_error("trace", Pike_sp-args, args, 2,    "trace facility identifier", Pike_sp-args+1,    "Bad argument 2 to trace(). Unknown trace facility.");    }    }    else {
pike.git/src/builtin.cmod:476:    */   PIKEFUN mapping(string:mixed) gc_parameters (void|mapping(string:mixed) params)    errname Pike.gc_parameters;    optflags OPT_SIDE_EFFECT;   {    struct pike_string *str;    struct svalue *set;    struct svalue get;       if (!params) { -  push_mapping (allocate_mapping (5)); -  params = Pike_sp - 1; +  push_mapping (params = allocate_mapping (5));    } -  else if (params->type != T_MAPPING) -  SIMPLE_BAD_ARG_ERROR ("Pike.gc_parameters", 1, "void|mapping"); +       #define HANDLE_PARAM(NAME, CHECK_AND_SET, GET) do { \    MAKE_CONST_STRING (str, NAME); \ -  if ((set = low_mapping_string_lookup (params->u.mapping, str))) { \ +  if ((set = low_mapping_string_lookup (params, str))) { \    CHECK_AND_SET; \    } \    else { \    GET; \ -  mapping_string_insert (params->u.mapping, str, &get); \ +  mapping_string_insert (params, str, &get); \    } \    } while (0)      #define HANDLE_FLOAT_FACTOR(NAME, VAR) \    HANDLE_PARAM (NAME, { \    if (set->type != T_FLOAT || \    set->u.float_number < 0.0 || set->u.float_number > 1.0) \    SIMPLE_BAD_ARG_ERROR ("Pike.gc_parameters", 1, \    "float between 0.0 and 1.0 for " NAME); \    VAR = set->u.float_number; \
pike.git/src/builtin.cmod:530:    get.u.integer = gc_enabled;    });    HANDLE_FLOAT_FACTOR ("garbage_ratio_low", gc_garbage_ratio_low);    HANDLE_FLOAT_FACTOR ("time_ratio", gc_time_ratio);    HANDLE_FLOAT_FACTOR ("garbage_ratio_high", gc_garbage_ratio_high);    HANDLE_FLOAT_FACTOR ("average_slowness", gc_average_slowness);      #undef HANDLE_PARAM   #undef HANDLE_FLOAT_FACTOR    -  REF_RETURN params->u.mapping; +  REF_RETURN params;   }      /*! @decl string ctime(int timestamp)    *!    *! Convert the output from a previous call to @[time()] into a readable    *! string containing the current year, month, day and time.    *!    *! Like @[localtime], this function might throw an error if the    *! ctime(2) call failed on the system. It's platform dependent what    *! time ranges that function can handle, e.g. Windows doesn't handle
pike.git/src/builtin.cmod:848:   {    RETURN multiset_get_flags(m) & MULTISET_WEAK;   }      /*! @decl program __empty_program(int|void line, string|void file)    */   PIKEFUN program __empty_program(int|void line, string|void file)    efun;    optflags OPT_EXTERNAL_DEPEND;   { -  if (line && line->type != T_INT) -  SIMPLE_BAD_ARG_ERROR("__empty_program", 1, "int|void"); -  else if (file && file->type != T_STRING) -  SIMPLE_BAD_ARG_ERROR("__empty_program", 2, "string|void"); -  else { +     struct program *prog = low_allocate_program(); -  if (file) ext_store_program_line (prog, line->u.integer, file->u.string); +  if (file) ext_store_program_line (prog, line?line->u.integer:0, file);    RETURN prog;   } - } +       /*! @decl string function_name(function f)    *!    *! Return the name of the function @[f].    *!    *! If @[f] is a global function defined in the runtime @expr{0@}    *! (zero) will be returned.    *!    *! @seealso    *! @[function_object()]
pike.git/src/builtin.cmod:1909:    CVAR INT32 set_start[256];    CVAR INT32 set_end[256];       static int replace_sortfun(struct tupel *a,struct tupel *b)    {    return DO_NOT_WARN((int)my_quick_strcmp(a->ind, b->ind));    }       /*! @decl void create(array(string)|void from, array(string)|void to)    */ -  PIKEFUN void create(array(string)|void from_, array(string)|void to_) +  PIKEFUN void create(array(string)|void from, array(string)|void to)    {    int i; -  struct array *from; -  struct array *to; +     if (!args) {    push_int(0);    return;    } -  if (!from_ || !to_) { +  if (!from || !to) {    Pike_error("Bad number of arguments to create().\n");    } -  from = from_->u.array; -  to = to_->u.array; +     if (from->size != to->size) {    Pike_error("Replace must have equal-sized from and to arrays.\n");    }    for (i = 0; i < (int)from->size; i++) {    if (from->item[i].type != PIKE_T_STRING) {    Pike_error("Replace: from array is not an array(string).\n");    }    if (to->item[i].type != PIKE_T_STRING) {    Pike_error("Replace: to array is not an array(string).\n");    }
pike.git/src/builtin.cmod:2198:    THIS->del = NULL;    }    if (THIS->to) {    free_string(THIS->to);    THIS->to = NULL;    }    }       /*! @decl void create(string|void del, string|void to)    */ -  PIKEFUN void create(string|void del_, string|void to_) +  PIKEFUN void create(string|void del, string|void to)    { -  struct pike_string *del; -  struct pike_string *to; -  +     /* Clean up... */    exit_single_string_replace_struct();    -  if (!del_) return; +  if (!del) return;    -  if (!to_) { +  if (!to) {    SIMPLE_BAD_ARG_ERROR("String.SingleReplace->create", 2, "string");    }    -  if (del_->u.string == to_->u.string) { +  if (del == to) {    /* No-op... */    return;    }    -  copy_shared_string(THIS->del, del = del_->u.string); -  copy_shared_string(THIS->to, to = to_->u.string); +  copy_shared_string(THIS->del, del); +  copy_shared_string(THIS->to, to);       if (del->len) {    THIS->mojt = simple_compile_memsearcher(del);    }    }       /*** replace function ***/    typedef char *(* replace_searchfunc)(void *,void *,size_t);       /*! @decl string `()(string str)
pike.git/src/builtin.cmod:2424:    INC_PCHARP( input, pos+1 );    input_left -= pos+1;    break;    }       while (input_left > 0) {    INT_TYPE oldi = i;    INT_TYPE w = 1;    INT_TYPE k;    for (k=bs->base; ; k+=bs->base) { -  INT_TYPE digit, t; +  INT_TYPE digit = 0, t;    if (input_left < 1 ||    (digit = bootstring_cp_to_digit( EXTRACT_PCHARP( input ) )) < 0) {    free_string_builder( &output );    Pike_error( "Invalid variable-length integer.\n" );    }    INC_PCHARP( input, 1 );    --input_left;    i += digit * w; /* fail on overflow... */    if (k <= bias + bs->tmin)    t = bs->tmin;
pike.git/src/builtin.cmod:2696:    /*! @decl static void create( int fast );    *!    *! If fast is true, do not request a new time from the system,    *! instead use the global current time variable.    *!    *! This will only work in callbacks, but can save significant amounts    *! of CPU.    */    PIKEFUN void create( int|void fast )    { -  THIS->hard_update = !fast; +  THIS->hard_update = !(fast && fast->u.integer);    }   }      /*! @endclass    */      /*! @class Timer    */   PIKECLASS Timer   {
pike.git/src/builtin.cmod:2750:    *!    *! If fast is specified, the timer will not do system calls to get    *! the current time but instead use the one maintained by pike. This    *! will result in faster but somewhat more inexact timekeeping.    *! Also, if your program never utilizes the pike event loop the pike    *! maintained current time never change.    */    PIKEFUN void create( int|void fast )    {    extern struct timeval current_time; -  THIS->hard_update = !fast; +  THIS->hard_update = !(fast || fast->u.integer);    if( THIS->hard_update )    GETTIMEOFDAY( &current_time );    THIS->last_time = current_time;    }   }      /*! @endclass    */      /*! @endmodule