Fix various issues related to stability when using highly compliant compilers such as Comeau 4.3.0.1, VC7.1 and GCC 3.2

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@108 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rani_sharoni 2003-02-27 20:09:08 +00:00
parent 80e63b12a3
commit b53b3265e4
56 changed files with 441 additions and 203 deletions

View file

@ -21,7 +21,7 @@
#ifndef FACTORY_INC_
#define FACTORY_INC_
#include "TypeInfo.h"
#include "LokiTypeInfo.h"
#include "AssocVector.h"
#include <exception>

106
MSVC/1200/LokiTypeInfo.h Normal file
View file

@ -0,0 +1,106 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
// 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 author or Addison-Wesley Longman make no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
#ifndef LOKITYPEINFO_INC_
#define LOKITYPEINFO_INC_
#include <typeinfo>
#include <cassert>
#include "Typelist.h"
namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// class TypeInfo
// Purpose: offer a first-class, comparable wrapper over std::type_info
////////////////////////////////////////////////////////////////////////////////
class TypeInfo
{
public:
// Constructors
TypeInfo(); // needed for containers
TypeInfo(const std::type_info&); // non-explicit
// Access for the wrapped std::type_info
const std::type_info& Get() const;
// Compatibility functions
bool before(const TypeInfo& rhs) const;
const char* name() const;
private:
const std::type_info* pInfo_;
};
// Implementation
inline TypeInfo::TypeInfo()
{
class Nil {};
pInfo_ = &typeid(Nil);
assert(pInfo_);
}
inline TypeInfo::TypeInfo(const std::type_info& ti)
: pInfo_(&ti)
{ assert(pInfo_); }
inline bool TypeInfo::before(const TypeInfo& rhs) const
{
assert(pInfo_);
return pInfo_->before(*rhs.pInfo_) != 0;
}
inline const std::type_info& TypeInfo::Get() const
{
assert(pInfo_);
return *pInfo_;
}
inline const char* TypeInfo::name() const
{
assert(pInfo_);
return pInfo_->name();
}
// Comparison operators
inline bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
{ return (lhs.Get() == rhs.Get()) != 0; }
inline bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
{ return lhs.before(rhs); }
inline bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs == rhs); }
inline bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
{ return rhs < lhs; }
inline bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs > rhs); }
inline bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs < rhs); }
}
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
////////////////////////////////////////////////////////////////////////////////
#endif // LOKITYPEINFO_INC_

View file

@ -42,7 +42,7 @@
#define MULTIMETHODS_INC_
#include "Typelist.h"
#include "TypeInfo.h"
#include "LokiTypeInfo.h"
#include "Functor.h"
#include "AssocVector.h"

View file

@ -18,7 +18,7 @@
#ifndef FACTORY_INC_
#define FACTORY_INC_
#include "TypeInfo.h"
#include "LokiTypeInfo.h"
#include "AssocVector.h"
#include <exception>

View file

@ -240,7 +240,7 @@ namespace Loki
typedef typename Select
<
SameType<UnitType, TupleUnit<ElementType> >::value,
IsSameType<UnitType, TupleUnit<ElementType> >::value,
ElementType,
UnitType
>
@ -285,7 +285,7 @@ namespace Loki
typedef typename Select
<
SameType<UnitType, TupleUnit<ElementType> >::value,
IsSameType<UnitType, TupleUnit<ElementType> >::value,
ElementType,
UnitType
>

View file

@ -15,8 +15,8 @@
// Last update: May 19, 2002
#ifndef TYPEINFO_INC_
#define TYPEINFO_INC_
#ifndef LOKITYPEINFO_INC_
#define LOKITYPEINFO_INC_
#include <typeinfo>
#include <cassert>
@ -104,4 +104,4 @@ namespace Loki
// May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466)
////////////////////////////////////////////////////////////////////////////////
#endif // TYPEINFO_INC_
#endif // LOKITYPEINFO_INC_

View file

@ -19,7 +19,7 @@
#define MULTIMETHODS_INC_
#include "Typelist.h"
#include "TypeInfo.h"
#include "LokiTypeInfo.h"
#include "Functor.h"
#include "AssocVector.h"

View file

