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.228 2009/06/23 16:26:16 grubba Exp $ + || $Id: builtin.cmod,v 1.229 2009/06/24 11:35:46 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:1466:    */      /*! @module Pike    */      /*! @class BacktraceFrame    */      PIKECLASS backtrace_frame   { -  PIKEVAR mixed fun; +  PIKEVAR mixed _fun flags ID_PROTECTED|ID_PRIVATE; + #ifdef PIKE_DEBUG +  PIKEVAR program oprog flags ID_PROTECTED|ID_PRIVATE; + #endif    PIKEVAR array args;    -  /* These are cleared when filename and lineno has been initialized +  /* These are cleared when filename and lineno have been initialized    * from them. */    PIKEVAR program prog flags ID_PROTECTED|ID_PRIVATE;    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
pike.git/src/builtin.cmod:1497:    gc_trivial;    {    if (THIS->filename) {    free_string(THIS->filename);    THIS->filename = NULL;    }    THIS->pc = NULL;    THIS->lineno = -1;    }    +  PIKEFUN mixed `fun() +  { +  push_svalue(&THIS->_fun); +  } +  +  PIKEFUN void `fun=(mixed val) +  { +  /* FIXME: Should we allow this at all? +  * Linenumber info etc won't match. +  */ + #ifdef PIKE_DEBUG +  if ((val->type == T_FUNCTION) && (val->subtype != FUNCTION_BUILTIN)) { +  assign_short_svalue((union anything *)&THIS->oprog, +  (union anything *)&val->u.object->prog, T_PROGRAM); +  } + #endif +  assign_svalue(&THIS->_fun, val); +  } +     /*! @decl int(0..1) _is_type(string t)    *! This object claims to be an array for backward compatibility.    */    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 = NULL;    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, +  else if (THIS->_fun.type == PIKE_T_FUNCTION) { + #ifdef PIKE_DEBUG +  if (THIS->_fun.u.object->prog && +  THIS->_fun.u.object->prog != THIS->oprog) { +  struct identifier *id = ID_FROM_INT(THIS->oprog, THIS->_fun.subtype); +  /* FIXME: Dump dmalloc info for the object? */ +  Pike_fatal("Lost track of function pointer! Function name was %s.\n", +  id->name?id->name->str:"<no name>"); +  } + #endif +  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 (file) {    if (!THIS->filename) THIS->filename = file;    else free_string (file);    }
pike.git/src/builtin.cmod:1559:       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) { -  push_svalue(&THIS->fun); +  if (THIS->_fun.type == PIKE_T_FUNCTION) { +  if (THIS->_fun.u.object->prog) { + #ifdef PIKE_DEBUG +  if (THIS->_fun.u.object->prog != THIS->oprog) { +  struct identifier *id = ID_FROM_INT(THIS->oprog, THIS->_fun.subtype); +  /* FIXME: Dump dmalloc info for the object? */ +  Pike_fatal("Lost track of function pointer! Function name was %s.\n", +  id->name?id->name->str:"<no name>"); +  } + #endif +  push_svalue(&THIS->_fun);    f_function_name(1);    push_text("(), ");    f_add(2);    } else { -  free_svalue(&THIS->fun); -  THIS->fun.type = PIKE_T_INT; -  THIS->fun.u.integer = 0; -  THIS->fun.subtype = NUMBER_DESTRUCTED; +  free_svalue(&THIS->_fun); +  THIS->_fun.type = PIKE_T_INT; +  THIS->_fun.u.integer = 0; +  THIS->_fun.subtype = NUMBER_DESTRUCTED;    push_text("destructed_function(), ");    }    } else {    push_text("destructed_function(), ");    }       if (THIS->args) {    push_text("Args: ");    push_int(THIS->args->size);    f_add(2);
pike.git/src/builtin.cmod:1656:    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); +  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,    "int(0..)", Pike_sp-args,    "Bad argument 1 to backtrace_frame->`[](): "
pike.git/src/builtin.cmod:1736:    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); +  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:1838:    res->item[size].type = PIKE_T_OBJECT;    res->item[size].subtype = 0;       bf = OBJ2_BACKTRACE_FRAME(o);       if ((bf->prog = f->context->prog)) {    add_ref(bf->prog);    bf->pc = f->pc;    }    -  if ((bf->fun.u.object = f->current_object) && -  (bf->fun.u.object->prog)) { -  add_ref(bf->fun.u.object); -  bf->fun.subtype = CHECK_IDREF_RANGE(f->fun, f->current_object->prog); -  bf->fun.type = PIKE_T_FUNCTION; +  if ((bf->_fun.u.object = f->current_object) && +  (bf->_fun.u.object->prog)) { +  add_ref(bf->_fun.u.object); + #ifdef PIKE_DEBUG +  add_ref(bf->oprog = bf->_fun.u.object->prog); + #endif +  bf->_fun.subtype = CHECK_IDREF_RANGE(f->fun, f->current_object->prog); +  bf->_fun.type = PIKE_T_FUNCTION;    function = ID_FROM_INT(f->current_object->prog, f->fun);    } else { -  bf->fun.u.integer = 0; -  bf->fun.subtype = NUMBER_DESTRUCTED; -  bf->fun.type = PIKE_T_INT; +  bf->_fun.u.integer = 0; +  bf->_fun.subtype = NUMBER_DESTRUCTED; +  bf->_fun.type = PIKE_T_INT;    }       if (f->locals) {    INT32 numargs = DO_NOT_WARN((INT32) MINIMUM(f->num_args,    stack_top - f->locals));    INT32 varargs = 0;       if(of && of->locals) {    /* f->num_args can be too large, so this is necessary for some    * reason. I don't know why. /mast */