[C++-sig] Re: boost::python::range and duplicate comdat under MSVC 6
Raoul Gough
RaoulGough at yahoo.co.uk
Mon Nov 10 18:46:05 CET 2003
David Abrahams <dave at boost-consulting.com> writes:
> Raoul Gough <RaoulGough at yahoo.co.uk> writes:
>
>>> However, a simple transformation ought to be enough to eliminate the
>>> static data member, AFAICT. Do you need help working it out?
>>
>> It looks to me like the static member is only useful for the
>> side-effects of its constructor. Is there an alternative way to
>> achieve this?
>
> Sure; use a function-static variable in the constructor to make sure
> that the side-effects only happen once, and then change
> class_converters.hpp so that it constructs a shared_ptr_from_python
> on the stack instead of calling force_instantiate.
OK, I've gone with a static variable in register_class_from_python to
force construction of the shared_ptr_from_python. This is wrapped in
MSVC6 workaround guards, so that other compilers still use a
class-static variable. No real reason for doing this, except that it
would probably affect the initialization order on other platforms
unnecessarily, and I just like to minimize the impact of fixes.
Patches follow. OK to commit these on the CVS mainline?
$ cvs diff -c boost/python/converter/shared_ptr_from_python.hpp boost/python/object/class_converters.hpp
Index: boost/python/converter/shared_ptr_from_python.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/python/converter/shared_ptr_from_python.hpp,v
retrieving revision 1.1
diff -c -r1.1 shared_ptr_from_python.hpp
*** boost/python/converter/shared_ptr_from_python.hpp 2 Dec 2002 01:37:39 -0000 1.1
--- boost/python/converter/shared_ptr_from_python.hpp 10 Nov 2003 17:34:53 -0000
***************
*** 8,13 ****
--- 8,14 ----
# include <boost/python/handle.hpp>
# include <boost/python/converter/shared_ptr_deleter.hpp>
+ # include <boost/detail/workaround.hpp>
namespace boost { namespace python { namespace converter {
***************
*** 19,25 ****
--- 20,29 ----
converter::registry::insert(&convertible, &construct, type_id<shared_ptr<T> >());
}
+ # if !BOOST_WORKAROUND (BOOST_MSVC, == 1200)
+ // This static var can cause duplicate comdat link errors with MSVC6
static shared_ptr_from_python const registration;
+ # endif
private:
static void* convertible(PyObject* p)
{
***************
*** 45,52 ****
--- 49,58 ----
}
};
+ # if !BOOST_WORKAROUND (BOOST_MSVC, == 1200)
template <class T>
shared_ptr_from_python<T> const shared_ptr_from_python<T>::registration;
+ # endif
}}} // namespace boost::python::converter
Index: boost/python/object/class_converters.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/python/object/class_converters.hpp,v
retrieving revision 1.15
diff -c -r1.15 class_converters.hpp
*** boost/python/object/class_converters.hpp 21 May 2003 22:17:23 -0000 1.15
--- boost/python/object/class_converters.hpp 10 Nov 2003 17:34:53 -0000
***************
*** 18,23 ****
--- 18,25 ----
# include <boost/mpl/for_each.hpp>
+ # include <boost/detail/workaround.hpp>
+
namespace boost { namespace python { namespace objects {
//////////////////////////////////////////////////////////////////////
***************
*** 76,83 ****
template <class Derived, class Bases>
inline void register_class_from_python(Derived* = 0, Bases* = 0)
{
python::detail::force_instantiate(converter::shared_ptr_from_python<Derived>::registration);
!
// register all up/downcasts here
register_dynamic_id<Derived>();
--- 78,90 ----
template <class Derived, class Bases>
inline void register_class_from_python(Derived* = 0, Bases* = 0)
{
+ # if BOOST_WORKAROUND (BOOST_MSVC, == 1200)
+ // Avoids duplicate comdat link errors with MSVC6
+ static converter::shared_ptr_from_python<Derived> shared_ptr_registration;
+ # else
python::detail::force_instantiate(converter::shared_ptr_from_python<Derived>::registration);
! # endif
!
// register all up/downcasts here
register_dynamic_id<Derived>();
--
Raoul Gough.
(setq dabbrev-case-fold-search nil)
More information about the Cplusplus-sig
mailing list