@ -335,14 +335,10 @@ namespace Loki
class SingletonHolderStaticData
{
friend ClientType; // illegal (11.4/2) but works with VC
static ThreadingModelType s_ThreadingModelData;
static PtrInstanceType s_pInstance;
static bool s_destroyed;
};
template<class C, class M, class P>
M SingletonHolderStaticData<C, M, P>::s_ThreadingModelData;
template<class C, class M, class P>
P SingletonHolderStaticData<C, M, P>::s_pInstance;
@ -382,9 +378,7 @@ namespace Loki
// Helpers
static void MakeInstance()
{
typename ThreadingModel<T>::Lock guard(
MySingletonHolderStaticData::s_ThreadingModelData);
typename ThreadingModel<SingletonHolder>::Lock guard;
(void)guard;
if (!pInstance_())

View file

@ -273,6 +273,9 @@ FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p)
Chunk* loBound = &chunks_.front();
Chunk* hiBound = &chunks_.back() + 1;
// Special case: deallocChunk_ is the last in the array
if (hi == hiBound) hi = 0;
for (;;)
{
if (lo)

View file

@ -127,20 +127,6 @@ namespace Loki
// allocations/deallocations
////////////////////////////////////////////////////////////////////////////////
template
<
class ClientType,
class ThreadingModelType
>
class SmallObjectStaticData
{
friend ClientType; // illegal (11.4/2) but works with VC
static ThreadingModelType s_ThreadingModelData;
};
template<class C, class M>
M SmallObjectStaticData<C, M>::s_ThreadingModelData;
template
<
template <class> class ThreadingModel = DEFAULT_THREADING,
@ -153,13 +139,6 @@ namespace Loki
typedef ThreadingModel< SmallObject<ThreadingModel,
chunkSize, maxSmallObjectSize> > MyThreadingModel;
typedef SmallObjectStaticData
<
SmallObject,
MyThreadingModel
>
MySmallObjectStaticData;
struct MySmallObjAllocator : public SmallObjAllocator
{
MySmallObjAllocator()
@ -175,8 +154,7 @@ namespace Loki
static void* operator new(std::size_t size)
{
#if (MAX_SMALL_OBJECT_SIZE != 0) && (DEFAULT_CHUNK_SIZE != 0)
typename MyThreadingModel::Lock lock(
MySmallObjectStaticData::s_ThreadingModelData);
typename MyThreadingModel::Lock lock;
(void)lock; // get rid of warning
return SingletonHolder<MySmallObjAllocator, CreateStatic,
@ -188,8 +166,7 @@ namespace Loki
static void operator delete(void* p, std::size_t size)
{
#if (MAX_SMALL_OBJECT_SIZE != 0) && (DEFAULT_CHUNK_SIZE != 0)
typename MyThreadingModel::Lock lock(
MySmallObjectStaticData::s_ThreadingModelData);
typename MyThreadingModel::Lock lock;
(void)lock; // get rid of warning
SingletonHolder<MySmallObjAllocator, CreateStatic,

View file

@ -155,7 +155,9 @@ namespace Loki
// class template RefCountedMT
// Implementation of the OwnershipPolicy used by SmartPtr
// Implements external reference counting for multithreaded programs
// Policy Usage: RefCountedMTAdj<ThreadingModel>::RefCountedMT
////////////////////////////////////////////////////////////////////////////////
template <template <class> class ThreadingModel>
struct RefCountedMTAdj
{

View file

@ -54,9 +54,6 @@ namespace Loki
static IntType AtomicDecrement(volatile IntType& lval)
{ return --lval; }
static IntType AtomicDivide(volatile IntType& lval)
{ return lval /= val; }
static void AtomicAssign(volatile IntType & lval, IntType val)
{ lval = val; }
@ -98,13 +95,13 @@ namespace Loki
Lock(const Lock&);
Lock& operator=(const Lock&);
Lock(); // buggy design
public:
explicit Lock(ObjectLevelLockable& host) : host_(host)
{
::EnterCriticalSection(&host_.mtx_);
}
~Lock()
{
::LeaveCriticalSection(&host_.mtx_);

View file

@ -73,18 +73,18 @@ namespace Loki
typedef typename In<flag>::Result Result;
};
/*
////////////////////////////////////////////////////////////////////////////////
// class template SameType
// class template IsSameType
// Return true iff two given types are the same
// Invocation: SameType<T, U>::value
// Invocation: IsSameType<T, U>::value
// where:
// T and U are types
// Result evaluates to true iff U == T (types equal)
////////////////////////////////////////////////////////////////////////////////
template <typename T, typename U>
struct SameType
struct IsSameType
{
private:
template<typename>
@ -98,7 +98,6 @@ namespace Loki
public:
enum { value = In<U>::value };
};
//*/
////////////////////////////////////////////////////////////////////////////////
// Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big)
@ -113,10 +112,10 @@ namespace Loki
struct IsVoid
{
enum { result =
SameType<T, void>::value ||
SameType<T, const void>::value ||
SameType<T, volatile void>::value ||
SameType<T, const volatile void>::value
IsSameType<T, void>::value ||
IsSameType<T, const void>::value ||
IsSameType<T, volatile void>::value ||
IsSameType<T, const volatile void>::value
};
};
}
@ -172,7 +171,7 @@ namespace Loki
{
enum { exists = (is_convertible<T,U>::exists) };
enum { exists2Way = (exists && is_convertible<U, T>::exists) };
enum { sameType = (SameType<T, U>::value) };
enum { sameType = (IsSameType<T, U>::value) };
};
////////////////////////////////////////////////////////////////////////////////
@ -238,7 +237,7 @@ struct SuperSubclassStrict
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466)
// October 10, 2002: Commented SameType template (not a Loki-template - yet). MKH
// October 10, 2002: Commented IsSameType template (not a Loki-template - yet). MKH
// October 12, 2002: Added SuperSubclass and SuperSubclassStrict templates.
// The corresponding macros are deprecated. T.S.
////////////////////////////////////////////////////////////////////////////////

View file

@ -226,10 +226,10 @@ namespace Loki
enum {
isVoid =
SameType<T, void>::value ||
SameType<T, const void>::value ||
SameType<T, volatile void>::value ||
SameType<T, const volatile void>::value
IsSameType<T, void>::value ||
IsSameType<T, const void>::value ||
IsSameType<T, volatile void>::value ||
IsSameType<T, const volatile void>::value
};
enum { isStdUnsignedInt =

View file

@ -766,7 +766,7 @@ typedef char _type_##_is_not_a_Typelist[true]
public:
typedef typename Select
<
SameType<Head, T>::value,
IsSameType<Head, T>::value,
TailResult,
Typelist<Head, TailResult>
>
@ -885,7 +885,7 @@ typedef char _type_##_is_not_a_Typelist[true]
public:
typedef typename Select
<
SameType<Head, T>::value,
IsSameType<Head, T>::value,
Typelist<U, TailResult>,
Typelist<Head, TailResult>
>