[buildd-tools-devel] [PATCH 10/12] [chroot::facets] Convert from vector to list

Jan-Marek Glogowski glogow at fbihome.de
Fri Jul 31 14:21:47 UTC 2009


For chroots implementing the union facet a source facet is added
dynamically to the facet. This happens on load depending on the
configured union type and renders most iterators invalid.

So we use list as its iterators won't invalidate except if their
list item is freed.
---
 sbuild/sbuild-chroot.cc |   14 +++++++-------
 sbuild/sbuild-chroot.h  |   11 ++++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index 3aeed25..6fc2d43 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -136,7 +136,7 @@ sbuild::chroot::chroot (const chroot& rhs):
   facets()
 {
   /// @todo Use internal version of add_facet to add chroot pointer.
-  for (std::vector<facet_ptr>::const_iterator pos = rhs.facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = rhs.facets.begin();
        pos != rhs.facets.end();
        ++pos)
     {
@@ -411,7 +411,7 @@ sbuild::chroot::list_facets () const
 {
   string_list fnames;
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
@@ -426,7 +426,7 @@ sbuild::chroot::setup_env (environment& env) const
 {
   setup_env(*this, env);
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
@@ -519,7 +519,7 @@ sbuild::chroot::get_session_flags () const
 {
   session_flags flags = get_session_flags(*this);
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
@@ -534,7 +534,7 @@ sbuild::chroot::get_details (format_detail& detail) const
 {
   get_details(*this, detail);
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
@@ -593,7 +593,7 @@ sbuild::chroot::get_keyfile (keyfile& keyfile) const
 {
   get_keyfile(*this, keyfile);
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
@@ -673,7 +673,7 @@ sbuild::chroot::set_keyfile (keyfile const& keyfile,
 {
   set_keyfile(*this, keyfile, used_keys);
 
-  for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+  for (std::list<facet_ptr>::const_iterator pos = facets.begin();
        pos != facets.end();
        ++pos)
     {
diff --git a/sbuild/sbuild-chroot.h b/sbuild/sbuild-chroot.h
index c92a1f8..3d0f13f 100644
--- a/sbuild/sbuild-chroot.h
+++ b/sbuild/sbuild-chroot.h
@@ -28,6 +28,7 @@
 
 #include <ostream>
 #include <string>
+#include <list>
 
 namespace sbuild
 {
@@ -739,7 +740,7 @@ namespace sbuild
     string_list   command_prefix;
 
     typedef std::tr1::shared_ptr<chroot_facet> facet_ptr;
-    std::vector<facet_ptr> facets;
+    std::list<facet_ptr> facets;
   };
 
   /**
@@ -783,7 +784,7 @@ namespace sbuild
   {
     std::tr1::shared_ptr<T> ret;
 
-    for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+    for (std::list<facet_ptr>::const_iterator pos = facets.begin();
 	 pos != facets.end();
 	 ++pos)
       {
@@ -800,7 +801,7 @@ namespace sbuild
   {
     std::tr1::shared_ptr<T> ret;
 
-    for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+    for (std::list<facet_ptr>::const_iterator pos = facets.begin();
 	 pos != facets.end();
 	 ++pos)
       {
@@ -819,7 +820,7 @@ namespace sbuild
     if (!new_facet)
       throw error(FACET_INVALID);
 
-    for (std::vector<facet_ptr>::const_iterator pos = facets.begin();
+    for (std::list<facet_ptr>::const_iterator pos = facets.begin();
 	 pos != facets.end();
 	 ++pos)
       {
@@ -835,7 +836,7 @@ namespace sbuild
   void
   chroot::remove_facet ()
   {
-    for (std::vector<facet_ptr>::iterator pos = facets.begin();
+    for (std::list<facet_ptr>::iterator pos = facets.begin();
 	 pos != facets.end();
 	 ++pos)
       {
-- 
1.6.3.2




More information about the Buildd-tools-devel mailing list