sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\cppexceptions\d_unmap.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_unmap.h" sl@0: sl@0: class TAlwaysTrue sl@0: { sl@0: public: sl@0: TBool val; sl@0: TAlwaysTrue() { val = ETrue; } sl@0: ~TAlwaysTrue() { val = EFalse; } sl@0: }; sl@0: sl@0: #ifndef NO_STATIC_DATA sl@0: static TAlwaysTrue alwaysTrue; sl@0: #endif sl@0: sl@0: // Test C++ stack unwinding sl@0: class TNeedsCxxCleanup sl@0: { sl@0: public: sl@0: TNeedsCxxCleanup() : iPtr(NULL) {} sl@0: ~TNeedsCxxCleanup() { delete iPtr; } sl@0: private: sl@0: TInt* iPtr; sl@0: }; sl@0: sl@0: void AnotherStackLevelL() sl@0: { sl@0: TNeedsCxxCleanup foo; sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: EXPORT_C void Ordinal1L() sl@0: { sl@0: TNeedsCxxCleanup bar; sl@0: AnotherStackLevelL(); sl@0: } sl@0: sl@0: // Test DLL unloading sl@0: NONSHARABLE_CLASS( CDllUnloader ) : public CTimer sl@0: { sl@0: public: sl@0: static CDllUnloader* NewL(); sl@0: sl@0: private: sl@0: CDllUnloader(); sl@0: void ConstructL(); sl@0: sl@0: private: sl@0: void RunL(); sl@0: sl@0: private: sl@0: RLibrary iLibrary; sl@0: }; sl@0: sl@0: sl@0: CDllUnloader::CDllUnloader() sl@0: : CTimer(EPriorityNormal) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CDllUnloader::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: User::LeaveIfError(iLibrary.Load(KLeavingDll)); sl@0: } sl@0: sl@0: CDllUnloader* CDllUnloader::NewL() sl@0: { sl@0: CDllUnloader* self = new(ELeave) CDllUnloader(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: void CDllUnloader::RunL() sl@0: { sl@0: // Temporary copy of handle sl@0: RLibrary library(iLibrary); sl@0: sl@0: // Prevent the AS calling back into us later sl@0: // - everything is poison now sl@0: delete this; sl@0: sl@0: // Push the library handle onto the cleanupstack for euser to clean up sl@0: CleanupClosePushL(library); sl@0: sl@0: // Prevent [Run]Error() from being called... sl@0: // - effect thread diversion out of the DLL sl@0: // - and breath a sigh of relief that you've been so cunning sl@0: User::Leave(KErrNone); sl@0: } sl@0: sl@0: EXPORT_C TBool Ordinal2() sl@0: { sl@0: /* sl@0: CDllUnloader* unloader = CDllUnloader::NewL(); sl@0: unloader->After(1000000); sl@0: */ sl@0: #ifdef NO_STATIC_DATA sl@0: return EFalse; sl@0: #else sl@0: return alwaysTrue.val; sl@0: #endif sl@0: } sl@0: