On Thu, Jul 30, 2009 at 02:04:00AM +0200, Alban Browaeys <[email protected]> was heard to say: > This way ? It fixes the issue though it looks to me as it breaks the > design (as it make cache part of > the api, though this may be minor : probably is_valid_cache could be > replaced by is_valid and the function could > include more checks). > Mind that I am new to c++ so the usage of const may be invalid or the > function ought > to be in the .cc .
I was thinking more this way. Daniel
changeset: 3130:75fb72c6bc8f tag: tip user: Daniel Burrows <[email protected]> date: Wed Jul 29 08:28:37 2009 -0700 summary: Make resolver objects created by empty constructors return end iterators from their get_*() routines instead of crashing. diff -r 4b8a7d0e706d -r 75fb72c6bc8f src/generic/apt/aptitude_resolver_universe.h --- a/src/generic/apt/aptitude_resolver_universe.h Tue Jul 28 08:26:51 2009 -0700 +++ b/src/generic/apt/aptitude_resolver_universe.h Wed Jul 29 08:28:37 2009 -0700 @@ -93,7 +93,10 @@ /** \return The underlying APT package wrapped by this object. */ pkgCache::PkgIterator get_pkg() const { - return pkgCache::PkgIterator(*cache, const_cast<pkgCache::Package *>(pkg)); + if(cache == NULL) + return pkgCache::PkgIterator(); + else + return pkgCache::PkgIterator(*cache, const_cast<pkgCache::Package *>(pkg)); } // Note that it's not necessary to compare the cache along with the @@ -198,13 +201,18 @@ */ pkgCache::PkgIterator get_pkg() const { - pkgCache &pcache(cache->GetCache()); + if(cache == NULL) + return pkgCache::PkgIterator(); + else + { + pkgCache &pcache(cache->GetCache()); - if(is_version) - return pkgCache::PkgIterator(pcache, - pcache.PkgP + (pcache.VerP[offset].ParentPkg)); - else - return pkgCache::PkgIterator(pcache, pcache.PkgP + offset); + if(is_version) + return pkgCache::PkgIterator(pcache, + pcache.PkgP + (pcache.VerP[offset].ParentPkg)); + else + return pkgCache::PkgIterator(pcache, pcache.PkgP + offset); + } } /** \return The APT version wrapped by this object, or an end @@ -212,12 +220,17 @@ */ pkgCache::VerIterator get_ver() const { - pkgCache &pcache(cache->GetCache()); + if(cache == NULL) + return pkgCache::VerIterator(); + else + { + pkgCache &pcache(cache->GetCache()); - if(!is_version) - return pkgCache::VerIterator(pcache, 0); - else - return pkgCache::VerIterator(pcache, pcache.VerP + offset); + if(!is_version) + return pkgCache::VerIterator(pcache, 0); + else + return pkgCache::VerIterator(pcache, pcache.VerP + offset); + } } /** \return The APT ID of this version if it is a real version, @@ -478,7 +491,10 @@ /** \return The APT dependency associated with this abstract dependency. */ pkgCache::DepIterator get_dep() const { - return pkgCache::DepIterator(cache->GetCache(), const_cast<pkgCache::Dependency *>(start)); + if(cache == NULL) + return pkgCache::DepIterator(); + else + return pkgCache::DepIterator(cache->GetCache(), const_cast<pkgCache::Dependency *>(start)); } /** \return The APT Provides relationship associated with this @@ -486,8 +502,11 @@ */ pkgCache::PrvIterator get_prv() const { - return pkgCache::PrvIterator(cache->GetCache(), const_cast<pkgCache::Provides *>(prv), - (pkgCache::Version *)0); + if(cache == NULL) + return pkgCache::PrvIterator(); + else + return pkgCache::PrvIterator(cache->GetCache(), const_cast<pkgCache::Provides *>(prv), + (pkgCache::Version *)0); } /** \return \b true if the given version will resolve this dependency. */
_______________________________________________ Aptitude-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/aptitude-devel

