pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:898:    /* 'A' - 'F' */    10, 11, 12, 13, 14, 15,       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,    /* 'a' - 'f' */    10, 11, 12, 13, 14, 15,   };      PMOD_EXPORT    PIKEFUN string(0..255) string2hex(string s) -  errname String.string2hex; +     optflags OPT_TRY_OPTIMIZE;   {    struct pike_string *hex;    unsigned char *p,*st = (unsigned char *)s->str;    int i, l;       if (s->size_shift)    Pike_error("Bad argument 1 to string2hex(), expected 8-bit string.\n");       hex = begin_shared_string(2 * s->len);
pike.git/src/builtin.cmod:931:   /*! @decl string hex2string(string hex)    *! @appears String.hex2string    *!    *! Convert a string of hexadecimal digits to binary data.    *!    *! @seealso    *! @[string2hex()]    */   PMOD_EXPORT   PIKEFUN string(0..255) hex2string(string hex) -  errname String.hex2string; +     optflags OPT_TRY_OPTIMIZE;   {    struct pike_string *s;    int tmp, i;    unsigned char *p, *q = (unsigned char *)hex->str;    int l = hex->len>>1;    if(hex->size_shift) Pike_error("Only hex digits allowed.\n");    if(hex->len&1) Pike_error("Can't have odd number of digits.\n");       s = begin_shared_string(l);
pike.git/src/builtin.cmod:960:      /*! @decl array(int) range(string s)    *! @appears String.range    *!    *! Returns the character range of a string in an array of two    *! elements. The first element contains the lower bound and the    *! second the upper. The precision is only 8 bits, so for wide    *! strings only character blocks are known.    */   PIKEFUN array(int) string_range(string s) -  errname String.range; +  errname range;    optflags OPT_TRY_OPTIMIZE;   {    int min, max;    check_string_range(s, 0, &min, &max);    pop_n_elems(args);    push_int(min);    push_int(max);    f_aggregate(2);   }   
pike.git/src/builtin.cmod:1179:    *! @member function(int:void) "done_cb"    *! This function is called when the gc is done and about to exit.    *! The argument is the same value as will be returned by gc().    *! @endmapping    *!    *! @seealso    *! @[gc], @[Debug.gc_status]    */   PMOD_EXPORT   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 (6));    params = Pike_sp[-1].u.mapping;    }
pike.git/src/builtin.cmod:1206:    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 ("Pike.gc_parameters", 1, \ +  SIMPLE_BAD_ARG_ERROR ("gc_parameters", 1, \    "float between 0.0 and 1.0 for " NAME); \    VAR = DO_NOT_WARN ((double) set->u.float_number); \    }, { \    SET_SVAL(get, T_FLOAT, 0, float_number, \    DO_NOT_WARN ((FLOAT_TYPE) VAR)); \    });       HANDLE_PARAM ("enabled", {    if (TYPEOF(*set) != T_INT || set->u.integer < -1 || set->u.integer > 1) -  SIMPLE_BAD_ARG_ERROR ("Pike.gc_parameters", 1, +  SIMPLE_BAD_ARG_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:1376:    *! occurs in the string @[haystack]. The special cases for the needle    *! @expr{""@} is that it occurs one time in the empty string, zero    *! times in a one character string and between every character    *! (length-1) in any other string.    *!    *! @seealso    *! @[search()], @[`/()]    */   PMOD_EXPORT   PIKEFUN int string_count(string haystack, string needle) -  errname String.count; +  errname count;    optflags OPT_TRY_OPTIMIZE;   {    ptrdiff_t c = 0;    ptrdiff_t i, j;       switch (needle->len)    {    case 0:    switch (haystack->len)    {
pike.git/src/builtin.cmod:1415:    RETURN DO_NOT_WARN((INT_TYPE)c);   }      /*! @decl string trim_whites (string s)    *! @belongs String    *!    *! Trim leading and trailing spaces and tabs from the string @[s].    */   PMOD_EXPORT   PIKEFUN string string_trim_whites (string s) -  errname String.trim_whites; +  errname trim_whites;    optflags OPT_TRY_OPTIMIZE;   {    ptrdiff_t start = 0, end = s->len;    int chr;    switch (s->size_shift) {   #define DO_IT(TYPE) \    { \    for (; start < s->len; start++) { \    chr = ((TYPE *) s->str)[start]; \    if (chr != ' ' && chr != '\t') break; \
pike.git/src/builtin.cmod:1465:    *! @note    *! Trailing and leading whitespace around \r and \n characters    *! is stripped as well (only useful if they're not in the @[whitespace] set).    *!    *! @note    *! This function is a lot faster with just one argument (i.e. the builtin    *! whitespace set has an optimised code path).    */   PMOD_EXPORT   PIKEFUN string string_normalize_space (string s, string|void whitespace) -  errname String.normalize_space; +  errname normalize_space;    optflags OPT_TRY_OPTIMIZE;   {    size_t len = s->len, wlen;    const void *src = s->str;    unsigned shift = s->size_shift, replspace;    const void *ws;    void *wstemp = 0;    struct string_builder sb;    unsigned foundspace = 0;   
pike.git/src/builtin.cmod:1596:      /*! @decl string trim_all_whites (string s)    *! @belongs String    *!    *! Trim leading and trailing white spaces characters (space, tab,    *! newline, carriage return, form feed, vertical tab and all the    *! white spaces defined in Unicode) from the string @[s].    */   PMOD_EXPORT   PIKEFUN string string_trim_all_whites (string s) -  errname String.trim_all_whites; +  errname trim_all_whites;    optflags OPT_TRY_OPTIMIZE;   {    ptrdiff_t start = 0, end = s->len;    int chr;    switch (s->size_shift) {      #define DO_IT(TYPE,CASE) \    { \    for (; start < end; start++) { \    chr = ((TYPE *) s->str)[start]; \
pike.git/src/builtin.cmod:1648:    *!    *! @note    *! Currently returns the empty string (@expr{""@})    *! if @[verbose] is zero.    *!    *! @note    *! The formatting and contents of the result    *! may vary between different versions of Pike.    */   PIKEFUN string string_status(int verbose) -  errname String.status; +  errname status;   {    RETURN add_string_status(verbose);   }      /*! @decl int implements(program prog, program api)    *! @belongs Program    *!    *! Returns 1 if @[prog] implements @[api].    */   PMOD_EXPORT   PIKEFUN int program_implements(program prog, program api) -  errname Program.implements; +  errname implements;    optflags OPT_TRY_OPTIMIZE;   {    RETURN implements(prog, api);   }      /*! @decl int inherits(program|object child, program parent)    *! @belongs Program    *!    *! Returns 1 if @[child] has inherited @[parent].    */   PMOD_EXPORT   PIKEFUN int program_inherits(program|object child, program parent) -  errname Program.inherits; +  errname inherits;    optflags OPT_TRY_OPTIMIZE;   {    struct program *p = program_from_svalue(child);       if (!p) -  SIMPLE_ARG_TYPE_ERROR("Program.inherits", 1, "program|object"); +  SIMPLE_ARG_TYPE_ERROR("inherits", 1, "program|object");    RETURN low_get_storage(p, parent) != -1;   }      /*! @decl string defined(program p)    *! @belongs Program    *!    *! Returns a string with filename and linenumber describing where    *! the program @[p] was defined.    *!    *! The returned string is of the format @expr{"filename:linenumber"@}.    *!    *! If it cannot be determined where the program was defined, @expr{0@}    *! (zero) will be returned.    */   PMOD_EXPORT   PIKEFUN string program_defined(program p) -  errname Program.defined; +  errname defined;    optflags OPT_TRY_OPTIMIZE;   {    INT_TYPE line;    struct pike_string *tmp = low_get_program_line(p, &line);       pop_n_elems(args);       if (tmp) {    push_string(tmp);    if(line >= 1)
pike.git/src/builtin.cmod:1740:    *! The string @[s] contains characters >= 65536.    *! @endint    *!    *! @note    *! It is possible that a future version of Pike may return    *! further values. In particular the width @expr{7@} seems    *! like it could be useful.    */   PMOD_EXPORT   PIKEFUN int(8 .. 8)|int(16 .. 16)|int(32 .. 32) string_width(string s) -  errname String.width; +  errname width;    optflags OPT_TRY_OPTIMIZE;   {    RETURN 8 * (1 << s->size_shift);   }      /*! @decl mixed m_delete(object|mapping map, mixed index)    *!    *! If @[map] is an object that implements @[lfun::_m_delete()],    *! that function will be called with @[index] as its single argument.    *!
pike.git/src/builtin.cmod:2673:    break;    case 2: /* Function */    push_svalue(&THIS->_fun);    break;    default: /* Arguments */    {    if ((i > 2) && (THIS->args) && (i-3 < THIS->args->size)) {    push_svalue(THIS->args->item + (i - 3));    break;    } -  bad_arg_error("backtrace_frame->`[]", Pike_sp-args, args, 1, +  bad_arg_error("`[]", Pike_sp-args, args, 1,    "int(0..)", Pike_sp-args,    "Bad argument 1 to backtrace_frame->`[](): "    "Expected int(0..%d)\n",    numargs + 2);    }    /* NOT_REACHED */    break;    }    }    if (end_or_none) {
pike.git/src/builtin.cmod:2719:    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("backtrace_frame->`[]=", 2, -  "string|int(0..0)"); +  SIMPLE_BAD_ARG_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("backtrace_frame->`[]=", 2, "int(1..)"); +  SIMPLE_BAD_ARG_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);
pike.git/src/builtin.cmod:3535:    *    * 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;    if (TYPEOF(*from_arg) != T_ARRAY) { -  SIMPLE_BAD_ARG_ERROR("Replace", 1, +  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) { -  SIMPLE_BAD_ARG_ERROR("Replace", 2, "array(string)|string"); +  SIMPLE_BAD_ARG_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. */    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, +  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"); +  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)
pike.git/src/builtin.cmod:3676:    THIS->del = NULL;    }    if (THIS->to) {    free_string(THIS->to);    THIS->to = NULL;    }       if (!del) return;       if (!to) { -  SIMPLE_BAD_ARG_ERROR("String.SingleReplace->create", 2, "string"); +  SIMPLE_BAD_ARG_ERROR("replace", 2, "string");    }       if (del == to) {    /* No-op... */    return;    }       copy_shared_string(THIS->del, del);    copy_shared_string(THIS->to, to);