Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-10-19 14:07:27


that's what I mean. Now suppose your A.hpp is included in two different
*.cpp files that are used to create two different DLLS? When linking
statically, the duplicate instances can be eliminated. For DLLs the link is
done at run time so this is not possible. As far as I know, the results are
undefined in this situation and mostly likely vary between os environments.
Your test suggests that for your environment gcc/linux this is all resolved
automagically which I have to concede leaves me impressed.

Still, to fully support this idea, changes in the library would be required
to update some internal structures when a DLL is unloaded. As I said
before, this is certainly doable - doing in such a way as to avoid making
the library implementation even more obscure will require some effort.

And of course, your little bit of dl.RTLD_GLOBAL|dl.RTLD_NOW will have to be
added to the reference manual.

if anyone wants to do this work let me know.

Robert Ramey

"Neal D. Becker" <ndbecker2_at_[hidden]> wrote in message
news:cl3n84$2me$1_at_sea.gmane.org...
> You mean this?
> ,----[ /disk1/nbecker/stuff/A.hpp ]
> | // {{{ struct A
> |
> | template<class i_type>
> | struct A {
> | i_type i;
> | A() { i = 1; }
> | static const A instance;
> | };
> |
> | // }}}
> |
> | template<class i_type>
> | extern const A<i_type> A<i_type>::instance = A();
> |
> | template<>
> | extern const A<int> A<int>::instance = A<int>();
> `----
> ,----[ /disk1/nbecker/stuff/A.cc ]
> | #include <boost/python/module.hpp>
> | #include <boost/python/def.hpp>
> | #include <boost/python/class.hpp>
> | #include <boost/python/init.hpp>
> | #include <boost/python/reference_existing_object.hpp>
> | #include "A.hpp"
> |
> | namespace python = boost::python;
> |
> | int get() { return int(&A<int>::instance); }
> |
> | BOOST_PYTHON_MODULE(A)
> | {
> | python::def ("get", &get);
> | }
> `----
> ,----[ /disk1/nbecker/stuff/B.cc ]
> | #include <boost/python/module.hpp>
> | #include <boost/python/def.hpp>
> | #include <boost/python/class.hpp>
> | #include <boost/python/init.hpp>
> | #include <boost/python/reference_existing_object.hpp>
> | #include "A.hpp"
> |
> | namespace python = boost::python;
> |
> | int get() { return int(&A<int>::instance); }
> |
> | BOOST_PYTHON_MODULE(B)
> | {
> | python::def ("get", &get);
> | }
> `----
> python
> Python 2.3.4 (#1, Aug 31 2004, 11:13:54)
> [GCC 3.4.1 20040815 (Red Hat 3.4.1-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> import dl
> >>> sys.setdlopenflags (dl.RTLD_GLOBAL|dl.RTLD_NOW)
> >>> import A
> >>> import B
> >>> A.get()
> -155365500
> >>> B.get()
> -155365500
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk