[Boost-bugs] [Boost C++ Libraries] #8414: flyweights causes weird library initialization error

Subject: [Boost-bugs] [Boost C++ Libraries] #8414: flyweights causes weird library initialization error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-04-07 15:34:28


#8414: flyweights causes weird library initialization error
----------------------------------------------------------+-----------------
 Reporter: charles quarra <charlls_quarra@…> | Owner: joaquin
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: flyweight
  Version: Boost 1.53.0 | Severity: Showstopper
 Keywords: |
----------------------------------------------------------+-----------------
 the bug is reproduced with the following test case:

 g++ main.cpp -o xmain -ldl

 main.cpp:
 #include <dlfcn.h>
 #include <iostream>
 int
 main()
 {
     std::cout << "load: " << std::endl;
     void *foo = dlopen("./libpluginTest.so", RTLD_NOW);
     std::cout << "load: library loaded "<< foo << std::endl;
     if (dlclose(foo) < 0) {
         std::cout << "load: library close failed " << std::endl;
         return 1;
     }
     std::cout << "load: library closed " << std::endl;
     return 0;
 }

 ---
 g++ -I/path/to/boost/includes -fPIC -shared -rdynamic test_plugin.cpp -o
 libpluginTest.so -L/path/to/boost/libs -lrt

 test_plugin.cpp:
 #include <iostream>
 //#include <boost/flyweight/intermodule_holder.hpp>
 #include <boost/flyweight.hpp>

 typedef boost::flyweight< std::string > SymbolName_t;

 SymbolName_t getEmptyStringSymbol() {
             SymbolName_t empty("");
             return empty;
         }

 void __attribute__ ((constructor)) library_init()
 {
   std::cout << "Library constructor: " << std::endl;
 }
 void __attribute__ ((destructor)) library_fini()
 {
   std::cout << "Library destructor:" << std::endl;
 }


 this program outputs the following:


 load:
 Library constructor: address of static cbContainer is:
 load: library loaded 0x1226030
 load: library closed
 Library destructor:

 as this shows, the library destructor is called at program termination,
 and NOT before dlclose returns, which is the expected behavior.
 If we comment the function 'getEmptyStringSymbol', the resulting output
 is:

 load:
 Library constructor: address of static cbContainer is:
 load: library loaded 0x1b0b030
 Library destructor:
 load: library closed

 which is the expected behavior

 this bug has been reproduced on the following compilers:

 g++-4.6 (Ubuntu/Linaro 4.6.3-10ubuntu1) 4.6.3 20120918 (prerelease)
 g++-4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8414>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC