diff --git a/include/loki/SmallObj.h b/include/loki/SmallObj.h index cdd4b55..d135f6b 100644 --- a/include/loki/SmallObj.h +++ b/include/loki/SmallObj.h @@ -37,12 +37,17 @@ #endif -//#define LOKI_DEFAULT_SMALLOBJ_LIFETIME NoDestroy //#define LOKI_DEFAULT_SMALLOBJ_LIFETIME DefaultLifetime #ifndef LOKI_DEFAULT_SMALLOBJ_LIFETIME -#define LOKI_DEFAULT_SMALLOBJ_LIFETIME \ - FollowIntoDeath::With::AsMasterLifetime + +#if defined(_MSC_VER) && (_MSC_VER<1400) +// msvc 7.1 is faulty and can't handle the FollowIntoDeath and DieOrder lifetime policies +#define LOKI_DEFAULT_SMALLOBJ_LIFETIME NoDestroy +#else +#define LOKI_DEFAULT_SMALLOBJ_LIFETIME FollowIntoDeath::With::AsMasterLifetime +#endif + #endif #if defined(LOKI_SMALL_OBJECT_USE_NEW_ARRAY) && defined(_MSC_VER) @@ -535,6 +540,9 @@ namespace Loki // Nov. 26, 2004: re-implemented by Rich Sposato. // // $Log$ +// Revision 1.21 2005/11/05 17:43:55 syntheticpp +// disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..' +// // Revision 1.20 2005/11/02 20:01:10 syntheticpp // more doxygen documentation, modules added // diff --git a/test/Factory/Factory.cpp b/test/Factory/Factory.cpp index 48d37be..eeaaaec 100755 --- a/test/Factory/Factory.cpp +++ b/test/Factory/Factory.cpp @@ -52,8 +52,10 @@ public: typedef SingletonHolder < Factory< AbstractProduct, int >, - CreateUsingNew, - FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed + CreateUsingNew +#if !defined(_MSC_VER) || (_MSC_VER>=1400) + ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed +#endif > PFactoryNull; @@ -68,8 +70,10 @@ typedef SingletonHolder #else Factory< AbstractProduct, int, Seq< int, int > >, #endif - CreateUsingNew, - FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed + CreateUsingNew +#if !defined(_MSC_VER) || (_MSC_VER>=1400) + ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed +#endif > PFactory; @@ -167,8 +171,10 @@ SingletonHolder #else Factory< AbstractProduct, int,Seq >, #endif - CreateUsingNew, - FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed + CreateUsingNew +#if !defined(_MSC_VER) || (_MSC_VER>=1400) + ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed +#endif > PFactoryFunctorParm; @@ -253,6 +259,9 @@ int main(int argc, char *argv[]) } // $Log$ +// Revision 1.7 2005/11/05 17:43:55 syntheticpp +// disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..' +// // Revision 1.6 2005/11/01 11:38:19 syntheticpp // apply new lifetime policy to avoid crash on exit in test/Factory // diff --git a/test/Singleton/Dependencies.cpp b/test/Singleton/Dependencies.cpp index 82cfcee..8b22ec1 100755 --- a/test/Singleton/Dependencies.cpp +++ b/test/Singleton/Dependencies.cpp @@ -1,4 +1,14 @@ - +//////////////////////////////////////////////////////////////////////////////// +// The Loki Library +// Copyright (c) 2005 Peter Kümmel +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this +// permission notice appear in supporting documentation. +// The authors make no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +//////////////////////////////////////////////////////////////////////////////// #include @@ -8,6 +18,7 @@ using namespace Loki; +#if !defined(_MSC_VER) || (_MSC_VER>=1400) //////////////////////////////////////////////////////////////////////////////////// // @@ -45,23 +56,23 @@ Singleton_of_with_a_MySmallObject; struct MyFunctionObject { - MyFunctionObject() - { - functor = Functor (this, &MyFunctionObject::f); - function = Function< void()>(this, &MyFunctionObject::f); - } + MyFunctionObject() + { + functor = Functor (this, &MyFunctionObject::f); + function = Function< void()>(this, &MyFunctionObject::f); + } - void f(){} - Functor functor; - Function function; - + void f(){} + Functor functor; + Function function; + }; typedef SingletonHolder < MyFunctionObject, CreateUsingNew, - FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed + FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed > Singleton_MyFunctionObject1; @@ -69,7 +80,7 @@ typedef SingletonHolder < MyFunctionObject, CreateUsingNew, - FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed + FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed > Singleton_MyFunctionObject2; @@ -363,8 +374,8 @@ void heap_debug() int main(int argc, char *argv[]) { - MyFunctionObject *f1 = &Singleton_MyFunctionObject1::Instance(); - MyFunctionObject *f2 = &Singleton_MyFunctionObject2::Instance(); + MyFunctionObject *f1 = &Singleton_MyFunctionObject1::Instance(); + MyFunctionObject *f2 = &Singleton_MyFunctionObject2::Instance(); #ifdef _MSC_VER heap_debug(); @@ -407,3 +418,13 @@ int main(int argc, char *argv[]) return 0; } + +#else + +int main() +{ + std::cout<<"code is disabled because of faulty microsoft compiler 7.1"; + return 0; +}; + +#endif //#if !defined(_MSC_VER) || (_MSC_VER>=1400) diff --git a/test/Singleton/make.msvc.bat b/test/Singleton/make.msvc.bat index 3755d9f..668f6a5 100755 --- a/test/Singleton/make.msvc.bat +++ b/test/Singleton/make.msvc.bat @@ -38,7 +38,7 @@ cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W0 -wd4710 -I"." -I"..\..\include" -Fot if not defined LOKI_MSVC_NOLIB ( -link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"Dependencies-msvc.exe" ..\..\lib\loki.lib tmp\Phoenix.obj +link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"Dependencies-msvc.exe" ..\..\lib\loki.lib tmp\Dependencies.obj ) else ( diff --git a/test/SmallObj/SmallSingleton.cpp b/test/SmallObj/SmallSingleton.cpp index c0511b6..32eb689 100644 --- a/test/SmallObj/SmallSingleton.cpp +++ b/test/SmallObj/SmallSingleton.cpp @@ -18,6 +18,9 @@ #include "../../include/loki/Singleton.h" #include +// disable new implementation when using msvc 7.1 +#if !defined(_MSC_VER) || (_MSC_VER>=1400) + // define DO_EXTRA_LOKI_TESTS in src/SmallObj.cpp to get // a message when a SmallObject is created/deleted. @@ -250,9 +253,168 @@ int main() return 0; } + +#else + +using namespace std; + + +// ---------------------------------------------------------------------------- + +typedef Loki::SmallValueObject< LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL, + LOKI_DEFAULT_CHUNK_SIZE, LOKI_MAX_SMALL_OBJECT_SIZE, + LOKI_DEFAULT_OBJECT_ALIGNMENT, Loki::SingletonWithLongevity > +LongLivedObject; + +typedef Loki::SmallValueObject< LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL, + LOKI_DEFAULT_CHUNK_SIZE, LOKI_MAX_SMALL_OBJECT_SIZE, + LOKI_DEFAULT_OBJECT_ALIGNMENT, Loki::NoDestroy > +ImmortalObject; + +// ---------------------------------------------------------------------------- + +class LongLivedSingleton : public LongLivedObject +{ +public: + + typedef Loki::SingletonHolder< LongLivedSingleton, Loki::CreateUsingNew, + Loki::SingletonWithLongevity, LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL > + MySmallSingleton; + + /// Returns reference to the singleton. + inline static LongLivedSingleton & Instance( void ) + { + return MySmallSingleton::Instance(); + } + + LongLivedSingleton( void ) + { + cout << "LongLivedSingleton" << endl; + } + ~LongLivedSingleton( void ) + { + cout << "~LongLivedSingleton" << endl; + } + void DoThat( void ) + { + cout << "LongLivedSingleton::DoThat" << endl; + } +private: + char m_stuff[ 16 ]; +}; + +// ---------------------------------------------------------------------------- + +inline unsigned int GetLongevity( LongLivedSingleton * ) +{ + /// @note Must return a longevity level lower than the one in SmallObj.h. + return 1; +} + +// ---------------------------------------------------------------------------- + +class ImmortalSingleton : public ImmortalObject +{ +public: + + typedef Loki::SingletonHolder< ImmortalSingleton, Loki::CreateUsingNew, + Loki::NoDestroy, LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL > + MySmallSingleton; + + /// Returns reference to the singleton. + inline static ImmortalSingleton & Instance( void ) + { + return MySmallSingleton::Instance(); + } + + ImmortalSingleton( void ) + { + cout << "ImmortalSingleton" << endl; + } + ~ImmortalSingleton( void ) + { + cout << "~ImmortalSingleton destructor should never get called!" << endl; + } + void DoThat( void ) + { + cout << "ImmortalSingleton::DoThat" << endl; + } +private: + char m_stuff[ 16 ]; +}; + +// ---------------------------------------------------------------------------- + +class MortalSingleton : public ImmortalObject +{ +public: + + typedef Loki::SingletonHolder< MortalSingleton, Loki::CreateUsingNew, + Loki::SingletonWithLongevity, LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL > + MySmallSingleton; + + /// Returns reference to the singleton. + inline static MortalSingleton & Instance( void ) + { + return MySmallSingleton::Instance(); + } + + MortalSingleton( void ) + { + cout << "MortalSingleton" << endl; + } + ~MortalSingleton( void ) + { + cout << "~MortalSingleton" << endl; + } + void DoThat( void ) + { + cout << "MortalSingleton::DoThat" << endl; + } +private: + char m_stuff[ 16 ]; +}; + +// ---------------------------------------------------------------------------- + +inline unsigned int GetLongevity( MortalSingleton * ) +{ + /// @note Must return a longevity level lower than the one in SmallObj.h. + return 1; +} + +// ---------------------------------------------------------------------------- + +int main() +{ + cout << "This program tests the three recommended combinations of singleton" << endl + << "lifetime policies for Loki's Small-Object Allocator and singleton" << endl + << "objects that are derived from SmallObject or SmallValueObject." << endl << endl + << "Those 3 recommended combinations are:" << endl + << "\t1. Both SmallObject and derived Singleton use NoDestroy policy." << endl + << "\t This is tested by the ImmortalSingleton class." << endl + << "\t2. Both use SingletonWithLongevity policy." << endl + << "\t This is tested by the LongLivedSingleton class." << endl + << "\t3. SmallObject has NoDestroy policy but the derived Singleton has" << endl + << "\t SingletonWithLongevity policy." << endl + << "\t This is tested by the MortalSingleton class." << endl << endl + << "If this program executes without crashing or asserting at exit time," << endl + << "then all 3 combinations work." << endl << endl; + MortalSingleton::Instance().DoThat(); + LongLivedSingleton::Instance().DoThat(); + ImmortalSingleton::Instance().DoThat(); + system("PAUSE"); + return 0; +} + +#endif + // ---------------------------------------------------------------------------- // $Log$ +// Revision 1.8 2005/11/05 17:43:55 syntheticpp +// disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..' +// // Revision 1.7 2005/11/02 15:00:38 syntheticpp // use new singleton lifetime policies //