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.111 2003/01/26 19:00:53 mirar Exp $ + || $Id: builtin.cmod,v 1.112 2003/01/31 01:59:49 mast Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "opcodes.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"
pike.git/src/builtin.cmod:25:   #include <ctype.h>   #include "module_support.h"   #include "cyclic.h"   #include "bignum.h"   #include "main.h"   #include "operators.h"   #include "builtin_functions.h"   #include "fsort.h"   #include "port.h"   #include "gc.h" + #include <assert.h>      /*! @decl array(array(int|string)) describe_program(program p)    *! @belongs Debug    *!    *! Debug function for showing the symbol table of a program.    */   PIKEFUN array(array(int|string)) _describe_program(mixed x)    efun;   {    struct program *p;
pike.git/src/builtin.cmod:1065:   /*! @module Pike    */      /*! @class BacktraceFrame    */      PIKECLASS backtrace_frame   {    PIKEVAR mixed fun;    PIKEVAR array args; +  +  /* These are cleared when filename and lineno has been initialized +  * from them. */    CVAR struct program *prog; /* FIXME: Ought to be a private pikevar... */    CVAR PIKE_OPCODE_T *pc; -  +  +  /* These two are considered to be uninitialized from prog, pc and +  * fun as long as lineno == -1. */    CVAR struct pike_string *filename;    CVAR INT32 lineno;       INIT    {    THIS->fun.type = T_INT;    THIS->fun.u.integer = 0;    THIS->prog = NULL;    THIS->pc = NULL; -  THIS->lineno = 0; +  THIS->lineno = -1;    THIS->args = NULL;    THIS->filename = NULL;    }       EXIT    {    if (THIS->prog) {    free_program(THIS->prog);    THIS->prog = NULL;    }    if (THIS->args) {    free_array(THIS->args);    THIS->args = NULL;    }    if (THIS->filename) {    free_string(THIS->filename);    THIS->filename = NULL;    }    THIS->pc = NULL; -  THIS->lineno = 0; +  THIS->lineno = -1;    free_svalue(&THIS->fun);    THIS->fun.type = T_INT;    THIS->fun.u.integer = 0;    }       PIKEFUN int(0..1) _is_type(string t)    {    INT_TYPE res = (t == findstring("array"));    pop_n_elems(args);    push_int(res);    }    -  +  static void fill_in_file_and_line() +  { +  struct pike_string *file; +  assert (THIS->lineno == -1); +  +  if (THIS->pc && THIS->prog) { +  file = low_get_line(THIS->pc, THIS->prog, &THIS->lineno); +  THIS->pc = NULL; +  } +  else if (THIS->fun.type == PIKE_T_FUNCTION) +  file = low_get_function_line (THIS->fun.u.object, THIS->fun.subtype, +  &THIS->lineno); +  else if (THIS->prog) +  file = low_get_program_line (THIS->prog, &THIS->lineno); +  +  if (!THIS->filename) THIS->filename = file; +  else free_string (file); +  +  if (THIS->prog) { +  free_program(THIS->prog); +  THIS->prog = NULL; +  } +  } +     PIKEFUN string _sprintf(int c, mapping|void opts)    {    pop_n_elems(args);       if (c != 'O') {    push_undefined ();    return;    }       push_text("backtrace_frame("); -  if (THIS->pc) { -  if (!THIS->filename) { -  THIS->filename = get_line(THIS->pc, THIS->prog, &THIS->lineno); -  } -  THIS->pc = NULL; -  } -  if (THIS->prog) { -  free_program(THIS->prog); -  THIS->prog = NULL; -  } +  +  if (THIS->lineno == -1) fill_in_file_and_line(); +     if (THIS->filename) {    ref_push_string(THIS->filename);    push_text(":");    push_int(THIS->lineno);    push_text(", ");    f_add(4);    } else {    push_text("Unknown file, ");    }    if (THIS->fun.type == PIKE_T_FUNCTION) {
pike.git/src/builtin.cmod:1218:    }       if (end >= numargs) {    end = numargs-1;    }    }       for (i = index; i <= end; i++) {    switch(i) {    case 0: /* Filename */ -  case 1: /* Linenumber */ -  if (THIS->pc) { -  if (!THIS->filename) { -  THIS->filename = get_line(THIS->pc, THIS->prog, &THIS->lineno); -  } -  THIS->pc = NULL; -  } -  if (THIS->prog) { -  free_program(THIS->prog); -  THIS->prog = NULL; -  } -  if (i) { -  /* Linenumber */ -  push_int(THIS->lineno); -  } else { -  /* Filename */ +  if (THIS->lineno == -1) fill_in_file_and_line();    if (THIS->filename) {    ref_push_string(THIS->filename);    } else {    push_int(0);    } -  } +     break; -  +  case 1: /* Linenumber */ +  if (THIS->lineno == -1) fill_in_file_and_line(); +  push_int(THIS->lineno); +  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,
pike.git/src/builtin.cmod:1290:    index += numargs;    }       if (args > 2) {    pop_n_elems(args - 2);    args = 2;    }       switch(index) {    case 0: /* Filename */ -  case 1: /* Linenumber */ -  /* First make sure we have line-number info. */ -  if (THIS->pc) { -  if (!THIS->filename) { -  THIS->filename = get_line(THIS->pc, THIS->prog, &THIS->lineno); -  } -  THIS->pc = NULL; -  } -  if (THIS->prog) { -  free_program(THIS->prog); -  THIS->prog = NULL; -  } -  if (index) { -  /* Linenumber */ -  if (value->type != PIKE_T_INT) { -  SIMPLE_BAD_ARG_ERROR("backtrace_frame->`[]=", 2, "int(1..)"); -  } -  THIS->lineno = value->u.integer; -  } else { -  /* Filename */ +  if (THIS->lineno == -1) fill_in_file_and_line();    if (value->type != PIKE_T_STRING) {    if ((value->type != PIKE_T_INT) ||    (value->u.integer)) {    SIMPLE_BAD_ARG_ERROR("backtrace_frame->`[]=", 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 (value->type != PIKE_T_INT) { +  SIMPLE_BAD_ARG_ERROR("backtrace_frame->`[]=", 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);    break;    }    stack_swap();    pop_stack();    }   
pike.git/src/builtin.cmod:1633:       if( str->str.s )    {    str2 = OBJ2_BUFFER( res );       if( str2->str.s ) free_string_builder( &str2->str );    *str2 = *str;    init_string_builder_alloc( &str2->str,    str->str.malloced,    str->str.s->size_shift ); +  /* We know the actual shift. */ +  str2->str.known_shift = str->str.s->size_shift;    MEMCPY( (void *)str2->str.s, (void *)str->str.s,    str->str.malloced+sizeof(struct pike_string));    }    apply( res, "add", 1 );    RETURN res;    }       /*! @decl int add(string ... data)    *!    *! Adds @[data] to the buffer. Returns the size of the buffer.
pike.git/src/builtin.cmod:1661:    int sum = 0;    int shift = 0;    for (j=0; j < args; j++) {    struct pike_string *a = Pike_sp[j-args].u.string;    sum += a->len;    shift |= a->size_shift;    }    if (sum < str->initial) {    sum = str->initial;    } -  init_string_builder_alloc(&str->str, sum, shift & ~(shift>>1)); +  shift = shift & ~(shift >> 1); +  init_string_builder_alloc(&str->str, sum, shift); +  /* We know it will be a string that really is this wide. */ +  str->str.known_shift = shift;    }       for( j = 0; j<args; j++ )    {    struct pike_string *a = Pike_sp[j-args].u.string;    string_builder_shared_strcat( &str->str, a );    }       if (str->str.s) {    RETURN str->str.s->len;