home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.4 KB | 155 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWAutoDe.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWAUTODE_H
- #include "FWAutoDe.h"
- #endif
-
- #if defined(FW_USE_NEW_HELPER) && !defined(FWNEWHEL_H)
- #include "FWNewHel.h"
- #endif
-
- #ifndef FWEXCTAS_H
- #include "FWExcTas.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWExcLib
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(FW_qUsePlatformAlloc)
- #define FW_qUsePlatformAlloc
- #endif
-
- //========================================================================================
- // CLASS _FW_CAutoDestructObject
- //========================================================================================
-
- #if defined(__BORLANDC__) && !defined(FW_NATIVE_EXCEPTIONS)
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::__Delete
- //----------------------------------------------------------------------------------------
- void _FW_CAutoDestructObject::__Delete()
- {
- // Borland C++ 3.1 is bizzare, too. It will call operator delete in any case, but
- // not intentionally, but simply because it forgets to push the argument for
- // the destructor on the stack
- __asm {
- push 0 // this is the argument that the compiler forgets
- push word ptr[this + 2] // push the address
- push word ptr[this]
- les bx, [this] // get the object pointer
- les bx, dword ptr es:[bx] // get the vtable pointer
- call dword ptr es:[bx] // and call the dtor
- add sp, 6 // clean up the stack
- };
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::~_FW_CAutoDestructObject
- //----------------------------------------------------------------------------------------
- _FW_CAutoDestructObject::~_FW_CAutoDestructObject()
- {
- }
-
- #ifdef FW_USE_NEW_HELPER
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::operator new
- //----------------------------------------------------------------------------------------
- void* _FW_CAutoDestructObject::operator new(size_t size, const FW_CPrivNewHelper &helper)
- {
- #ifdef FW_qUsePlatformAlloc
- void *p = ::operator new(size);
- #else
- FW_PRIV_ASSERT(helper.fNewHandler != NULL);
- FW_PRIV_ASSERT(helper.fDeleteHandler != NULL);
-
- if (GetOperatorNewHandler() == NULL)
- {
- SetOperatorNewHandler(helper.fNewHandler);
- SetOperatorDeleteHandler(helper.fDeleteHandler);
- }
- FW_PRIV_ASSERT(helper.fNewHandler == GetOperatorNewHandler());
- FW_PRIV_ASSERT(helper.fDeleteHandler == GetOperatorDeleteHandler());
- __FW_OperatorNewHandler operatorNewHandler = helper.fNewHandler;
- void *p = operatorNewHandler(size);
- #endif
-
- helper.WatchObject((_FW_CAutoDestructObject*)p, size);
-
- return p;
- }
- #endif
-
- #ifdef FW_USE_NEW_HELPER
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::operator delete
- //----------------------------------------------------------------------------------------
- void _FW_CAutoDestructObject::operator delete(void *object)
- {
- #ifdef FW_qUsePlatformAlloc
- ::operator delete(object);
- #else
- __FW_OperatorDeleteHandler operatorDeleteHandler = GetOperatorDeleteHandler();
- FW_PRIV_ASSERT(operatorDeleteHandler != NULL);
- operatorDeleteHandler(object);
- #endif
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::SetOperatorNewHandler
- //----------------------------------------------------------------------------------------
- void _FW_CAutoDestructObject::SetOperatorNewHandler(__FW_OperatorNewHandler operatorNewHandler)
- {
- FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
- FW_PRIV_ASSERT(globals.gOperatorNewHandler == NULL);
- globals.gOperatorNewHandler = operatorNewHandler;
- }
-
-
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::SetOperatorDeleteHandler
- //----------------------------------------------------------------------------------------
-
- void _FW_CAutoDestructObject::SetOperatorDeleteHandler(__FW_OperatorDeleteHandler operatorDeleteHandler)
- {
- FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
- FW_PRIV_ASSERT(globals.gOperatorDeleteHandler == NULL);
- globals.gOperatorDeleteHandler = operatorDeleteHandler;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::GetOperatorNewHandler
- //----------------------------------------------------------------------------------------
- __FW_OperatorNewHandler _FW_CAutoDestructObject::GetOperatorNewHandler()
- {
- return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorNewHandler;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CAutoDestructObject::GetOperatorDeleteHandler
- //----------------------------------------------------------------------------------------
-
- __FW_OperatorDeleteHandler _FW_CAutoDestructObject::GetOperatorDeleteHandler()
- {
- return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorDeleteHandler;
- }
-