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.424 2008/05/28 19:07:18 grubba Exp $ + // $Id: master.pike.in,v 1.425 2008/05/29 12:50:26 grubba Exp $      #pike __REAL_VERSION__   //#pragma strict_types      // Some programs destroys character pairs beginning with the currency   // symbol when running in chinese locale.   #if "ยค/" != "\244/"   #error "master.pike.in is corrupted."   #endif   
pike.git/lib/master.pike.in:125:   }      #else // !RESOLV_DEBUG   #define INC_RESOLV_MSG_DEPTH() 0   #define DEC_RESOLV_MSG_DEPTH() 0   #define resolv_debug(X...) do {} while (0)   #endif // !RESOLV_DEBUG      // Some API compatibility stuff.    + //! Pike 0.6 master compatibility interface. + //! + //! Most of the interface is implemented via mixin. + //! + //! @seealso + //! @[get_compat_master()], @[master()]   static class Pike_0_6_master   {    int is_absolute_path(string p);    array(string) explode_path(string p);    string dirname(string x);    string basename(string x);    string describe_backtrace(array(mixed) trace);    object low_cast_to_object(string oname, string current_file); -  array(string) pike_include_path; -  array(string) pike_module_path; -  array(string) pike_program_path; -  int want_warnings; +  extern array(string) pike_include_path; +  extern array(string) pike_module_path; +  extern array(string) pike_program_path; +  extern int want_warnings;    program compile_string(string data, void|string name);    program compile_file(string file);   #ifdef GETCWD_CACHE -  string current_path; +  extern string current_path;    int cd(string s);    string getcwd();   #endif    string combine_path_with_cwd(string path);   #ifdef FILE_STAT_CACHE -  int invalidate_time; +  extern int invalidate_time;    mapping(string:multiset(string)) dir_cache;    array(mixed) master_file_stat(string x);   #endif    mapping (string:array(string)) environment;    mixed getenv(string|void s);    void putenv(string var, string val);    void add_include_path(string tmp);    void remove_include_path(string tmp);    void add_module_path(string tmp);    void remove_module_path(string tmp);    void add_program_path(string tmp);    void remove_program_path(string tmp);    mapping(string:program|NoValue) programs;   #if constant(_static_modules.Builtin.mutex) -  object compilation_mutex; +  extern object compilation_mutex;   #endif    program cast_to_program(string pname, string current_file);    void handle_error(array(mixed) trace);    __deprecated__ object new(mixed prog, mixed ... args)    {    if(stringp(prog))    prog=cast_to_program(prog,backtrace()[-2][0]);    return prog(@args);    }    local constant mkmultiset = predef::mkmultiset;    __deprecated__(function) clone = new;    constant master_efuns = ({});    void create();    program handle_inherit(string pname, string current_file); -  mapping (program:object) objects; +  extern mapping(program:object) objects;    object low_cast_to_object(string oname, string current_file);    object cast_to_object(string oname, string current_file);    class dirnode {};    class joinnode {}; -  mapping(string:mixed) fc; +  extern mapping(string:mixed) fc;    object findmodule(string fullname);    mixed handle_import(string what, string|void current_file);    local static object Pike_0_6_compat_handler;    local mixed resolv(string identifier, string|void current_file)    {    if (!Pike_0_6_compat_handler) {    Pike_0_6_compat_handler = global::get_compilation_handler(0, 6);    }    return Pike_0_6_compat_handler->resolv(identifier, current_file);    } -  string _pike_file_name; -  string _master_file_name; +  extern string _pike_file_name; +  extern string _master_file_name;    void _main(array(string) orig_argv, array(string) env); -  mixed inhibit_compile_errors; -  void set_inhibit_compile_errors(mixed f); +  extern mixed inhibit_compile_errors; +  extern void set_inhibit_compile_errors(mixed f);    string trim_file_name(string s);    void compile_error(string file,int line,string err);    void compile_warning(string file,int line,string err);    string handle_include(string f, string current_file, int local_include);    string read_include(string f); -  string stupid_describe(mixed m); +  string stupid_describe(mixed m) +  { +  switch(string typ=sprintf("%t",m)) +  { +  case "int": +  case "float": +  return (string)m; +  +  case "string": +  if(sizeof(m) < BT_MAX_STRING_LEN) +  { +  string t = sprintf("%O", m); +  if (sizeof(t) < (BT_MAX_STRING_LEN + 2)) { +  return t; +  } +  t = 0; +  } +  +  case "array": +  case "mapping": +  case "multiset": +  return typ+"["+sizeof(m)+"]"; +  +  default: +  return typ; +  } +  } +     string describe_program(program p);    string describe_backtrace(array(mixed) trace);    class Codec {};   }    - static private inherit Pike_0_6_master; + static inherit Pike_0_6_master;      //! @appears error   //! Throws an error. A more readable version of the code   //! @expr{throw( ({ sprintf(f, @@args), backtrace() }) )@}.   void error(string f, mixed ... args) {    if (sizeof(args)) f = sprintf(f, @args);    throw( ({ f, backtrace()[..<1] }) );   }      // FIXME: Should the pikeroot-things be private?
pike.git/lib/master.pike.in:1021:    switch(ext)    {    case "":    case ".pike":    foreach(query_precompiled_names(fname), string oname) {    if(Stat s2=master_file_stat(fakeroot(oname)))    {    if(s2->isreg && s2->mtime >= s->mtime)    {    mixed err=catch { +  object|program decoded;    AUTORELOAD_CHECK_FILE(oname);    resolv_debug ("low_findprog %s: decoding dumped\n", fname);    INC_RESOLV_MSG_DEPTH(); -  ret = decode_value(master_read_file(oname), +  decoded = decode_value(master_read_file(oname),    (handler && handler->get_codec ||    get_codec)(fname, mkobj, handler));    DEC_RESOLV_MSG_DEPTH();    resolv_debug ("low_findprog %s: dump decode ok\n", fname); -  if (ret && ret->this_program_does_not_exist) { +  if (decoded && decoded->this_program_does_not_exist) {    resolv_debug ("low_findprog %s: program claims not to exist\n",    fname);    return programs[fname] = 0;    }    else { -  +  if (objectp(decoded)) { +  resolv_debug("low_findprog %s: decoded object %O\n", +  fname, decoded); +  objects[ret = object_program(decoded)] = decoded; +  } else { +  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));    // handle_error(err);
pike.git/lib/master.pike.in:1135:    return 0;   }      //   // This function is called by the compiler when a delayed compilation   // error occurs in the given program. It should remove all references   // to the program so that it can be freed.   //   void unregister(program p)   { +  // werror("Unregistering %O...\n", p);    if(string fname=rev_programs[p] || search(programs,p)) {    resolv_debug("unregister %s\n", fname);    if (m_delete (rev_programs, p))    m_delete (programs, fname);    else    programs[fname] = no_value;       fname = dirname (fname);    object n;    if ( fname!="" && objectp (n = fc[fname]) )    if (n->is_resolv_dirnode || n->is_resolv_joinnode)    n->delete_value (p);    }    -  object o = objects[p]; +  object o = m_delete(objects, p);    if (objectp (o)) { -  if (m_delete (rev_objects, o)) -  m_delete (objects, p); -  else -  objects[p] = no_value; +  m_delete(rev_objects, o);    }       foreach (fc; string name; mixed mod)    if (objectp(mod) && object_program(mod) == p)    if (m_delete (rev_fc, mod))    m_delete (fc, name);    else    fc[name] = no_value;   }   
pike.git/lib/master.pike.in:1657:    return fc[fname] = dirnode(fname, compilation_handler);    }    resolv_debug("dirnode(%O)->ind(%O) casting (object)%O\n",    dirname, index, fname);    // FIXME: cast_to_program() and cast_to_object()    // have lots of overhead to guess the proper    // filename. This overhead isn't needed in    // our cases, so we could make do with    // low_findprog() and the caches.    mixed ret; +  if (ret = catch {    if (objectp(ret = low_cast_to_object(fname, 0, compilation_handler))) {    // 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)); +  }    } 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)    if (has_suffix(fname, ".so")) {
pike.git/lib/master.pike.in:1839:    _cache_full = 0;    }    }       static int(0..) _sizeof() {    return sizeof(_values());    }       static string _sprintf(int as)    { -  return as=='O' && sprintf("master()->dirnode(%O)",dirname); +  return as=='O' && sprintf("master()->dirnode(%O:%O)", +  dirname, module && module);    }   }      //! Module node holding possibly multiple directories,   //! and optionally falling back to another level.   //!   //! @seealso   //! @[dirnode]   class joinnode   {
pike.git/lib/master.pike.in:4483:    // it can potentially be large mappings and stuff that we encode    // here. They can go stale too.       ENC_MSG (" encoding recursively\n");    return ([])[0];    }       mixed encode_object(object x)    {    DEC_MSG ("encode_object (%O)\n", x); -  if(!x->_encode) +  if(!x->_encode) {    error ("Cannot encode object %O without _encode function.\n", x); -  +  // return ({}); +  }    DEC_RETURN (([function]x->_encode)());    }       static void create (void|mixed encoded)    //! Creates an encoder instance. If @[encoded] is specified, it's    //! encoded instead of being reverse resolved to a name. That's    //! necessary to encode programs.    {    this_program::encoded = encoded;   
pike.git/lib/master.pike.in:4665:    DEC_MSG ("functionof (%O)\n", what);    DEC_RETURN ([function] thingof (what));    }       program programof (string|array what)    {    DEC_MSG ("programof (%O)\n", what);    DEC_RETURN ([program] thingof (what));    }    -  void decode_object(object o, mixed data) +  //! Restore the state of an encoded object. +  //! +  //! @param o +  //! Object to modify. +  //! +  //! @param data +  //! State information from @[Encoder()->encode_object()]. +  //! +  //! The default implementation calls @expr{o->_decode(data)@} +  //! if the object has an @expr{_decode()@}, otherwise if +  //! @[data] is an array, returns it to indicate that @[lfun::create()] +  //! should be called. +  //! +  //! @note +  //! This function is called @b{before@} @[lfun::create()] +  //! in the object has been called, but after @[lfun::__INIT()] +  //! has been called. +  //! +  //! @returns +  //! Returns an array to indicate to the caller that +  //! @[lfun::create()] should be called with the elements +  //! of the array as arguments. +  //! +  //! Returns @expr{0@} (zero) to inhibit calling of @[lfun::create()]. +  //! +  //! @seealso +  //! @[Encoder()->encode_object()] +  array(mixed) decode_object(object o, mixed data)    {    DEC_MSG ("decode_object (object(%O), %O)\n", object_program (o), data); -  if(!o->_decode) +  if(!o->_decode) { +  if (!arrayp(data)) {    error ("Cannot decode object(%O) without _decode function.\n",    object_program (o)); -  +  } +  // Try calling lfun::create(). +  return data; +  }    ([function(mixed:void)]o->_decode)(data); -  +  return 0;    }   }      // Note: This mapping is not for caching but for coping with recursion   // problems by returning the same codec for the same file. As a cache   // it's really pointless.   static mapping(string:Decoder) codecs = set_weak_flag (([]), 1);      Decoder get_codec(string|void fname, int|void mkobj, void|object handler)   {