pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   // -*- Pike -*-   //   // Master Control Program for Pike.   //   // 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: master.pike.in,v 1.471 2010/03/03 13:00:31 mast Exp $ + // $Id: master.pike.in,v 1.472 2010/05/06 14:13:58 grubba Exp $      #pike __REAL_VERSION__   //#pragma strict_types      //! @appears predef::MasterObject   //!   //! Master control program for Pike.   //!   //! @seealso   //! @[predef::master()], @[predef::replace_master()]
pike.git/lib/master.pike.in:1471:   }      protected void compile_cb_rethrow (object|array err)   // Use this to rethrow errors that should be converted to plain   // compile error messages, without backtraces being reported by   // compile_exception.   {    array bt;    if (array|object e = catch (bt = get_backtrace (err)))    handle_error (e); -  throw (CompileCallbackError (describe_error (err), bt)); +  throw (CompileCallbackError (call_describe_error (err), bt));   }      protected void call_compile_warning (object handler, string file,    string msg, mixed ... args)   {    if (sizeof (args)) msg = sprintf (msg, @args);    msg = trim_all_whites (msg);    if (handler && handler->compile_warning)    handler->compile_warning (file, 0, msg);    else if (master()->compile_warning)
pike.git/lib/master.pike.in:1628:       if (documentation[prog])    {    if (child)    return documentation[prog]->findObject(child)||documentation[prog]->findChild(child);    else    return documentation[prog];    }   }    + // Make it possible to customize the backtrace formatting. + protected string call_describe_backtrace(array(mixed) trace, +  void|int linewidth) + { +  return (all_constants()["describe_backtrace"]||describe_backtrace) +  (trace, linewidth); + }    -  + protected string call_describe_error(mixed /* object|array */ err) + { +  return (all_constants()["describe_error"]||describe_error)(err); + } +    protected program low_findprog(string pname,    string ext,    object|void handler,    void|int mkobj)   {    program ret;    Stat s;    string fname=pname+ext;       resolv_debug("low_findprog(%O, %O, %O, %O)\n",
pike.git/lib/master.pike.in:1733:    ret = decoded;    }    resolv_debug("low_findprog %s: returning %O\n", fname, ret);    return programs[fname]=ret;    }    };    DEC_RESOLV_MSG_DEPTH();    resolv_debug ("low_findprog %s: dump decode failed\n", fname);    programs[fname] = no_value;    call_compile_warning (handler, oname, -  "Decode failed: " + describe_error(err)); +  "Decode failed: " + +  call_describe_error(err));    // handle_error(err);    } else if (out_of_date_warning) {    call_compile_warning (handler, oname,    "Compiled file is out of date");    }    }    }       resolv_debug ("low_findprog %s: compiling, mkobj: %O\n", fname, mkobj);    INC_RESOLV_MSG_DEPTH();
pike.git/lib/master.pike.in:1774:    throw(e);    }    DEC_RESOLV_MSG_DEPTH();    resolv_debug ("low_findprog %s: compilation ok\n", fname);    break;      #if constant(load_module)    case ".so":    if (fname == "") {    werror( "low_findprog(%O, %O) => load_module(\"\")\n" -  "%s\n", pname, ext, describe_backtrace(backtrace()) ); +  "%s\n", pname, ext, call_describe_backtrace(backtrace()) );    }       if (array|object err = catch (ret = load_module(fakeroot(fname)))) {    DEC_RESOLV_MSG_DEPTH();    resolv_debug ("low_findprog %s: failed to load binary\n", fname);    objects[ret] = no_value;    ret=programs[fname]=0; // Negative cache.    if (objectp (err) && err->is_module_load_error)    // Do not treat errors from dlopen(3) as exceptions since in    // a dist we can have .so files that are dynamically linked
pike.git/lib/master.pike.in:1954:   }         //! This function is called when an error occurs that is not caught   //! with catch().   void handle_error(array|object trace)   {    // NB: Use predef::trace() to modify trace level here.    // predef::trace(2);    if(mixed x=catch { -  werror(describe_backtrace(trace)); +  werror(call_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 {    // NB: Splited werror calls to retain some information    // even if/when werror throws.    catch {    if (catch {
pike.git/lib/master.pike.in:2291:    * this).    */    cache=([]);    _cache_full=0;    }    DEC_RESOLV_MSG_DEPTH();    resolv_debug("dirnode(%O)->module_checker()->`!() => %s\n",    dirname, !module ? "doesn't exist" : "exists");    return !module;    }) { -  //werror ("findmodule error: " + describe_backtrace (err)); +  //werror ("findmodule error: " + call_describe_backtrace (err));       // findmodule() failed. This can occur due to circularities    // between encode_value()'ed programs.    // The error will then typically be:    // "Cannot call functions in unfinished objects."       // Pretend not to exist for now...    DEC_RESOLV_MSG_DEPTH();    resolv_debug("dirnode(%O)->module_checker()->`!() => failure, doesn't exist\n",    dirname);
pike.git/lib/master.pike.in:2370:    // This assignment is needed for eg the Calendar module.    if (set_module) module = ret;    if(mixed tmp=ret->_module_value) ret=tmp;    DEC_RESOLV_MSG_DEPTH();    resolv_debug("dirnode(%O)->ind(%O) => found submodule %O:%O\n",    dirname, index, fname, ret);    return ret;    }    }) {    resolv_debug("dirnode(%O)->ind(%O) ==> Cast to object failed: %s\n", -  dirname, index, describe_backtrace(ret)); +  dirname, index, call_describe_backtrace(ret));    }    } else {    resolv_debug("dirnode(%O)->ind(%O) casting (program)%O\n",    dirname, index, fname);    program|object ret;    if (ret = low_cast_to_program(fname, 0, compilation_handler)) {    DEC_RESOLV_MSG_DEPTH();    resolv_debug("dirnode(%O)->ind(%O) => found subprogram %O:%O\n",    dirname, index, fname, ret);   #if constant(load_module)
pike.git/lib/master.pike.in:2480:    return ret;    }       mixed safe_index(string index)    {    mixed err;    resolv_debug ("dirnode(%O): %O...\n", dirname, index);    if (err = catch { return `[](index); }) {    call_compile_warning (compilation_handler,    dirname+"."+fname, -  "Compilation failed: " + describe_error(err)); +  "Compilation failed: " + +  call_describe_error(err));    }    return UNDEFINED;    }       protected int(0..1) _cache_full;    void fill_cache()    {   #if 0 -  werror(describe_backtrace(({ sprintf("Filling cache in dirnode %O\n", +  werror(call_describe_backtrace(({ sprintf("Filling cache in dirnode %O\n",    dirname),    backtrace() })));   #endif    if (_cache_full) {    return;    }       resolv_debug ("dirnode(%O) => Filling cache...\n", dirname);       // NOTE: We rely on side effects in `[]() and safe_index()
pike.git/lib/master.pike.in:2671:    cache[index] = ret;    }    return ret;    }       protected int _cache_full;       void fill_cache()    {   #if 0 -  werror(describe_backtrace(({ "Filling cache in joinnode\n", +  werror(call_describe_backtrace(({ "Filling cache in joinnode\n",    backtrace() })));   #endif    if (_cache_full) {    return;    }    foreach(joined_modules, object|mapping|program o) {    foreach(indices(o), string index) {    if (zero_type(cache[index])) {    `[](index);    }
pike.git/lib/master.pike.in:3637:    prog = compile_string(    "#define NOT(X) !(X)\n"    "mixed run(int argc, array(string) argv){" + code + ";}");    }    };       if (compile_err) {    if (compile_err->is_cpp_or_compilation_error) {    // Don't clutter the output with the backtrace for    // compilation errors. -  exit (20, describe_error (compile_err)); +  exit (20, call_describe_error (compile_err));    }    else throw (compile_err);    }      #if constant(_debug)    if(debug) _debug(debug);   #endif    if(trace) trace = predef::trace(trace);    mixed ret;    mixed err = catch {
pike.git/lib/master.pike.in:3752:       if(run_tool) {    mixed err = catch {    prog = main_resolv("Tools.Standalone." + argv[0],    get_compilation_handler(compat_major, compat_minor));    };       if (err)    exit(1, "Pike: Failed to load tool %s:\n"    "%s\n", argv[0], -  stringp(err[0])?err[0]:describe_backtrace(err)); +  stringp(err[0])?err[0]:call_describe_backtrace(err));       argv[0] = search(programs, prog) || argv[0];    } else {    argv[0]=combine_path_with_cwd(argv[0]);       mixed err = catch {    prog=(program)argv[0];    };       if (err) {
pike.git/lib/master.pike.in:3780:    }    if( !file_stat(fn)->isreg )    exit(1, "File %O is not a regular file.\n", fn);    if( !master_read_file(fn) )    exit(1, "File %O is not readable. %s.\n",    fn, strerror(errno()));    if (objectp (err) && err->is_cpp_or_compilation_error)    exit(1, "Pike: Failed to compile script.\n");    else    exit(1, "Pike: Failed to compile script:\n" -  "%s", describe_backtrace(err)); +  "%s", call_describe_backtrace(err));    }       // Don't list the program with its real path in the programs    // mapping, so that reverse lookups (typically by the codec)    // always find the canonical "/main" instead.    programs[argv[0]] = no_value;    }       programs["/main"] = prog;   
pike.git/lib/master.pike.in:4564:    // like arrays.    trace = err_obj[1];    if (!trace)    return ret + "<No backtrace>\n";    else if (!arrayp (trace))    return sprintf ("%s<Backtrace in %O is %t, expected array>\n",    ret, err_obj, trace);       })    return sprintf ("<Failed to index backtrace object %O: %s>\n", -  err_obj, trim_all_whites (describe_error (err))); +  err_obj, trim_all_whites (call_describe_error (err)));    }       else if (arrayp(trace)) {    if (sizeof([array]trace)==2 && stringp(ret = ([array]trace)[0])) {    trace = ([array] trace)[1];    if(!trace)    return ret + "<No backtrace>\n";    else if (!arrayp (trace))    return sprintf ("%s<Backtrace in error array is %t, expected array>\n",    ret, trace);    }    else    ret = "";    }       else {   #if constant(_gdb_breakpoint)    _gdb_breakpoint();   #endif    return sprintf ("<Invalid backtrace/error container: %O>\n" -  "%s\n", trace, describe_backtrace(backtrace())); +  "%s\n", trace, call_describe_backtrace(backtrace()));    }       {    Describer desc = Describer();    array trace = [array]trace;       int end = 0;    if( (sizeof(trace)>1) &&    arrayp(trace[0]) &&    (sizeof([array]trace[0]) > 2) &&
pike.git/lib/master.pike.in:4784:    if (stringp (msg))    return msg;    else if (!msg)    return "<No error message>\n";    else    return sprintf ("<Message in %O is %t, expected string>\n",    err_obj, msg);       })    return sprintf ("<Failed to index error object %O: %s>\n", -  err_obj, trim_all_whites (describe_error (err))); +  err_obj, trim_all_whites (call_describe_error (err)));    }       else if (arrayp(err) && sizeof([array]err)==2 &&    (!(msg = ([array]err)[0]) || stringp (msg)))    return [string] msg || "<No error message>\n";       else    return sprintf ("<Invalid error container: %O>\n", err);   }