pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   /* -*- Pike -*-    * -  * $Id: master.pike.in,v 1.134 2000/09/28 03:38:23 hubbe Exp $ +  * $Id: master.pike.in,v 1.135 2000/11/20 01:26:26 mast Exp $    *    * Master-file for Pike.    *    * Based on master.pike 1.67.    */      // Some configurable parameters useful for debugging      #pike __REAL_VERSION__   #define PIKE_AUTORELOAD
pike.git/lib/master.pike.in:449:       foreach(pike_program_path, string path)    if(program ret=findprog(combine_path(path,pname),ext,handler))    return ret;       return 0;    }   }      /* This function is called when an error occurs that is not caught -  * with catch(). It's argument consists of: -  * ({ error_string, backtrace }) where backtrace is the output from the -  * backtrace() efun. +  * with catch().    */   void handle_error(array(mixed)|object trace)   { -  predef::trace(0); +     if(mixed x=catch {    werror(describe_backtrace(trace));    })    { -  +  // One reason for this might be too little stack space, which +  // easily can occur for "out of stack" errors. It should help to +  // tune up the STACK_MARGIN values in interpret.c then.    werror("Error in handle_error in master object:\n");    if(catch {    werror("%O\nOriginal error:\n%O\n",x,trace);    }) {    werror("sprintf() failed to write error.\n");    }    } -  +    }      object new(mixed prog, mixed ... args)   {    if(stringp(prog))    {    if(program p=cast_to_program(prog,backtrace()[-2][0]))    return p(@args);    else    error(sprintf("new: failed to find program %s.\n",prog));
pike.git/lib/master.pike.in:1483:      class Describer   {    int clipped=0;    int canclip=0;    mapping(mixed:int|string) ident = ([]);    int identcount = 0;       void identify_parts (mixed stuff)    { +  // Use an array as stack here instead of recursing directly; we +  // might be pressed for stack space if the backtrace being +  // described is a stack overflow. +  array identify_stack = ({stuff}); +  while (sizeof (identify_stack)) { +  stuff = identify_stack[-1]; +  identify_stack = identify_stack[..sizeof (identify_stack) - 2];    if (arrayp (stuff)) {    if (!ident[stuff]++) -  foreach (stuff, mixed elem) -  identify_parts (elem); +  identify_stack += stuff;    }    else if (multisetp (stuff)) {    if (!ident[stuff]++) -  foreach (indices (stuff), mixed elem) -  identify_parts (elem); +  identify_stack += indices (stuff);    }    else if (mappingp (stuff)) {    if (!ident[stuff]++) -  foreach (indices (stuff), mixed elem) -  identify_parts (elem), identify_parts (stuff[elem]); +  identify_stack += indices (stuff) + values (stuff);    }    else if (objectp (stuff) || functionp (stuff) || programp (stuff))    ident[stuff]++;    } -  +  }       string describe_string (string m, int maxlen)    {    canclip++;    if(sizeof(m) < maxlen)    {    string t = sprintf("%O", m);    if (sizeof(t) < (maxlen + 2)) {    return t;    }
pike.git/lib/master.pike.in:1742:    if(string s=search(programs,f))    {    if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp")    name = EXPLODE_PATH(reverse(rest))[-1];    else    name = trim_file_name(s);    }    else    if (catch (name = function_name (f))) name = "function";    -  if(object o=function_object(f)) { +  object o = function_object(f); +  if(o != 0) { // Testing simply on o here could invoke a `!.    string s;    if (!catch (s = sprintf("%O",o)) && s != "object")    return s+"->"+name;    }    return name;   }      /* It is possible that this should be a real efun,    * it is currently used by handle_error to convert a backtrace to a    * readable message.
pike.git/lib/master.pike.in:1790:    ret="";    }       if(!arrayp(trace))    {    ret+="No backtrace.\n";    }else{    Describer desc = Describer();    desc->identify_parts (trace);    -  for(e = sizeof(trace)-1; e>=0; e--) +  int end = 0; +  if( (sizeof(trace)>1) && +  arrayp(trace[0]) && +  (sizeof(trace[0]) > 2) && +  (trace[0][2] == _main)) +  end = 1; +  +  mapping(string:int) prev_pos = ([]); +  array(string) frames = ({}); +  int loop_start = 0, loop_next, loops; +  +  for(e = sizeof(trace)-1; e>=end; e--)    {    mixed tmp;    string row; -  if( arrayp(trace[e]) && -  (sizeof(trace[e]) > 2) && -  (trace[e][2] == _main) && -  (sizeof(trace)>1) ) -  continue; -  if (mixed err=catch { +  // The continue's below jump wrong when this catch is here.. :P + // if (mixed err=catch {    tmp = trace[e];    if(stringp(tmp))    {    row=tmp;    }    else if(arrayp(tmp))    {    string pos;    if(sizeof(tmp)>=2 && stringp(tmp[0])) {    if (intp(tmp[1])) { -  +  +  string exact_pos = tmp[0] + ":" + tmp[1]; +  int dup_frame; +  if (!zero_type (dup_frame = prev_pos[exact_pos])) { +  dup_frame -= sizeof (frames); +  if (!loop_start) { +  loop_start = dup_frame; +  loop_next = dup_frame + 1; +  loops = 0; +  continue; +  } +  else { +  int new_loop = 0; +  if (!loop_next) loop_next = loop_start, new_loop = 1; +  if (dup_frame == loop_next++) { +  loops += new_loop; +  continue; +  } +  } +  } +  prev_pos[exact_pos] = sizeof (frames); +     pos=trim_file_name(tmp[0])+":"+tmp[1];    } else {    pos = sprintf("%s:Bad line %t", trim_file_name(tmp[0]), tmp[1]);    }    }else{    mixed desc="Unknown program";    if(sizeof(tmp)>=3 && functionp(tmp[2]))    {    catch    {    if(mixed tmp=function_object(tmp[2]))    if(tmp=object_program(tmp))    if(tmp=describe_program(tmp))    desc=tmp;    };    }    pos=desc;    }    -  +  if (loop_start) { +  array(string) tail; +  if (!loop_next) tail = ({}), loops++; +  else tail = frames[loop_start + sizeof (frames) .. +  loop_next - 1 + sizeof (frames)]; +  if (loops) +  frames += ({sprintf ("... last %d frames above repeated %d times ...\n", +  -loop_start, loops)}); +  frames += tail; +  prev_pos = ([]); +  loop_start = 0; +  } +     string data;       if(sizeof(tmp)>=3)    {    if(functionp(tmp[2])) {    data = describe_function (tmp[2]);    }    else if (stringp(tmp[2])) {    data= tmp[2];    } else
pike.git/lib/master.pike.in:1864:    }    else    {    if (tmp) {    if (catch (row = sprintf("%O", tmp)))    row = describe_program(object_program(tmp)) + " with broken _sprintf()";    } else {    row = "Destructed object";    }    } -  }) { -  row = sprintf("Error indexing backtrace line %d: %s (%O)!", e, err[0], err[1]); + // }) { + // row = sprintf("Error indexing backtrace line %d: %s (%O)!", e, err[0], err[1]); + // } +  frames += ({row + "\n"});    } -  ret += row + "\n"; +  +  if (loop_start) { +  // Want tail to contain a full loop rather than being empty; it +  // looks odd when the repeat message ends the backtrace. +  array(string) tail = frames[loop_start + sizeof (frames) .. +  loop_next - 1 + sizeof (frames)]; +  if (loops) +  frames += ({sprintf ("... last %d frames above repeated %d times ...\n", +  -loop_start, loops)}); +  frames += tail;    } -  +  +  ret += frames * "";    }       return ret;   }      // Returns a short description of a backtrace, containing only the   // error message.   string describe_error (mixed trace)   {    if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) ||