]> git.tdb.fi Git - builder.git/commitdiff
Store lookup failures separately from the package map
authorMikko Rasa <tdb@tdb.fi>
Wed, 15 Aug 2012 16:15:19 +0000 (19:15 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 15 Aug 2012 16:24:33 +0000 (19:24 +0300)
This ensures that every pointer in the package map is valid, avoiding the
need to check them and preventing segfaults due to a forgotten check.

source/builder.cpp
source/packagemanager.cpp
source/packagemanager.h

index f894de08fda7bfb55d0bade32d1f94055a7d26b9..3ac4b282ad9d19615236714b01cfc75345d55c8c 100644 (file)
@@ -259,7 +259,7 @@ int Builder::main()
        list<string> package_details;
        for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
        {
-               if(!i->second || !i->second->is_prepared())
+               if(!i->second->is_prepared())
                        continue;
 
                string line = i->second->get_name();
index 746755eaf2d36b4afac5273fbfc5fc9375c9f183..240bf60caafd888ad9b56845331235c8849dce62 100644 (file)
@@ -59,6 +59,9 @@ void PackageManager::add_package(Package *pkg)
 
 Package *PackageManager::find_package(const string &name)
 {
+       if(not_found.count(name))
+               return 0;
+
        PackageMap::iterator i = packages.find(name);
        if(i!=packages.end())
                return i->second;
@@ -84,22 +87,21 @@ Package *PackageManager::find_package(const string &name)
                        return i->second;
        }
 
-       Package *pkg = 0;
        try
        {
                // Package source not found - create a binary package
                string flags_str = run_pkgconfig(name, "flags");
                vector<string> flags = split(flags_str);
-               pkg = BinaryPackage::from_flags(builder, name, flags);
+               Package *pkg = BinaryPackage::from_flags(builder, name, flags);
+               packages.insert(PackageMap::value_type(name, pkg));
+               return pkg;
        }
        catch(...)
        {
                builder.problem(name, "not found");
+               not_found.insert(name);
+               return 0;
        }
-
-       packages.insert(PackageMap::value_type(name, pkg));
-
-       return pkg;
 }
 
 string PackageManager::run_pkgconfig(const string &pkg, const string &what)
index 2fbaca1c37c03dc0afafb3fa36d63402ec1535f3..9fb373ec48152b70a16a5e56b93604c08176b38c 100644 (file)
@@ -28,6 +28,7 @@ private:
        SearchPath binpkg_files;
        bool no_externals;
        PackageMap packages;
+       std::set<std::string> not_found;
        bool env_set;
 
 public: