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.160 2004/06/02 00:08:34 nilsson Exp $ + || $Id: builtin.cmod,v 1.161 2004/09/02 14:34:59 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:398:    *! @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;    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:477:   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; +  params = Pike_sp[-1].u.mapping;    } -  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:854:   }      /*! @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->u.integer, 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.
pike.git/src/builtin.cmod:1921:    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_) { +  /* FIXME: Why are from and to declared |void, when they aren't allowed +  * to be void? +  * /grubba 2004-09-02 +  */ +  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");    }       if( (from->type_field & ~BIT_STRING) &&    (array_fix_type_field(from) & ~BIT_STRING) )    SIMPLE_BAD_ARG_ERROR("Replace", 1, "array(string)");       if( (to->type_field & ~BIT_STRING) &&    (array_fix_type_field(to) & ~BIT_STRING) )
pike.git/src/builtin.cmod:2224:    free_string(THIS->del);    THIS->del = NULL;    }    if (THIS->to) {    free_string(THIS->to);    THIS->to = NULL;    }    }       /*! @decl void create(string|void from, string|void to) +  *! +  *! @note +  *! May be called with either zero or two arguments.    */ -  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)