fix 857415: Calling convention issue with MSVC

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@133 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rani_sharoni 2003-12-11 16:48:26 +00:00
parent 118c72dad1
commit de3e4bf67c
4 changed files with 34 additions and 18 deletions

View file

@ -27,7 +27,7 @@ unsigned int Loki::Private::elements = 0;
// Ensures proper destruction of objects with longevity // Ensures proper destruction of objects with longevity
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Loki::Private::AtExitFn() void C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
{ {
assert(elements > 0 && pTrackerArray != 0); assert(elements > 0 && pTrackerArray != 0);
// Pick the element at the top of the stack // Pick the element at the top of the stack

View file

@ -25,8 +25,16 @@
#include <cstdlib> #include <cstdlib>
#include <new> #include <new>
#ifdef _MSC_VER
#define C_CALLING_CONVENTION_QUALIFIER __cdecl
#else
#define C_CALLING_CONVENTION_QUALIFIER
#endif
namespace Loki namespace Loki
{ {
typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)();
namespace Private namespace Private
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -87,7 +95,7 @@ namespace Loki
Destroyer destroyer_; Destroyer destroyer_;
}; };
void AtExitFn(); // declaration needed below void C_CALLING_CONVENTION_QUALIFIER AtExitFn(); // declaration needed below
} // namespace Private } // namespace Private
@ -223,7 +231,7 @@ namespace Loki
template <class T> template <class T>
struct DefaultLifetime struct DefaultLifetime
{ {
static void ScheduleDestruction(T*, void (*pFun)()) static void ScheduleDestruction(T*, atexit_pfn_t pFun)
{ std::atexit(pFun); } { std::atexit(pFun); }
static void OnDeadReference() static void OnDeadReference()
@ -241,7 +249,7 @@ namespace Loki
class PhoenixSingleton class PhoenixSingleton
{ {
public: public:
static void ScheduleDestruction(T*, void (*pFun)()) static void ScheduleDestruction(T*, atexit_pfn_t pFun)
{ {
#ifndef ATEXIT_FIXED #ifndef ATEXIT_FIXED
if (!destroyedOnce_) if (!destroyedOnce_)
@ -277,7 +285,7 @@ namespace Loki
struct Adapter struct Adapter
{ {
void operator()(T*) { return pFun_(); } void operator()(T*) { return pFun_(); }
void (*pFun_)(); atexit_pfn_t pFun_;
}; };
} }
@ -293,7 +301,7 @@ namespace Loki
class SingletonWithLongevity class SingletonWithLongevity
{ {
public: public:
static void ScheduleDestruction(T* pObj, void (*pFun)()) static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun)
{ {
Private::Adapter<T> adapter = { pFun }; Private::Adapter<T> adapter = { pFun };
SetLongevity(pObj, GetLongevity(pObj), adapter); SetLongevity(pObj, GetLongevity(pObj), adapter);
@ -312,7 +320,7 @@ namespace Loki
template <class T> template <class T>
struct NoDestroy struct NoDestroy
{ {
static void ScheduleDestruction(T*, void (*)()) static void ScheduleDestruction(T*, atexit_pfn_t)
{} {}
static void OnDeadReference() static void OnDeadReference()
@ -399,7 +407,7 @@ namespace Loki
} }
} }
static void DestroySingleton() static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton()
{ {
assert(!destroyed_()); assert(!destroyed_());
CreationPolicy<T>::Destroy(pInstance_()); CreationPolicy<T>::Destroy(pInstance_());

View file

@ -27,7 +27,7 @@ unsigned int Loki::Private::elements = 0;
// Ensures proper destruction of objects with longevity // Ensures proper destruction of objects with longevity
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Loki::Private::AtExitFn() void C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
{ {
assert(elements > 0 && pTrackerArray != 0); assert(elements > 0 && pTrackerArray != 0);
// Pick the element at the top of the stack // Pick the element at the top of the stack

View file

@ -23,8 +23,16 @@
#include <cstdlib> #include <cstdlib>
#include <new> #include <new>
#ifdef _MSC_VER
#define C_CALLING_CONVENTION_QUALIFIER __cdecl
#else
#define C_CALLING_CONVENTION_QUALIFIER
#endif
namespace Loki namespace Loki
{ {
typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)();
namespace Private namespace Private
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -85,8 +93,7 @@ namespace Loki
Destroyer destroyer_; Destroyer destroyer_;
}; };
void AtExitFn(); // declaration needed below void C_CALLING_CONVENTION_QUALIFIER AtExitFn(); // declaration needed below
} // namespace Private } // namespace Private
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -222,7 +229,7 @@ namespace Loki
template <class T> template <class T>
struct DefaultLifetime struct DefaultLifetime
{ {
static void ScheduleDestruction(T*, void (*pFun)()) static void ScheduleDestruction(T*, atexit_pfn_t pFun)
{ std::atexit(pFun); } { std::atexit(pFun); }
static void OnDeadReference() static void OnDeadReference()
@ -240,7 +247,7 @@ namespace Loki
class PhoenixSingleton class PhoenixSingleton
{ {
public: public:
static void ScheduleDestruction(T*, void (*pFun)()) static void ScheduleDestruction(T*, atexit_pfn_t pFun)
{ {
#ifndef ATEXIT_FIXED #ifndef ATEXIT_FIXED
if (!destroyedOnce_) if (!destroyedOnce_)
@ -276,7 +283,7 @@ namespace Loki
struct Adapter struct Adapter
{ {
void operator()(T*) { return pFun_(); } void operator()(T*) { return pFun_(); }
void (*pFun_)(); atexit_pfn_t pFun_;
}; };
} }
@ -292,7 +299,7 @@ namespace Loki
class SingletonWithLongevity class SingletonWithLongevity
{ {
public: public:
static void ScheduleDestruction(T* pObj, void (*pFun)()) static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun)
{ {
Private::Adapter<T> adapter = { pFun }; Private::Adapter<T> adapter = { pFun };
SetLongevity(pObj, GetLongevity(pObj), adapter); SetLongevity(pObj, GetLongevity(pObj), adapter);
@ -311,7 +318,7 @@ namespace Loki
template <class T> template <class T>
struct NoDestroy struct NoDestroy
{ {
static void ScheduleDestruction(T*, void (*)()) static void ScheduleDestruction(T*, atexit_pfn_t pFun)
{} {}
static void OnDeadReference() static void OnDeadReference()
@ -340,7 +347,7 @@ namespace Loki
private: private:
// Helpers // Helpers
static void MakeInstance(); static void MakeInstance();
static void DestroySingleton(); static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton();
// Protection // Protection
SingletonHolder(); SingletonHolder();
@ -432,7 +439,8 @@ namespace Loki
template <class> class L, template <class> class L,
template <class> class M template <class> class M
> >
void SingletonHolder<T, CreationPolicy, L, M>::DestroySingleton() void C_CALLING_CONVENTION_QUALIFIER
SingletonHolder<T, CreationPolicy, L, M>::DestroySingleton()
{ {
assert(!destroyed_); assert(!destroyed_);
CreationPolicy<T>::Destroy(pInstance_); CreationPolicy<T>::Destroy(pInstance_);