pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*\   ||| 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.   \*/   /**/   #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.434 2002/08/06 14:18:57 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.435 2002/08/15 14:49:19 marcus Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:98:    *! like @code{int a[10]=allocate(10);@} (and it isn't possible either) like    *! in C, just @code{array(int) a=allocate(10);@} will do.    *!    *! @seealso    *! @[sizeof()], @[arrayp()], @[allocate()]    */   PMOD_EXPORT void debug_f_aggregate(INT32 args)   {    struct array *a;   #ifdef PIKE_DEBUG -  if(args < 0) fatal("Negative args to f_aggregate() (%d)\n",args); +  if(args < 0) Pike_fatal("Negative args to f_aggregate() (%d)\n",args);   #endif       a=aggregate_array(args);    push_array(a); /* beware, macro */   }         /*! @decl int hash_7_0(string s)    *! @decl int hash_7_0(string s, int max)    *!
pike.git/src/builtin_functions.c:310:      #define DO_LOWER_CASE(C) do {\    INT32 c = C; \    struct case_info *ci = find_ci(c); \    if (ci) { \    switch(ci->mode) { \    case CIM_NONE: case CIM_LOWERDELTA: break; \    case CIM_UPPERDELTA: C = c + ci->data; break; \    case CIM_CASEBIT: C = c | ci->data; break; \    case CIM_CASEBITOFF: C = ((c - ci->data) | ci->data) + ci->data; break; \ -  default: fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \ +  default: Pike_fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \    } \    } \    } while(0)      #define DO_LOWER_CASE_SHIFT0(C) do {\    INT32 c = C; \    struct case_info *ci = find_ci_shift0(c); \    if (ci) { \    switch(ci->mode) { \    case CIM_NONE: case CIM_LOWERDELTA: break; \    case CIM_UPPERDELTA: C = c + ci->data; break; \    case CIM_CASEBIT: C = c | ci->data; break; \    case CIM_CASEBITOFF: C = ((c - ci->data) | ci->data) + ci->data; break; \ -  default: fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \ +  default: Pike_fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \    } \    } \    } while(0)      #define DO_UPPER_CASE(C) do {\    INT32 c = C; \    struct case_info *ci = find_ci(c); \    if (ci) { \    switch(ci->mode) { \    case CIM_NONE: case CIM_UPPERDELTA: break; \    case CIM_LOWERDELTA: C = c - ci->data; break; \    case CIM_CASEBIT: C = c & ~ci->data; break; \    case CIM_CASEBITOFF: C = ((c - ci->data)& ~ci->data) + ci->data; break; \ -  default: fatal("upper_case(): Unknown case_info mode: %d\n", ci->mode); \ +  default: Pike_fatal("upper_case(): Unknown case_info mode: %d\n", ci->mode); \    } \    } \    } while(0)      #define DO_UPPER_CASE_SHIFT0(C) do {\    INT32 c = C; \    struct case_info *ci = find_ci_shift0(c); \    if (ci) { \    switch(ci->mode) { \    case CIM_NONE: case CIM_UPPERDELTA: break; \    case CIM_LOWERDELTA: C = c - ci->data; break; \    case CIM_CASEBIT: C = c & ~ci->data; break; \    case CIM_CASEBITOFF: C = ((c - ci->data)& ~ci->data) + ci->data; break; \ -  default: fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \ +  default: Pike_fatal("lower_case(): Unknown case_info mode: %d\n", ci->mode); \    } \    } \    } while(0)      /*! @decl string lower_case(string s)    *!    *! Convert a string to lower case.    *!    *! @returns    *! Returns a copy of the string @[s] with all upper case characters
pike.git/src/builtin_functions.c:400:    while(i--) {    DO_LOWER_CASE(str[i]);    }    } else if (orig->size_shift == 2) {    p_wchar2 *str = STR2(ret);       while(i--) {    DO_LOWER_CASE(str[i]);    }    } else { -  fatal("lower_case(): Bad string shift:%d\n", orig->size_shift); +  Pike_fatal("lower_case(): Bad string shift:%d\n", orig->size_shift);    }       pop_n_elems(args);    push_string(end_shared_string(ret));   }      /*! @decl string upper_case(string s)    *!    *! Convert a string to upper case.    *!
pike.git/src/builtin_functions.c:454:    while(i--) {    DO_UPPER_CASE(str[i]);    }    } else if (orig->size_shift == 2) {    p_wchar2 *str = STR2(ret);       while(i--) {    DO_UPPER_CASE(str[i]);    }    } else { -  fatal("lower_case(): Bad string shift:%d\n", orig->size_shift); +  Pike_fatal("lower_case(): Bad string shift:%d\n", orig->size_shift);    }       pop_n_elems(args);    push_string(end_shared_string(ret));       if (widen) {    /* Widen the string, and replace any 0xb5's or 0xff's. */    orig = Pike_sp[-1].u.string;    ret = begin_wide_shared_string(orig->len, 1);   
pike.git/src/builtin_functions.c:636:    case 2:    {    p_wchar2 *str = STR2(haystack);    while (start < haystack->len) {    if (str[start] == (p_wchar2)val) break;    start++;    }    }    break;    default: -  fatal("search(): Unsupported string shift: %d!\n", +  Pike_fatal("search(): Unsupported string shift: %d!\n",    haystack->size_shift);    break;    }    if (start >= haystack->len) {    start = -1;    }    } else {    SIMPLE_BAD_ARG_ERROR("search", 2, "string | int");    }    pop_n_elems(args);
pike.git/src/builtin_functions.c:1079:    pop_n_elems(args-1);    Pike_sp[-1].u.integer=Pike_sp[-1].subtype;    Pike_sp[-1].subtype=NUMBER_NUMBER;    }   }      static int generate_zero_type(node *n)   {    if(count_args(CDR(n)) != 1) return 0;    if(do_docode(CDR(n),DO_NOT_COPY) != 1) -  fatal("Count args was wrong in generate_zero_type().\n"); +  Pike_fatal("Count args was wrong in generate_zero_type().\n");    emit0(F_ZERO_TYPE);    return 1;   }      /*    * Some wide-strings related functions    */      /*! @decl string string_to_unicode(string s)    *!
pike.git/src/builtin_functions.c:1123:    case 0:    /* Just 8bit characters */    len = in->len * 2;    out = begin_shared_string(len);    if (len) {    MEMSET(out->str, 0, len); /* Clear the upper (and lower) byte */   #ifdef PIKE_DEBUG    if (d_flag) {    for(i = len; i--;) {    if (out->str[i]) { -  fatal("MEMSET didn't clear byte %ld of %ld\n", +  Pike_fatal("MEMSET didn't clear byte %ld of %ld\n",    PTRDIFF_T_TO_LONG(i+1),    PTRDIFF_T_TO_LONG(len));    }    }    }   #endif /* PIKE_DEBUG */    for(i = in->len; i--;) {    out->str[i * 2 + 1] = in->str[i];    }    }
pike.git/src/builtin_functions.c:1211:    out->str[j] = 0xdc | ((c >> 8) & 0x03);    j -= 2;    c >>= 10;    c |= 0xd800;    }    out->str[j + 1] = c & 0xff;    out->str[j] = c >> 8;    }   #ifdef PIKE_DEBUG    if (j) { -  fatal("string_to_unicode(): Indexing error: len:%ld, j:%ld.\n", +  Pike_fatal("string_to_unicode(): Indexing error: len:%ld, j:%ld.\n",    PTRDIFF_T_TO_LONG(len), PTRDIFF_T_TO_LONG(j));    }   #endif /* PIKE_DEBUG */    out = end_shared_string(out);    }    break;    default:    Pike_error("string_to_unicode(): Bad string shift: %d!\n", in->size_shift);    break;    }
pike.git/src/builtin_functions.c:1509:    out->str[j++] = 0x80 | ((c >> 30) & 0x3f);    out->str[j++] = 0x80 | ((c >> 24) & 0x3f);    out->str[j++] = 0x80 | ((c >> 18) & 0x3f);    out->str[j++] = 0x80 | ((c >> 12) & 0x3f);    out->str[j++] = 0x80 | ((c >> 6) & 0x3f);    out->str[j++] = 0x80 | (c & 0x3f);    }    }   #ifdef PIKE_DEBUG    if (len != j) { -  fatal("string_to_utf8(): Calculated and actual lengths differ: " +  Pike_fatal("string_to_utf8(): Calculated and actual lengths differ: "    "%ld != %ld\n",    PTRDIFF_T_TO_LONG(len), PTRDIFF_T_TO_LONG(j));    }   #endif /* PIKE_DEBUG */    out = end_shared_string(out);    pop_n_elems(args);    push_string(out);   }      /*! @decl string utf8_to_string(string s)
pike.git/src/builtin_functions.c:1666:    }    while(cont--) {    unsigned INT32 c2 = ((unsigned char *)(in->str))[++i] & 0x3f;    c = (c << 6) | c2;    }    }    low_set_index(out, j++, c);    }   #ifdef PIKE_DEBUG    if (j != len) { -  fatal("utf8_to_string(): Calculated and actual lengths differ: %d != %d\n", +  Pike_fatal("utf8_to_string(): Calculated and actual lengths differ: %d != %d\n",    len, j);    }   #endif /* PIKE_DEBUG */    out = end_shared_string(out);    pop_n_elems(args);    push_string(out);   }      /*! @decl string __parse_pike_type(string t)    */
pike.git/src/builtin_functions.c:1898:    * pointers all the way. */    int i;    for (i = 0; i < compilation_depth; i++, state = state->previous)    state->new_program->flags |= PROGRAM_USES_PARENT | PROGRAM_NEEDS_PARENT;    return NULL;    }    else {    int level;   #ifdef PIKE_DEBUG    if (CDR (n)->u.sval.type != T_INT || CDR (n)->u.sval.u.integer < 0) -  fatal ("The type check for this_object() failed.\n"); +  Pike_fatal ("The type check for this_object() failed.\n");   #endif    level = CDR (n)->u.sval.u.integer;    if (level > compilation_depth) {    my_yyerror ("There is no surrounding class %d levels out.", level);    return NULL;    }    for (; level > 0; level--, state = state->previous)    state->new_program->flags |= PROGRAM_USES_PARENT | PROGRAM_NEEDS_PARENT;    id = state->new_program->id;    }
pike.git/src/builtin_functions.c:1938:    int level;       if (CDR (n)) {    struct program_state *state = Pike_compiler;    if (CDR (n)->token != F_CONSTANT)    /* Not a constant expression. Make a call to f_this_object. */    return 0;    else {   #ifdef PIKE_DEBUG    if (CDR (n)->u.sval.type != T_INT || CDR (n)->u.sval.u.integer < 0) -  fatal ("The type check for this_object() failed.\n"); +  Pike_fatal ("The type check for this_object() failed.\n");   #endif    level = CDR (n)->u.sval.u.integer;   #ifdef PIKE_DEBUG    if (level > compilation_depth) -  fatal ("this_object level too high. " +  Pike_fatal ("this_object level too high. "    "Expected this to be caught by optimize_this_object.\n");   #endif    }    }    else level = 0;       emit1(F_THIS_OBJECT, level);    return 1;   }   
pike.git/src/builtin_functions.c:4322:       get_all_args("parse_format", args, "%W", &s);       len = low_parse_format(STR0(s), s->len);    if (len != s->len) {    Pike_error("parse_format(): Unexpected %%} in format string at offset %ld\n",    PTRDIFF_T_TO_LONG(len));    }   #ifdef PIKE_DEBUG    if (Pike_sp[-1].type != T_ARRAY) { -  fatal("parse_format(): Unexpected result from low_parse_format()\n"); +  Pike_fatal("parse_format(): Unexpected result from low_parse_format()\n");    }   #endif /* PIKE_DEBUG */    a = (--Pike_sp)->u.array;    debug_malloc_touch(a);       pop_n_elems(args);    push_array(a);   }      
pike.git/src/builtin_functions.c:5004:       for (j = cmptbl->item[i].u.array->size; j--;)    {    int x = inner[j].u.integer;      #ifdef DIFF_DEBUG    fprintf(stderr, "DIFF: j=%d, x=%d\n", j, x);   #endif /* DIFF_DEBUG */   #ifdef PIKE_DEBUG    if (x >= blen) { -  fatal("diff_longest_sequence(): x:%d >= blen:%d\n", x, blen); +  Pike_fatal("diff_longest_sequence(): x:%d >= blen:%d\n", x, blen);    } else if (x < 0) { -  fatal("diff_longest_sequence(): x:%d < 0\n", x); +  Pike_fatal("diff_longest_sequence(): x:%d < 0\n", x);    }   #endif /* PIKE_DEBUG */    if (!marks[x]) {    int pos;       if (top && x<=stack[top-1]->x) {    /* Find the insertion point. */    pos = diff_ponder_stack(x, stack, top);    if (pos != top) {    /* Not on the stack anymore. */
pike.git/src/builtin_functions.c:5047:    {    j = 0;    x = inner->u.integer;    }      #ifdef DIFF_DEBUG    fprintf(stderr, "DIFF: New j=%d, x=%d\n", j, x);   #endif /* DIFF_DEBUG */   #ifdef PIKE_DEBUG    if (x >= blen) { -  fatal("diff_longest_sequence(): x:%d >= blen:%d\n", x, blen); +  Pike_fatal("diff_longest_sequence(): x:%d >= blen:%d\n", x, blen);    } else if (x < 0) { -  fatal("diff_longest_sequence(): x:%d < 0\n", x); +  Pike_fatal("diff_longest_sequence(): x:%d < 0\n", x);    }   #endif /* PIKE_DEBUG */       /* Put x on the stack. */    marks[x] = 1;    if (pos == top)    {   #ifdef DIFF_DEBUG    fprintf(stderr, "DIFF: New top element\n");   #endif /* DIFF_DEBUG */
pike.git/src/builtin_functions.c:5314:    }    SIMPLE_OUT_OF_MEMORY_ERROR("diff_dyn_longest_sequence",    sizeof(struct array) +    sz*sizeof(struct svalue));    }       i = 0;    while(dml) {   #ifdef PIKE_DEBUG    if (i >= sz) { -  fatal("Consistency error in diff_dyn_longest_sequence()\n"); +  Pike_fatal("Consistency error in diff_dyn_longest_sequence()\n");    }   #endif /* PIKE_DEBUG */   #ifdef DIFF_DEBUG    fprintf(stderr, " %02d: %d\n", i, dml->x);   #endif /* DIFF_DEBUG */    res->item[i].type = T_INT;    res->item[i].subtype = 0;    res->item[i].u.integer = dml->x;    dml = dml->prev;    i++;    }   #ifdef PIKE_DEBUG    if (i != sz) { -  fatal("Consistency error in diff_dyn_longest_sequence()\n"); +  Pike_fatal("Consistency error in diff_dyn_longest_sequence()\n");    }   #endif /* PIKE_DEBUG */       dml_free_pools(dml_pool);    return(res);   }      static struct array* diff_build(struct array *a,    struct array *b,    struct array *seq)
pike.git/src/builtin_functions.c:6158:    *! @seealso    *! @[`/()], @[`*()], @[`+()], @[`-()], @[everynth()]    */   PMOD_EXPORT void f_splice(INT32 args)   {    struct array *out;    INT32 size=0x7fffffff;    INT32 i,j,k;      #ifdef PIKE_DEBUG -  if(args < 0) fatal("Negative args to f_splice()\n"); +  if(args < 0) Pike_fatal("Negative args to f_splice()\n");   #endif       for(i=0;i<args;i++)    if (Pike_sp[i-args].type!=T_ARRAY)    SIMPLE_BAD_ARG_ERROR("splice", i+1, "array");    else    if (Pike_sp[i-args].u.array->size < size)    size=Pike_sp[i-args].u.array->size;       out=allocate_array(args * size);
pike.git/src/builtin_functions.c:6205:    *! @[splice()], @[`/()]    */   void f_everynth(INT32 args)   {    INT32 k,n=2;    INT32 start=0;    struct array *a;    struct array *ina;    INT32 size=0;   #ifdef PIKE_DEBUG -  if(args < 0) fatal("Negative args to f_everynth()\n"); +  if(args < 0) Pike_fatal("Negative args to f_everynth()\n");   #endif       check_all_args("everynth", args,    BIT_ARRAY, BIT_INT | BIT_VOID, BIT_INT | BIT_VOID , 0);       switch(args)    {    default:    case 3:    start=Pike_sp[2-args].u.integer;
pike.git/src/builtin_functions.c:6250:   PMOD_EXPORT void f_transpose(INT32 args)   {    struct array *out;    struct array *in;    struct array *outinner;    INT32 sizeininner=0,sizein=0;    INT32 inner=0;    INT32 j,i;    TYPE_FIELD type=0;   #ifdef PIKE_DEBUG -  if(args < 0) fatal("Negative args to f_transpose()\n"); +  if(args < 0) Pike_fatal("Negative args to f_transpose()\n");   #endif       if (args<1)    SIMPLE_TOO_FEW_ARGS_ERROR("transpose", 1);       if (Pike_sp[-args].type!=T_ARRAY)    SIMPLE_BAD_ARG_ERROR("transpose", 1, "array(array)");       in=Pike_sp[-args].u.array;    sizein=in->size;