pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.47 2001/06/25 22:19:18 mast Exp $ +  * $Id: builtin.cmod,v 1.48 2001/06/25 23:16:36 grubba 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:668:    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 = 0; +  THIS->pc = NULL;    THIS->lineno = 0;    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);
pike.git/src/builtin.cmod:691:       PIKEFUN string _sprintf(int c, mapping|void opts)    {    pop_n_elems(args);       push_text("backtrace_frame(");    if (THIS->pc) {    if (!THIS->filename) {    THIS->filename =    make_shared_string(get_line(THIS->pc, THIS->prog, &THIS->lineno)); +  } +  THIS->pc = NULL; +  }    if (THIS->prog) {    free_program(THIS->prog);    THIS->prog = NULL;    } -  } +  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) {    if (THIS->fun.u.object->prog) {
pike.git/src/builtin.cmod:784:    }       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 =    make_shared_string(get_line(THIS->pc, THIS->prog,    &THIS->lineno)); -  if (THIS->prog) { -  free_program(THIS->prog); -  THIS->prog = NULL; +     } -  +  THIS->pc = NULL;    } -  ref_push_string(THIS->filename); -  } else { -  push_int(0); -  } -  break; -  case 1: /* Linenumber */ -  if (THIS->pc) { -  if (!THIS->filename) { -  THIS->filename = -  make_shared_string(get_line(THIS->pc, THIS->prog, -  &THIS->lineno)); +     if (THIS->prog) {    free_program(THIS->prog);    THIS->prog = NULL;    } -  } +  if (i) { +  /* Linenumber */    push_int(THIS->lineno);    } else { -  +  /* Filename */ +  if (THIS->filename) { +  ref_push_string(THIS->filename); +  } else {    push_int(0);    } -  +  }    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;    }
pike.git/src/builtin.cmod:839:    }    /* NOT_REACHED */    break;    }    }    if (end_or_none) {    f_aggregate(1 + end - index);    }    }    +  PIKEFUN mixed `[]=(int index, mixed value) +  { +  INT32 numargs = 0; +  INT32 i; +  +  if (THIS->args) { +  numargs = THIS->args->size; +  } +  +  numargs += 3; +  +  if ((index < -numargs) || (index >= numargs)) { +  index_error("pike_frame->`[]=", Pike_sp-args, args, NULL, Pike_sp-args, +  "Index %"PRINTPIKEINT"d is out of array range 0 - %d,\n", +  index, numargs-1); +  } else if (index < 0) { +  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 = +  make_shared_string(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 (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 2: /* Function */ +  assign_svalue(&THIS->fun, value); +  break; +  default: /* Arguments */ +  assign_svalue(THIS->args->item + index - 3, value); +  break; +  } +  stack_swap(); +  pop_stack(); +  } +    };      /*! @endclass    */      /*! @decl array(array) backtrace()    *!    *! Get a description of the current call stack.    *!    *! The description is returned as an array with one entry for each call