[Aptitude-devel] r3183 - in branches/aptitude-0.3/aptitude: . src/cmdline src/generic

Daniel Burrows dburrows@costa.debian.org
Fri, 29 Apr 2005 01:31:12 +0000


Author: dburrows
Date: Fri Apr 29 01:31:08 2005
New Revision: 3183

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/cmdline/cmdline_dump_resolver.cc
   branches/aptitude-0.3/aptitude/src/generic/aptcache.cc
   branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc
   branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
Log:
Partially fix the crash when packages are broken on startup
(now it segfaults in a different place).

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Apr 29 01:31:08 2005
@@ -1,5 +1,11 @@
 2005-04-28  Daniel Burrows  <dburrows@debian.org>
 
+	* src/cmdline/cmdline_dump_resolver.cc, src/generic/aptcache.cc, src/generic/aptitude_resolver.cc, src/generic/aptitude_resolver.h:
+
+	  Carry a backpointer to the cache around in all the resolver glue
+	  code, to avoid segfaulting if apt_cache_file is uninitialized
+	  when we're called (e.g., if packages are broken on startup).
+
 	* src/cmdline/cmdline_resolver.cc:
 
 	  Fix a very stupid infinite loop bug.

Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_dump_resolver.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_dump_resolver.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_dump_resolver.cc	Fri Apr 29 01:31:08 2005
@@ -42,7 +42,7 @@
       return -1;
     }
 
-  aptitude_universe u;
+  aptitude_universe u(*apt_cache_file);
 
   dump_universe(u, cout);
 

Modified: branches/aptitude-0.3/aptitude/src/generic/aptcache.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptcache.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptcache.cc	Fri Apr 29 01:31:08 2005
@@ -1353,7 +1353,8 @@
 				 aptcfg->FindI(PACKAGE "::ProblemResolver::BrokenScore", -50),
 				 aptcfg->FindI(PACKAGE "::ProblemResolver::Infinity", 50000),
 				 aptcfg->FindI(PACKAGE "::ProblemResolver::Max-Successors", 50),
-				 aptcfg->FindI(PACKAGE "::ProblemResolver::ResolutionScore", 50));
+				 aptcfg->FindI(PACKAGE "::ProblemResolver::ResolutionScore", 50),
+				 this);
 
   resolver->add_action_scores(aptcfg->FindI(PACKAGE "::ProblemResolver::PreserveManualScore", 40),
 			      aptcfg->FindI(PACKAGE "::ProblemResolver::PreserveAutoScore", 0),
@@ -1505,7 +1506,7 @@
   assert(resolver_exists());
   assert(resolver->fresh());
 
-  resolver->add_version_score(aptitude_resolver_version(pkg, ver),
+  resolver->add_version_score(aptitude_resolver_version(pkg, ver, this),
 			      score);
 }
 

Modified: branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc	Fri Apr 29 01:31:08 2005
@@ -23,9 +23,10 @@
 				     int broken_penalty,
 				     int infinity,
 				     int max_successors,
-				     int resolution_score)
-  :generic_problem_resolver<aptitude_universe>(step_penalty, broken_penalty, infinity, max_successors, resolution_score, universe),
-   universe()
+				     int resolution_score,
+				     aptitudeDepCache *cache)
+  :generic_problem_resolver<aptitude_universe>(step_penalty, broken_penalty, infinity, max_successors, resolution_score, aptitude_universe(cache)),
+   universe(cache)
 {
 }
 
