summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp84
1 files changed, 53 insertions, 31 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 76ffb6a..818e555 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1910,6 +1910,15 @@ QSysInfo::SymVersion QSysInfo::symbianVersion()
*/
/*!
+ T *q_check_ptr(T *pointer)
+ \relates <QtGlobal>
+
+ Users Q_CHECK_PTR on \a pointer, then returns \a pointer.
+
+ This can be used as an inline version of Q_CHECK_PTR.
+*/
+
+/*!
\macro const char* Q_FUNC_INFO()
\relates <QtGlobal>
@@ -2162,7 +2171,7 @@ void qt_message_output(QtMsgType msgType, const char *buf)
_LIT(format, "[Qt Message] %S");
const int maxBlockSize = 256 - ((const TDesC &)format).Length();
const TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf));
- HBufC* hbuffer = HBufC::NewL(qMin(maxBlockSize, ptr.Length()));
+ HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length())));
for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) {
hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i)));
RDebug::Print(format, hbuffer);
@@ -2464,7 +2473,11 @@ bool qputenv(const char *varName, const QByteArray& value)
QByteArray buffer(varName);
buffer += '=';
buffer += value;
- return putenv(qstrdup(buffer.constData())) == 0;
+ char* envVar = qstrdup(buffer.constData());
+ int result = putenv(envVar);
+ if (result != 0) // error. we have to delete the string.
+ delete[] envVar;
+ return result == 0;
#endif
}
@@ -3231,7 +3244,7 @@ bool QInternal::callFunction(InternalFunction func, void **args)
#include <typeinfo>
-/*! \macro QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(function)
+/*! \macro QT_TRAP_THROWING(function)
\relates <QtGlobal>
\ingroup qts60
@@ -3251,14 +3264,14 @@ bool QInternal::callFunction(InternalFunction func, void **args)
CAknTitlePane* titlePane = S60->titlePane();
if (titlePane) {
TPtrC captionPtr(qt_QString2TPtrC(caption));
- QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(titlePane->SetTextL(captionPtr));
+ QT_TRAP_THROWING(titlePane->SetTextL(captionPtr));
}
\endcode
- \sa QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(), QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE()
+ \sa QT_TRYCATCH_ERROR(), QT_TRYCATCH_LEAVING()
*/
-/*! \macro QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(error, function)
+/*! \macro QT_TRYCATCH_ERROR(error, function)
\relates <QtGlobal>
\ingroup qts60
@@ -3278,7 +3291,7 @@ bool QInternal::callFunction(InternalFunction func, void **args)
{
TPtrC name;
TInt err;
- QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, name.Set(qt_QString2TPtrC(serverName)));
+ QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName)));
if (err != KErrNone)
return err;
return iServer.Connect(name);
@@ -3286,10 +3299,10 @@ bool QInternal::callFunction(InternalFunction func, void **args)
\endcode
}
- \sa QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(), QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION()
+ \sa QT_TRYCATCH_LEAVING(), QT_TRAP_THROWING()
*/
-/*! \macro QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(function)
+/*! \macro QT_TRYCATCH_LEAVING(function)
\relates <QtGlobal>
\ingroup qts60
@@ -3309,11 +3322,11 @@ bool QInternal::callFunction(InternalFunction func, void **args)
{
iStatus = KRequestPending;
SetActive();
- QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->wakeUpWasCalled());
+ QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled());
}
\endcode
- \sa QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(), QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR()
+ \sa QT_TRAP_THROWING(), QT_TRYCATCH_ERROR()
*/
#include <stdexcept>
@@ -3336,15 +3349,21 @@ public:
\warning This function is only available on Symbian.
- \sa qt_translateExceptionToSymbianErrorL(), qt_translateExceptionToSymbianError()
+ \sa qt_exception2SymbianLeaveL(), qt_exception2SymbianError()
*/
-void qt_translateSymbianErrorToException(int error)
+void qt_throwIfError(int error)
{
if (error >= KErrNone)
return; // do nothing - not an exception
switch (error) {
case KErrNoMemory:
throw std::bad_alloc();
+ case KErrArgument:
+ throw std::invalid_argument("from Symbian error");
+ case KErrOverflow:
+ throw std::overflow_error("from Symbian error");
+ case KErrUnderflow:
+ throw std::underflow_error("from Symbian error");
default:
throw QSymbianLeaveException(error);
}
@@ -3357,11 +3376,11 @@ void qt_translateSymbianErrorToException(int error)
\warning This function is only available on Symbian.
- \sa qt_translateSymbianErrorToException(), qt_translateExceptionToSymbianError()
+ \sa qt_throwIfError(), qt_exception2SymbianError()
*/
-void qt_translateExceptionToSymbianErrorL(const std::exception& aThrow)
+void qt_exception2SymbianLeaveL(const std::exception& aThrow)
{
- User::Leave(qt_translateExceptionToSymbianError(aThrow));
+ User::Leave(qt_exception2SymbianError(aThrow));
}
/*! \relates <QtGlobal>
@@ -3371,9 +3390,9 @@ void qt_translateExceptionToSymbianErrorL(const std::exception& aThrow)
\warning This function is only available on Symbian.
- \sa qt_translateSymbianErrorToException(), qt_translateExceptionToSymbianErrorL()
+ \sa qt_throwIfError(), qt_exception2SymbianLeaveL()
*/
-int qt_translateExceptionToSymbianError(const std::exception& aThrow)
+int qt_exception2SymbianError(const std::exception& aThrow)
{
const std::type_info& atype = typeid(aThrow);
int err = KErrGeneral;
@@ -3382,19 +3401,22 @@ int qt_translateExceptionToSymbianError(const std::exception& aThrow)
err = KErrNoMemory;
else if(atype == typeid(QSymbianLeaveException))
err = static_cast<const QSymbianLeaveException&>(aThrow).error;
- else if(atype == typeid(std::invalid_argument))
- err = KErrArgument;
- else if(atype == 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(atype == typeid(std::overflow_error))
- err = KErrOverflow;
- else if(atype == typeid(std::underflow_error))
- err = KErrUnderflow;
-
+ else {
+ if(atype == typeid(std::invalid_argument))
+ err = KErrArgument;
+ else if(atype == 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(atype == typeid(std::overflow_error))
+ err = KErrOverflow;
+ else if(atype == typeid(std::underflow_error))
+ err = KErrUnderflow;
+ qWarning("translation from std exception \"%s\" to %d", aThrow.what(), err);
+ }
+
return err;
}
#endif