From faff1c60a2a7f6ebef90249e759bdf822c8b17de Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Tue, 30 Mar 2010 18:46:51 +0200 Subject: Make s60main static lib not depend on QtCore Inline all the code that is used from QtCore as we should not assume QtCore is present for a static library linked into random 3rd party applications. --- src/s60main/qts60main.cpp | 6 ++++-- src/s60main/qts60main_mcrt0.cpp | 47 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/s60main/qts60main.cpp b/src/s60main/qts60main.cpp index 5fbeea5..7b85901 100644 --- a/src/s60main/qts60main.cpp +++ b/src/s60main/qts60main.cpp @@ -41,7 +41,7 @@ // INCLUDE FILES #include // must be before e32base.h so uncaught_exception gets defined #include -#include +#include GLDEF_C TInt QtMainWrapper(); @@ -51,7 +51,9 @@ GLDEF_C TInt QtMainWrapper(); */ GLDEF_C TInt E32Main() { - CTrapCleanup *cleanupStack = q_check_ptr(CTrapCleanup::New()); + CTrapCleanup *cleanupStack = CTrapCleanup::New(); + if (!(cleanupStack)) + throw std::bad_alloc(); TInt err = 0; TRAP(err, err = QtMainWrapper()); delete cleanupStack; diff --git a/src/s60main/qts60main_mcrt0.cpp b/src/s60main/qts60main_mcrt0.cpp index 0f0723e..28c3ac6 100644 --- a/src/s60main/qts60main_mcrt0.cpp +++ b/src/s60main/qts60main_mcrt0.cpp @@ -50,9 +50,8 @@ #include // must be before e32base.h so uncaught_exception gets defined #include #include "estlib.h" +#include -// Needed for QT_TRYCATCH_LEAVING. -#include #ifdef __ARMCC__ __asm int CallMain(int argc, char *argv[], char *envp[]) @@ -75,6 +74,18 @@ extern "C" GLDEF_C int __GccGlueInit() extern "C" IMPORT_C void exit(int ret); +namespace { +class QSymbianLeaveException : public std::exception +{ +public: + inline QSymbianLeaveException(int err) : error(err) {} + inline const char* what() const throw() { return "Symbian leave exception"; } + +public: + int error; +}; +} + GLDEF_C TInt QtMainWrapper() { int argc = 0; @@ -83,7 +94,37 @@ GLDEF_C TInt QtMainWrapper() // get args & environment __crt0(argc, argv, envp); //Call user(application)'s main - TRAPD(ret, QT_TRYCATCH_LEAVING(ret = CALLMAIN(argc, argv, envp);)); + + TInt _err = KErrNone; + TRAPD(ret, + try { + ret = CALLMAIN(argc, argv, envp); + } catch (const std::exception &____ex) { + _err = KErrGeneral; + const std::type_info& type = typeid(____ex); + + if (type == typeid (std::bad_alloc)) { + _err = KErrNoMemory; + } else if (type == typeid(::QSymbianLeaveException)) { + _err = static_cast(____ex).error; + } else { + if (type == typeid(std::invalid_argument)) + _err = KErrArgument; + else if (type == typeid(std::out_of_range)) + // std::out_of_range is of type logic_error which by definition means that it is + // "presumably detectable before the program executes". + // std::out_of_range is used to report an argument is not within the expected range. + // The description of KErrArgument says an argument is out of range. Hence the mapping. + _err = KErrArgument; + else if (type == typeid(std::overflow_error)) + _err = KErrOverflow; + else if (type == typeid(std::underflow_error)) + _err = KErrUnderflow; + } + } + User::LeaveIfError(_err); + ); + delete[] argv; delete[] envp; return ret; -- cgit v0.12