Boost logo

Boost-Commit :

From: sixtrillion_at_[hidden]
Date: 2007-05-29 23:23:13


Author: sixtrillion
Date: 2007-05-29 23:23:11 EDT (Tue, 29 May 2007)
New Revision: 4361
URL: http://svn.boost.org/trac/boost/changeset/4361

Log:
This fixes iterator issues - crashed on Windows. The registry class still does not close libraries correctly. The reason is that there is one structure that is instantiated inside a shared library that needs to be destroyed. It will actually require a rather complicated solution - as such, it will not be ready for the current release.

Text files modified:
   sandbox/boost/extension/counted_factory_map.hpp | 31 ++++++++++++++++++-------------
   sandbox/boost/extension/factory_map.hpp | 13 +++++++++----
   sandbox/boost/extension/registry.hpp | 12 ++++++++++--
   sandbox/libs/extension/scripts/GenerateHeaders.py | 34 +++++++++++++++++++++++-----------
   4 files changed, 60 insertions(+), 30 deletions(-)

Modified: sandbox/boost/extension/counted_factory_map.hpp
==============================================================================
--- sandbox/boost/extension/counted_factory_map.hpp (original)
+++ sandbox/boost/extension/counted_factory_map.hpp 2007-05-29 23:23:11 EDT (Tue, 29 May 2007)
@@ -30,21 +30,26 @@
   class factory_container : public std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >, public generic_factory_container
   {
   public:
+ int * counter_;
+ factory_container(int * counter) : counter_(counter) {++(*counter_);}
+ virtual ~factory_container() {--(*counter_);}
     virtual bool remove_library(const char * library_name)
     {
       for (typename std::list<counted_factory<Interface, Info, Param1, Param2, Param3,
               Param4, Param5, Param6> >::iterator it = this->begin();
- it != this->end(); ++it)
+ it != this->end();)
       {
         if (strcmp(it->library(), library_name) == 0)
- this->erase(it);
+ this->erase(it++);
+ else
+ ++it;
       }
       return this->size() == 0;
     }
- factory_container(){}
- factory_container(basic_counted_factory_map & z)
- :std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
- virtual ~factory_container(){}
+ // factory_container() {}
+ // factory_container(basic_counted_factory_map & z)
+ // :std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
+ //virtual ~factory_container(){}
   };
   typedef std::map<TypeInfo, generic_factory_container *> FactoryMap;
   FactoryMap factories_;
@@ -72,7 +77,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info> * ret =
- new factory_container<Interface, Info>();
+ new factory_container<Interface, Info>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -109,7 +114,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1> * ret =
- new factory_container<Interface, Info, Param1>();
+ new factory_container<Interface, Info, Param1>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -146,7 +151,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1, Param2> * ret =
- new factory_container<Interface, Info, Param1, Param2>();
+ new factory_container<Interface, Info, Param1, Param2>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -183,7 +188,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1, Param2, Param3> * ret =
- new factory_container<Interface, Info, Param1, Param2, Param3>();
+ new factory_container<Interface, Info, Param1, Param2, Param3>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -220,7 +225,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1, Param2, Param3, Param4> * ret =
- new factory_container<Interface, Info, Param1, Param2, Param3, Param4>();
+ new factory_container<Interface, Info, Param1, Param2, Param3, Param4>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -257,7 +262,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5> * ret =
- new factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5>();
+ new factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }
@@ -294,7 +299,7 @@
       if (it == factories_.end())
       {
         factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> * ret =
- new factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6>();
+ new factory_container<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6>(current_counter_);
         factories_[current_type] = ret;
         return *ret;
       }

Modified: sandbox/boost/extension/factory_map.hpp
==============================================================================
--- sandbox/boost/extension/factory_map.hpp (original)
+++ sandbox/boost/extension/factory_map.hpp 2007-05-29 23:23:11 EDT (Tue, 29 May 2007)
@@ -29,10 +29,15 @@
   class factory_container : public std::list<factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >, public generic_factory_container
   {
   public:
- factory_container(){}
- factory_container(basic_factory_map & z)
- :std::list<factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
- virtual ~factory_container(){}
+ factory_container() {}
+ // factory_container(basic_factory_map & z)
+ // :std::list<factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
+ virtual ~factory_container(){}
+
+ // factory_container() {}
+ // factory_container(basic_factory_map & z)
+ // :std::list<factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
+ //virtual ~factory_container(){}
   };
   typedef std::map<TypeInfo, generic_factory_container *> FactoryMap;
   FactoryMap factories_;