@@ -36,11 +37,11 @@
 {
   // Should I stick with APT iterators instead?  This is a bit more
   // convenient, though..
-  for(aptitude_universe::package_iterator pi=(*apt_cache_file)->PkgBegin();
+  for(aptitude_universe::package_iterator pi=aptitude_universe::package_iterator(universe.get_cache()->PkgBegin(), universe.get_cache());
       !pi.end(); ++pi)
     {
       const aptitude_universe::package &p=*pi;
-      aptitudeDepCache::aptitude_state &state=(*apt_cache_file)->get_ext_state(p.get_pkg());
+      aptitudeDepCache::aptitude_state &state=universe.get_cache()->get_ext_state(p.get_pkg());
 
       for(aptitude_universe::package::version_iterator vi=p.versions_begin(); !vi.end(); ++vi)
 	{
@@ -65,7 +66,7 @@
 	    add_version_score(v, keep_score);
 	  else if(v.get_ver().end())
 	    add_version_score(v, remove_score);
-	  else if(v.get_ver()==(*apt_cache_file)[p.get_pkg()].CandidateVerIter(*apt_cache_file))
+	  else if(v.get_ver()==(*universe.get_cache())[p.get_pkg()].CandidateVerIter(*universe.get_cache()))
 	    {
 	      // Could try harder not to break holds.
 	      if(p.get_pkg().CurrentVer().end())
@@ -96,7 +97,7 @@
 					    int optional,
 					    int extra)
 {
-  for(aptitude_universe::package_iterator pi=(*apt_cache_file)->PkgBegin();
+  for(aptitude_universe::package_iterator pi=aptitude_universe::package_iterator(universe.get_cache()->PkgBegin(), universe.get_cache());
       !pi.end(); ++pi)
     for(aptitude_universe::package::version_iterator vi=(*pi).versions_begin(); !vi.end(); ++vi)
       {

Modified: branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	Fri Apr 29 01:31:08 2005
@@ -51,10 +51,17 @@
 /** Wraps a PkgIterator for the resolver. */
 class aptitude_resolver_package
 {
+  pkgDepCache *cache;
   pkgCache::PkgIterator pkg;
 public:
-  aptitude_resolver_package(const pkgCache::PkgIterator &_pkg)
-    :pkg(_pkg)
+  aptitude_resolver_package()
+    :cache(0)
+  {
+  }
+
+  aptitude_resolver_package(const pkgCache::PkgIterator &_pkg,
+			    pkgDepCache *_cache)
+    :cache(_cache), pkg(_pkg)
   {
   }
 
@@ -98,16 +105,19 @@
 /** Wraps a package/version pair for the resolver. */
 class aptitude_resolver_version
 {
+  pkgDepCache *cache;
   pkgCache::PkgIterator pkg;
   pkgCache::VerIterator ver;
 public:
   aptitude_resolver_version()
+    :cache(0)
   {
   }
 
   aptitude_resolver_version(const pkgCache::PkgIterator &_pkg,
-			    const pkgCache::VerIterator &_ver)
-    :pkg(_pkg), ver(_ver)
+			    const pkgCache::VerIterator &_ver,
+			    pkgDepCache *_cache)
+    :cache(_cache), pkg(_pkg), ver(_ver)
   {
   }
 
@@ -132,7 +142,7 @@
       // there's more to copy.  I could also teach the resolver about
       // "null" versions...but that would mean a bunch of pointless
       // special-casing caller-side anyway.
-      return (*apt_cache_file)->Head().VersionCount+pkg->ID;
+      return cache->Head().VersionCount+pkg->ID;
   }
 
   const char *get_name() const
@@ -147,7 +157,7 @@
 
   aptitude_resolver_package get_package() const
   {
-    return pkg;
+    return aptitude_resolver_package(pkg, cache);
   }
 
   bool operator==(const aptitude_resolver_version &other) const
@@ -179,11 +189,13 @@
 
 inline aptitude_resolver_version aptitude_resolver_package::current_version() const
 {
-  return aptitude_resolver_version(pkg, (*apt_cache_file)[pkg].InstVerIter(*apt_cache_file));
+  return aptitude_resolver_version(pkg, (*cache)[pkg].InstVerIter(*cache),
+				   cache);
 }
 
 class aptitude_resolver_dep
 {
+  pkgDepCache *cache;
   pkgCache::DepIterator start;
   /** If start is a Conflicts and prv is not an end iterator, then the
    *  object represents "V -> {V'_1 V'_2 ..} where the V'-s are
@@ -197,9 +209,17 @@
    */
   pkgCache::PrvIterator prv;
 public:
+#if 0
+  aptitude_resolver_dep()
+    :cache(0)
+  {
+  }
+#endif
+
   aptitude_resolver_dep(const pkgCache::DepIterator dep,
-			const pkgCache::PrvIterator _prv)
-    :prv(_prv)
+			const pkgCache::PrvIterator _prv,
+			pkgDepCache *_cache)
+    :cache(_cache), prv(_prv)
   {
     assert(!dep.end());
     if(dep->Type != pkgCache::Dep::Conflicts)
@@ -258,7 +278,9 @@
   {
     assert(!start.end());
     assert(!const_cast<pkgCache::DepIterator &>(start).ParentPkg().end());
-    return aptitude_resolver_version(const_cast<pkgCache::DepIterator &>(start).ParentPkg(), const_cast<pkgCache::DepIterator &>(start).ParentVer());
+    return aptitude_resolver_version(const_cast<pkgCache::DepIterator &>(start).ParentPkg(),
+				     const_cast<pkgCache::DepIterator &>(start).ParentVer(),
+				     cache);
   }
 
   class solver_iterator;
@@ -268,12 +290,19 @@
 
 class aptitude_resolver_package::version_iterator
 {
+  pkgDepCache *cache;
   pkgCache::PkgIterator pkg;
   pkgCache::VerIterator ver;
 public:
+  version_iterator()
+    :cache(0)
+  {
+  }
+
   version_iterator(pkgCache::PkgIterator _pkg,
-		   pkgCache::VerIterator _ver)
-    :pkg(_pkg), ver(_ver)
+		   pkgCache::VerIterator _ver,
+		   pkgDepCache *_cache)
+    :cache(_cache), pkg(_pkg), ver(_ver)
   {
   }
 
@@ -293,7 +322,7 @@
 
   aptitude_resolver_version operator *() const
   {
-    return aptitude_resolver_version(pkg, ver);
+    return aptitude_resolver_version(pkg, ver, cache);
   }
 
   version_iterator &operator++()
@@ -313,7 +342,7 @@
 
 inline aptitude_resolver_package::version_iterator aptitude_resolver_package::versions_begin() const
 {
-  return version_iterator(pkg, pkg.VersionList());
+  return version_iterator(pkg, pkg.VersionList(), cache);
 }
 
 /** \note For our purposes, conflicts are revdeps of the conflicted
@@ -324,6 +353,7 @@
  */
 class aptitude_resolver_version::revdep_iterator
 {
+  pkgDepCache *cache;
   /** The Depends which is currently being tried. */
   pkgCache::DepIterator dep_lst;
   /** The Provides which is currently being tried. */
@@ -394,11 +424,20 @@
 				   dep_lst->CompareOp, dep_lst.TargetVer());
   }
 public:
+#if 0
+  revdep_iterator()
+    :cache(0)
+  {
+  }
+#endif
+
   /** Generate a revdep_iterator to cover the reverse deps of
    *  the given version. (note that v may be an end iterator..)
    */
-  revdep_iterator(const pkgCache::VerIterator &v)
-    :prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0), ver(v),
+  revdep_iterator(const pkgCache::VerIterator &v,
+		  pkgDepCache *_cache)
+    :cache(_cache),
+     prv_lst(*_cache, 0, (pkgCache::Package *) 0), ver(v),
      provides_open(false)
   {
     // Note that if v is an end iterator, we present an empty list and
@@ -431,7 +470,7 @@
 
   aptitude_resolver_dep operator*() const
   {
-    return aptitude_resolver_dep(dep_lst, prv_lst);
+    return aptitude_resolver_dep(dep_lst, prv_lst, cache);
   }
 
   revdep_iterator &operator++()
@@ -445,7 +484,7 @@
 
 inline aptitude_resolver_version::revdep_iterator aptitude_resolver_version::revdeps_begin() const
 {
-  return revdep_iterator(ver);
+  return revdep_iterator(ver, cache);
 }
 
 /** This class uses a technique similar to rev_dep_lst.  It assumes
@@ -459,6 +498,8 @@
  */
 class aptitude_resolver_dep::solver_iterator
 {
+  pkgDepCache *cache;
+
   pkgCache::DepIterator dep_lst;
   pkgCache::VerIterator ver_lst;
   pkgCache::PrvIterator prv_lst;
@@ -588,9 +629,11 @@
   }
 
 public:
-  solver_iterator(const pkgCache::DepIterator &start)
-    :dep_lst(start),
-     prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0),
+  solver_iterator(const pkgCache::DepIterator &start,
+		  pkgDepCache *_cache)
+    :cache(_cache),
+     dep_lst(start),
+     prv_lst(*cache, 0, (pkgCache::Package *) 0),
      finished(start.end())
   {
     if(!dep_lst.end())
@@ -606,8 +649,9 @@
 
   /** Initialize a Conflicts solution iterator. */
   solver_iterator(const pkgCache::DepIterator &d,
-		  const pkgCache::PrvIterator &p)
-    :dep_lst(d), prv_lst(p), finished(d.end())
+		  const pkgCache::PrvIterator &p,
+		  pkgDepCache *_cache)
+    :cache(_cache), dep_lst(d), prv_lst(p), finished(d.end())
   {
     if(!dep_lst.end())
       {
@@ -623,10 +667,14 @@
     normalize();
   }
 
+#if 0
   solver_iterator()
-    :prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0), finished(true)
+    :cache(0),
+     // shouldn't do this, but otherwise we crash!!
+     prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0), finished(true)
   {
   }
+#endif
 
   bool operator==(const solver_iterator &other) const
   {
@@ -671,7 +719,7 @@
     assert(!end());
 
     if(!ver_lst.end())
-      return aptitude_resolver_version(ver_lst.ParentPkg(),ver_lst);
+      return aptitude_resolver_version(ver_lst.ParentPkg(),ver_lst,cache);
     else // In this case we're trying to remove some package or other.
       {
 	if(dep_lst->Type != pkgCache::Dep::Conflicts)
@@ -679,12 +727,12 @@
 	    // Assume this because otherwise end() should be true.
 	    assert(!prv_lst.end());
 
-	    return aptitude_resolver_version(const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerPkg(),const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerVer());
+	    return aptitude_resolver_version(const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerPkg(),const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerVer(),cache);
 	  }
 	else if(!prv_lst.end())
-	  return aptitude_resolver_version(const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerPkg(),ver_lst);
+	  return aptitude_resolver_version(const_cast<pkgCache::PrvIterator &>(prv_lst).OwnerPkg(),ver_lst,cache);
 	else
-	  return aptitude_resolver_version(const_cast<pkgCache::DepIterator &>(dep_lst).TargetPkg(),ver_lst);
+	  return aptitude_resolver_version(const_cast<pkgCache::DepIterator &>(dep_lst).TargetPkg(),ver_lst,cache);
       }
   }
 
@@ -697,16 +745,16 @@
 inline aptitude_resolver_dep::solver_iterator aptitude_resolver_dep::solvers_begin() const
 {
   if(start->Type != pkgCache::Dep::Conflicts)
-    return solver_iterator(start);
+    return solver_iterator(start, cache);
   else
-    return solver_iterator(start, prv);
+    return solver_iterator(start, prv, cache);
 }
 
 template<class SolutionType>
 bool aptitude_resolver_dep::broken_under(const SolutionType &S) const
 {
   // First, check that the solution actually installs the source.
-  if(const_cast<pkgCache::DepIterator &>(start).ParentVer() != S.version_of(const_cast<pkgCache::DepIterator &>(start).ParentPkg()).get_ver())
+  if(const_cast<pkgCache::DepIterator &>(start).ParentVer() != S.version_of(aptitude_resolver_package(const_cast<pkgCache::DepIterator &>(start).ParentPkg(), cache)).get_ver())
     return false;
 
   if(start->Type != pkgCache::Dep::Conflicts)
@@ -715,7 +763,7 @@
 
       while(!dep.end())
 	{
-	  pkgCache::VerIterator direct_ver=S.version_of(dep.TargetPkg()).get_ver();
+	  pkgCache::VerIterator direct_ver=S.version_of(aptitude_resolver_package(dep.TargetPkg(), cache)).get_ver();
 	  if(!direct_ver.end() &&
 	     _system->VS->CheckDep(direct_ver.VerStr(),
 				   dep->CompareOp,
@@ -726,7 +774,7 @@
 	    {
 	      for(pkgCache::PrvIterator prv=dep.TargetPkg().ProvidesList();
 		  !prv.end(); ++prv)
-		if(prv.OwnerVer() == S.version_of(prv.OwnerPkg()).get_ver())
+		if(prv.OwnerVer() == S.version_of(aptitude_resolver_package(prv.OwnerPkg(), cache)).get_ver())
 		  return false;
 	    }
 
@@ -748,7 +796,7 @@
 	  if(const_cast<pkgCache::DepIterator &>(start).TargetPkg() == const_cast<pkgCache::DepIterator &>(start).ParentPkg())
 	    return false;
 
-	  pkgCache::VerIterator direct_ver=S.version_of(const_cast<pkgCache::DepIterator &>(start).TargetPkg()).get_ver();
+	  pkgCache::VerIterator direct_ver=S.version_of(aptitude_resolver_package(const_cast<pkgCache::DepIterator &>(start).TargetPkg(), cache)).get_ver();
 
 	  if(!(!direct_ver.end() &&
 	       _system->VS->CheckDep(direct_ver.VerStr(),
@@ -766,24 +814,41 @@
 	  if(start.TargetVer())
 	    return false;
 
-	  return S.version_of(const_cast<pkgCache::PrvIterator &>(prv).OwnerPkg()).get_ver()==const_cast<pkgCache::PrvIterator &>(prv).OwnerVer();
+	  return S.version_of(aptitude_resolver_package(const_cast<pkgCache::PrvIterator &>(prv).OwnerPkg(), cache)).get_ver()==const_cast<pkgCache::PrvIterator &>(prv).OwnerVer();
 	}
     }
 }
 
 class aptitude_universe
 {
+  aptitudeDepCache *cache;
+
+  aptitude_universe();
 public:
   typedef aptitude_resolver_package package;
   typedef aptitude_resolver_version version;
   typedef aptitude_resolver_dep dep;
 
+  aptitude_universe(aptitudeDepCache *_cache)
+    :cache(_cache)
+  {
+  }
+
+  aptitudeDepCache *get_cache() const {return cache;}
+
   class package_iterator
   {
+    pkgDepCache *cache;
     pkgCache::PkgIterator realiter;
   public:
-    package_iterator(pkgCache::PkgIterator _realiter)
-      :realiter(_realiter)
+    package_iterator()
+      :cache(0)
+    {
+    }
+
+    package_iterator(pkgCache::PkgIterator _realiter,
+		     pkgDepCache *_cache)
+      :cache(_cache), realiter(_realiter)
     {
     }
 
@@ -805,7 +870,7 @@
 
     package operator*() const
     {
-      return realiter;
+      return package(realiter, cache);
     }
 
     package_iterator &operator++()
@@ -823,6 +888,8 @@
   // ew
   class dep_iterator
   {
+    pkgDepCache *cache;
+
     class pkgCache::PkgIterator pkg;
     class pkgCache::VerIterator ver;
     class pkgCache::DepIterator dep;
@@ -897,9 +964,18 @@
 	}
     }
   public:
+#if 0
+    dep_iterator()
+      :cache(0)
+    {
+    }
+#endif
+
     // Start from the given package (typically Head() or End()).
-    dep_iterator(const pkgCache::PkgIterator &_pkg)
-      :pkg(_pkg), prv(*apt_cache_file, 0, (pkgCache::Package *) 0),
+    dep_iterator(const pkgCache::PkgIterator &_pkg,
+		 pkgDepCache *_cache)
+      :cache(_cache),
+       pkg(_pkg), prv(*_cache, 0, (pkgCache::Package *) 0),
        prv_open(false)
     {
       if(!pkg.end())
@@ -912,7 +988,7 @@
 
     aptitude_universe::dep operator*() const
     {
-      return aptitude_universe::dep(dep, prv);
+      return aptitude_universe::dep(dep, prv, cache);
     }
 
     dep_iterator &operator++()
@@ -972,6 +1048,8 @@
    */
   class broken_dep_iterator
   {
+    pkgDepCache *cache;
+
     class pkgCache::PkgIterator pkg;
     class pkgCache::DepIterator the_dep;
     /** If the_dep is a Conflicts, then the following keep track
@@ -988,7 +1066,7 @@
       while(d2->CompareOp & pkgCache::Dep::Or)
 	++d2;
 
-      return ((*apt_cache_file)[d2] & pkgDepCache::DepGInstall)==0;
+      return ((*cache)[d2] & pkgDepCache::DepGInstall)==0;
     }
 
     // Push forward to the next interesting point.
@@ -1005,13 +1083,13 @@
 	  // Otherwise we just spin on the same package over and over,
 	  // since it's still broken..
 	  ++pkg;
-	  while(!pkg.end() && !(*apt_cache_file)[pkg].InstBroken())
+	  while(!pkg.end() && !(*cache)[pkg].InstBroken())
 	    ++pkg;
 
 	  if(!pkg.end())
 	    {
 	      // Examine just the InstVer of the package.
-	      pkgCache::VerIterator ver=(*apt_cache_file)[pkg].InstVerIter(*apt_cache_file);
+	      pkgCache::VerIterator ver=(*cache)[pkg].InstVerIter(*cache);
 
 	      if(!ver.end())
 		the_dep=ver.DependsList();
@@ -1040,7 +1118,7 @@
 	      // right away.
 	      if(the_dep.TargetPkg() != the_dep.ParentPkg())
 		{
-		  pkgCache::VerIterator ver=(*apt_cache_file)[the_dep.TargetPkg()].InstVerIter(*apt_cache_file);
+		  pkgCache::VerIterator ver=(*cache)[the_dep.TargetPkg()].InstVerIter(*cache);
 
 		  if(!ver.end() &&
 		     (!the_dep.TargetVer() ||
@@ -1068,7 +1146,7 @@
 		{
 		  // First, is the providing version going to be
 		  // installed?
-		  if((*apt_cache_file)[prv.OwnerPkg()].InstVerIter(*apt_cache_file) == prv.OwnerVer())
+		  if((*cache)[prv.OwnerPkg()].InstVerIter(*cache) == prv.OwnerVer())
 		    {
 		      // Ok, does it match the version string?
 		      if(!the_dep.TargetVer() ||
@@ -1094,14 +1172,23 @@
 	}
     }
   public:
+#if 0
+    broken_dep_iterator()
+      :cache(0)
+    {
+    }
+#endif
+
     // Start from the given package (typically Head() or End()).
-    broken_dep_iterator(const pkgCache::PkgIterator &_pkg)
-      :pkg(_pkg), prv(*apt_cache_file, 0, (pkgCache::Package *) 0),
+    broken_dep_iterator(const pkgCache::PkgIterator &_pkg,
+			pkgDepCache *_cache)
+      :cache(_cache),
+       pkg(_pkg), prv(*_cache, 0, (pkgCache::Package *) 0),
        prv_open(false)
     {
       if(!pkg.end())
 	{
-	  pkgCache::VerIterator ver=(*apt_cache_file)[pkg].InstVerIter(*apt_cache_file);
+	  pkgCache::VerIterator ver=(*cache)[pkg].InstVerIter(*cache);
 
 	  if(!ver.end())
 	    the_dep=ver.DependsList();
@@ -1112,7 +1199,7 @@
 
     aptitude_universe::dep operator*() const
     {
-      return aptitude_universe::dep(the_dep, prv);
+      return aptitude_universe::dep(the_dep, prv, cache);
     }
 
     broken_dep_iterator &operator++()
@@ -1141,25 +1228,25 @@
     }
   };
 
-  static package_iterator packages_begin()
+  package_iterator packages_begin() const
   {
-    return (*apt_cache_file)->PkgBegin();
+    return package_iterator(cache->PkgBegin(), cache);
   }
 
-  static dep_iterator deps_begin()
+  dep_iterator deps_begin() const
   {
-    return (*apt_cache_file)->PkgBegin();
+    return dep_iterator(cache->PkgBegin(), cache);
   }
 
-  static broken_dep_iterator broken_begin()
+  broken_dep_iterator broken_begin() const
   {
-    return (*apt_cache_file)->PkgBegin();
+    return broken_dep_iterator(cache->PkgBegin(), cache);
   }
 
-  static unsigned long get_version_count()
+  unsigned long get_version_count() const
   {
     // PackageCount is added to make room for the UNINST versions.
-    return (*apt_cache_file)->Head().VersionCount+(*apt_cache_file)->Head().PackageCount;
+    return cache->Head().VersionCount+cache->Head().PackageCount;
   }
 };
 
@@ -1169,7 +1256,8 @@
 public:
   aptitude_resolver(int step_score, int broken_score,
 		    int infinity, int max_successors,
-		    int resolution_score);
+		    int resolution_score,
+		    aptitudeDepCache *cache);
 
   /** Assign scores to all packages and all package versions according
    *  to its arguments.  All scores are assigned with add_score, so