diff --git a/MSVC/1300/Singleton.cpp b/MSVC/1300/Singleton.cpp index 57899d2..7e9f1b0 100644 --- a/MSVC/1300/Singleton.cpp +++ b/MSVC/1300/Singleton.cpp @@ -27,7 +27,7 @@ unsigned int Loki::Private::elements = 0; // Ensures proper destruction of objects with longevity //////////////////////////////////////////////////////////////////////////////// -void Loki::Private::AtExitFn() +void C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn() { assert(elements > 0 && pTrackerArray != 0); // Pick the element at the top of the stack diff --git a/MSVC/1300/Singleton.h b/MSVC/1300/Singleton.h index c9c1118..7017184 100644 --- a/MSVC/1300/Singleton.h +++ b/MSVC/1300/Singleton.h @@ -25,8 +25,16 @@ #include #include +#ifdef _MSC_VER +#define C_CALLING_CONVENTION_QUALIFIER __cdecl +#else +#define C_CALLING_CONVENTION_QUALIFIER +#endif + namespace Loki { + typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)(); + namespace Private { //////////////////////////////////////////////////////////////////////////////// @@ -87,7 +95,7 @@ namespace Loki Destroyer destroyer_; }; - void AtExitFn(); // declaration needed below + void C_CALLING_CONVENTION_QUALIFIER AtExitFn(); // declaration needed below } // namespace Private @@ -223,7 +231,7 @@ namespace Loki template struct DefaultLifetime { - static void ScheduleDestruction(T*, void (*pFun)()) + static void ScheduleDestruction(T*, atexit_pfn_t pFun) { std::atexit(pFun); } static void OnDeadReference() @@ -241,7 +249,7 @@ namespace Loki class PhoenixSingleton { public: - static void ScheduleDestruction(T*, void (*pFun)()) + static void ScheduleDestruction(T*, atexit_pfn_t pFun) { #ifndef ATEXIT_FIXED if (!destroyedOnce_) @@ -277,7 +285,7 @@ namespace Loki struct Adapter { void operator()(T*) { return pFun_(); } - void (*pFun_)(); + atexit_pfn_t pFun_; }; } @@ -293,7 +301,7 @@ namespace Loki class SingletonWithLongevity { public: - static void ScheduleDestruction(T* pObj, void (*pFun)()) + static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun) { Private::Adapter adapter = { pFun }; SetLongevity(pObj, GetLongevity(pObj), adapter); @@ -312,7 +320,7 @@ namespace Loki template struct NoDestroy { - static void ScheduleDestruction(T*, void (*)()) + static void ScheduleDestruction(T*, atexit_pfn_t) {} static void OnDeadReference() @@ -399,7 +407,7 @@ namespace Loki } } - static void DestroySingleton() + static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton() { assert(!destroyed_()); CreationPolicy::Destroy(pInstance_()); diff --git a/Reference/Singleton.cpp b/Reference/Singleton.cpp index 8cb69c2..79346e4 100644 --- a/Reference/Singleton.cpp +++ b/Reference/Singleton.cpp @@ -27,7 +27,7 @@ unsigned int Loki::Private::elements = 0; // Ensures proper destruction of objects with longevity //////////////////////////////////////////////////////////////////////////////// -void Loki::Private::AtExitFn() +void C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn() { assert(elements > 0 && pTrackerArray != 0); // Pick the element at the top of the stack diff --git a/Reference/Singleton.h b/Reference/Singleton.h index cb57a06..9e62151 100644 --- a/Reference/Singleton.h +++ b/Reference/Singleton.h @@ -23,8 +23,16 @@ #include #include +#ifdef _MSC_VER +#define C_CALLING_CONVENTION_QUALIFIER __cdecl +#else +#define C_CALLING_CONVENTION_QUALIFIER +#endif + namespace Loki { + typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)(); + namespace Private { //////////////////////////////////////////////////////////////////////////////// @@ -85,8 +93,7 @@ namespace Loki Destroyer destroyer_; }; - void AtExitFn(); // declaration needed below - + void C_CALLING_CONVENTION_QUALIFIER AtExitFn(); // declaration needed below } // namespace Private //////////////////////////////////////////////////////////////////////////////// @@ -222,7 +229,7 @@ namespace Loki template struct DefaultLifetime { - static void ScheduleDestruction(T*, void (*pFun)()) + static void ScheduleDestruction(T*, atexit_pfn_t pFun) { std::atexit(pFun); } static void OnDeadReference() @@ -240,7 +247,7 @@ namespace Loki class PhoenixSingleton { public: - static void ScheduleDestruction(T*, void (*pFun)()) + static void ScheduleDestruction(T*, atexit_pfn_t pFun) { #ifndef ATEXIT_FIXED if (!destroyedOnce_) @@ -276,7 +283,7 @@ namespace Loki struct Adapter { void operator()(T*) { return pFun_(); } - void (*pFun_)(); + atexit_pfn_t pFun_; }; } @@ -292,7 +299,7 @@ namespace Loki class SingletonWithLongevity { public: - static void ScheduleDestruction(T* pObj, void (*pFun)()) + static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun) { Private::Adapter adapter = { pFun }; SetLongevity(pObj, GetLongevity(pObj), adapter); @@ -311,7 +318,7 @@ namespace Loki template struct NoDestroy { - static void ScheduleDestruction(T*, void (*)()) + static void ScheduleDestruction(T*, atexit_pfn_t pFun) {} static void OnDeadReference() @@ -340,7 +347,7 @@ namespace Loki private: // Helpers static void MakeInstance(); - static void DestroySingleton(); + static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton(); // Protection SingletonHolder(); @@ -432,7 +439,8 @@ namespace Loki template class L, template class M > - void SingletonHolder::DestroySingleton() + void C_CALLING_CONVENTION_QUALIFIER + SingletonHolder::DestroySingleton() { assert(!destroyed_); CreationPolicy::Destroy(pInstance_);