Modified: sandbox/boost/extension/registry.hpp
==============================================================================
--- sandbox/boost/extension/registry.hpp (original)
+++ sandbox/boost/extension/registry.hpp 2007-05-29 23:23:11 EDT (Tue, 29 May 2007)
@@ -70,8 +70,16 @@
     if (it == libraries_.end())
       return false;
     for (typename basic_counted_factory_map<TypeInfo>::FactoryMap::iterator it = this->factories_.begin();
- it != this->factories_.end(); ++it) {
- it->second->remove_library(library_location);
+ it != this->factories_.end();) {
+ if(it->second->remove_library(library_location))
+ {
+ delete it->second;
+ this->factories_.erase(it++);
+ }
+ else
+ {
+ ++it;
+ }
     }
     it->second.first.close();
     libraries_.erase(it);

Modified: sandbox/libs/extension/scripts/GenerateHeaders.py
==============================================================================
--- sandbox/libs/extension/scripts/GenerateHeaders.py (original)
+++ sandbox/libs/extension/scripts/GenerateHeaders.py 2007-05-29 23:23:11 EDT (Tue, 29 May 2007)
@@ -11,23 +11,34 @@
     self.generate_factory_hpp()
     self.generate_counted_factory_hpp()
     self.generate_shared_library_hpp()
- self.generate_factory_map_hpp("factory", "", "")
+ self.generate_factory_map_hpp("factory", "", "", "", """
+ factory_container() {}
+ // factory_container(basic_factory_map & z)
+ // :std::list<factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
+ virtual ~factory_container(){}
+ """)
     self.generate_factory_map_hpp("counted_factory",
       "\n f.set_library(current_library_.c_str());\n f.set_counter(current_counter_);",
       "\n std::string current_library_;\n int default_counter_;\n int * current_counter_;",
       "\n virtual bool remove_library(const char * library_name) = 0;", """
+ int * counter_;
+ factory_container(int * counter) : counter_(counter) {++(*counter_);}
+ virtual ~factory_container() {--(*counter_);}
     virtual bool remove_library(const char * library_name)
     {
       for (typename std::list<counted_factory<Interface, Info, Param1, Param2, Param3,
               Param4, Param5, Param6> >::iterator it = this->begin();
- it != this->end(); ++it)
+ it != this->end();)
       {
         if (strcmp(it->library(), library_name) == 0)
- this->erase(it);
+ this->erase(it++);
+ else
+ ++it;
       }
       return this->size() == 0;
     }""",
- "\n basic_counted_factory_map() : default_counter_(0), current_counter_(&default_counter_){}")
+ "\n basic_counted_factory_map() : default_counter_(0), current_counter_(&default_counter_){}",
+ "current_counter_")
       
   def template_header(self, start_string, start, count, add_void):
     if add_void:
@@ -349,7 +360,8 @@
      
   def generate_factory_map_hpp(self, factory_type, factory_type_add, new_members,
                                generic_factory_container_additions = "",
- factory_container_additions = "", new_public_members = ""):
+ factory_container_contents = "", new_public_members = "",
+ factory_container_params = ""):
     out = open(''.join(['../../../boost/extension/',factory_type,'_map.hpp']), mode='w')
     out.write(''.join(["""/* (C) Copyright Jeremy Pack 2007
  * Distributed under the Boost Software License, Version 1.0. (See
@@ -381,11 +393,11 @@
   template <class Interface, class Info, class Param1 = void, class Param2 = void, class Param3 = void, class Param4 = void, class Param5 = void, class Param6 = void>
   class factory_container : public std::list<""",factory_type,"""<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >, public generic_factory_container
   {
- public:""", factory_container_additions, """
- factory_container(){}
- factory_container(basic_""", factory_type, """_map & z)
- :std::list<""",factory_type,"""<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
- virtual ~factory_container(){}
+ public:""", factory_container_contents, """
+ // factory_container() {}
+ // factory_container(basic_""", factory_type, """_map & z)
+ // :std::list<""",factory_type,"""<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >(z.get<Interface, Param1, Param2, Param3, Param4, Param5, Param6>()){}
+ //virtual ~factory_container(){}
   };
   typedef std::map<TypeInfo, generic_factory_container *> FactoryMap;
   FactoryMap factories_;""", new_members,"""
@@ -428,7 +440,7 @@
            """> * ret =
           new factory_container<""",
            self.nameless_param_list(i, ["Interface", "Info"]),
- """>();
+ """>(""",factory_container_params,""");
         factories_[current_type] = ret;
         return *ret;
       }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk