disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..'
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@352 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
1857e40384
commit
4e97accb6a
5 changed files with 224 additions and 24 deletions
|
@ -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<DefaultLifetime>::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<DefaultLifetime>::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
|
||||
//
|
||||
|
|
|
@ -52,8 +52,10 @@ public:
|
|||
typedef SingletonHolder
|
||||
<
|
||||
Factory< AbstractProduct, int >,
|
||||
CreateUsingNew,
|
||||
FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
CreateUsingNew
|
||||
#if !defined(_MSC_VER) || (_MSC_VER>=1400)
|
||||
,FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
#endif
|
||||
>
|
||||
PFactoryNull;
|
||||
|
||||
|
@ -68,8 +70,10 @@ typedef SingletonHolder
|
|||
#else
|
||||
Factory< AbstractProduct, int, Seq< int, int > >,
|
||||
#endif
|
||||
CreateUsingNew,
|
||||
FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
CreateUsingNew
|
||||
#if !defined(_MSC_VER) || (_MSC_VER>=1400)
|
||||
,FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
#endif
|
||||
>
|
||||
PFactory;
|
||||
|
||||
|
@ -167,8 +171,10 @@ SingletonHolder
|
|||
#else
|
||||
Factory< AbstractProduct, int,Seq<CreateFunctor,int,int> >,
|
||||
#endif
|
||||
CreateUsingNew,
|
||||
FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
CreateUsingNew
|
||||
#if !defined(_MSC_VER) || (_MSC_VER>=1400)
|
||||
,FollowIntoDeath::AfterMaster<Functor<>::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
|
||||
//
|
||||
|
|
|
@ -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 <iostream>
|
||||
|
||||
|
@ -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<void> (this, &MyFunctionObject::f);
|
||||
function = Function< void()>(this, &MyFunctionObject::f);
|
||||
}
|
||||
MyFunctionObject()
|
||||
{
|
||||
functor = Functor<void> (this, &MyFunctionObject::f);
|
||||
function = Function< void()>(this, &MyFunctionObject::f);
|
||||
}
|
||||
|
||||
void f(){}
|
||||
Functor<void> functor;
|
||||
Function<void()> function;
|
||||
|
||||
void f(){}
|
||||
Functor<void> functor;
|
||||
Function<void()> function;
|
||||
|
||||
};
|
||||
|
||||
typedef SingletonHolder
|
||||
<
|
||||
MyFunctionObject,
|
||||
CreateUsingNew,
|
||||
FollowIntoDeath::AfterMaster<Function<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
FollowIntoDeath::AfterMaster<Function<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
>
|
||||
Singleton_MyFunctionObject1;
|
||||
|
||||
|
@ -69,7 +80,7 @@ typedef SingletonHolder
|
|||
<
|
||||
MyFunctionObject,
|
||||
CreateUsingNew,
|
||||
FollowIntoDeath::AfterMaster<Functor<>::Impl::ObjAllocatorSingleton>::IsDestroyed
|
||||
FollowIntoDeath::AfterMaster<Functor<>::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)
|
||||
|
|
|
@ -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 (
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
#include "../../include/loki/Singleton.h"
|
||||
#include <iostream>
|
||||
|
||||
// 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
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue