Branch: Tag:

2003-09-08

2003-09-08 12:57:33 by Henrik Grubbström (Grubba) <grubba@grubba.org>

CompatResolvers are now nested, so that compat modules are exhausted before searching for newer modules is begun.
Added support for programs in the root of module directories (ie not just in .pmod directories).

Rev: lib/master.pike.in:1.296

6:   // Pike is distributed under GPL, LGPL and MPL. See the file COPYING   // for more information.   // - // $Id: master.pike.in,v 1.295 2003/08/22 00:52:21 nilsson Exp $ + // $Id: master.pike.in,v 1.296 2003/09/08 12:57:33 grubba Exp $      #pike __REAL_VERSION__   
745:       AUTORELOAD_FINISH(ret,programs,fname);    +  resolv_debug("low_findprog %s: returning %O\n", fname, ret); +     return programs[fname]=ret;    }    resolv_debug ("low_findprog %s: file not found\n", fname);
759:   void unregister(program p)   {    if(string fname=search(programs,p)) { +  resolv_debug("unregister %s\n", fname);    programs[fname] = no_value;    // FIXME: The following assumes that programs are always stored    // with '/' as path separators, even on NT. Haven't checked if
1431:    }   };    - object findmodule(string fullname, object|void handler) + program|object findmodule(string fullname, object|void handler)   { -  object o; +  program|object o;       resolv_debug ("findmodule(%O)\n", fullname);    if(!zero_type(o=fc[fullname]) && o != no_value)    { -  if (objectp(o) || o != 0) { +  if (objectp(o) || programp(o) || o != 0) {    resolv_debug ("findmodule(%O) => found %O (cached)\n", fullname, o);    return o;    }
1472:    }   #endif    +  if (programp (o = cast_to_program(fullname, "/.", handler))) {    DEC_RESOLV_MSG_DEPTH(); -  +  resolv_debug ("findmodule(%O) => got .pike program %O\n", fullname, o); +  return fc[fullname] = o; +  } +  +  DEC_RESOLV_MSG_DEPTH();    resolv_debug ("findmodule(%O) => not found\n", fullname);    return fc[fullname] = 0;   }
1543:    mapping(string:string) predefines = ([]);    string ver;    +  //! If we fail to resolv, try our parent. +  //! +  //! Typical configuration: +  //! @pre{0.6->7.0->7.2->7.4->master@} +  CompatResolver parent_resolver; +     //! The CompatResolver is initialized with a value that can be    //! casted into a "%d.%d" string, e.g. a version object.    void create(mixed version)
1709:    {    string file=combine_path(dir, path, identifier);    mixed ret = findmodule(file, current_handler); -  if(objectp (ret)) { // ret is either zero or an object here. +  if(objectp (ret) || programp(ret)) { +  // ret is either zero or an object or a program here.    if (ret->is_resolv_dirnode || ret->is_resolv_joinnode) {    if (mixed new_ret = ret->_module_value) {    ret = new_ret;
1739:    }    return joinnode(tmp);    } +  if (parent_resolver) { +  return parent_resolver->resolv(identifier, current_file, +  current_handler); +  }    return UNDEFINED;    }   
1802:    string current_file,    int local_include)    { -  array(string) tmp; -  string path; -  +     if(local_include)    { -  tmp=EXPLODE_PATH(current_file); +  array(string) tmp=EXPLODE_PATH(current_file);    tmp[-1]=f; -  path=combine_path_with_cwd(tmp*"/"); +  return combine_path_with_cwd(tmp*"/");    }    else    { -  foreach(pike_include_path, path) +  foreach(pike_include_path, string path)    {    path=combine_path(path,f);    if(master_file_stat(fakeroot(path))) -  break; -  else -  path=0; +  return path;    } -  +  if (parent_resolver) { +  return parent_resolver->handle_include(f, current_file, +  local_include);    } -  -  return path; +     } -  +  // Failed. +  return 0; +  }       //!    string read_include(string f)
3589:    if(unregistered && fname)    {    unregistered = 0; +  resolv_debug("register %s\n", fname);    programs[fname]=p;    if (mkobj)    DEC_RETURN (objectp (objects[p]) ? objects[p] : (objects[p]=__null_program()));
3810:      CompatResolver get_compilation_handler(int major, int minor)   { -  CompatResolver ret; -  +     Version v=Version(major,minor);       if(v > currentversion)
3820:    return 0;    }    +  CompatResolver ret; +     if(!zero_type(ret=compat_handler_cache[v])) return ret;    -  array files; +  array(string) files;    array(Version) available=({});      #if "¤share_prefix¤"[0]!='¤'
3880:    return compat_handler_cache[v]=ret;   #endif    -  ret=CompatResolver(v); -  /* Add default paths */ -  ret->pike_module_path=pike_module_path; -  ret->pike_include_path=pike_include_path; +  // The root resolver is this object. +  ret = this_object();       foreach(reverse(available), Version tmp)    { -  +  CompatResolver compat_handler = compat_handler_cache[tmp]; +  if (!compat_handler) { +  compat_handler = CompatResolver(tmp); +  +  // Fall back to the successor version. +  compat_handler->parent_resolver = ret; +     string base;   #if "¤lib_prefix¤"[0]!='¤'    base=combine_path("¤lib_prefix¤",sprintf("%s",tmp)); -  ret->add_module_path(combine_path(base,"modules")); -  ret->add_include_path(combine_path(base,"include")); +  compat_handler->add_module_path(combine_path(base,"modules")); +  compat_handler->add_include_path(combine_path(base,"include"));   #endif      #if "¤share_prefix¤"[0]!='¤'    base=combine_path("¤share_prefix¤",sprintf("%s",tmp)); -  ret->add_module_path(combine_path(base,"modules")); -  ret->add_include_path(combine_path(base,"include")); +  compat_handler->add_module_path(combine_path(base,"modules")); +  compat_handler->add_include_path(combine_path(base,"include"));   #endif -  } +     -  if( v <= Version(0,6)) +  if( tmp <= Version(0,6))    ret->pike_module_path+=({"."});    -  compat_handler_cache[v] = ret; -  +    #ifndef RESOLVER_HACK -  compat_handler_cache[available[0]] = ret; /* may be equal to 'v' */ +  ret = compat_handler_cache[tmp] = compat_handler;   #endif -  +  } +  }    -  +  // Note: May duplicate the assignment above. +  compat_handler_cache[v] = ret; +     return ret;   }