Add macros for OOM errors and remove redundant nothrows 20/123220/3
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 5 Apr 2017 04:12:19 +0000 (13:12 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 5 Apr 2017 04:43:31 +0000 (13:43 +0900)
Change-Id: Id2348ea92e30bca8dc618c8fbc76d8a7328d17c1
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/ContextTypes.h
src/client/ServiceProxy.cpp
src/database/Database.cpp
src/server/ClientBase.cpp
src/server/ServiceBase.cpp
src/server/Timer.cpp
src/shared/SharedUtil.cpp
src/shared/Tuple.cpp

index 7a861f6..b9ddd57 100644 (file)
@@ -59,6 +59,9 @@
 #define _SW SECURE_SLOGW
 #define _SE SECURE_SLOGE
 
+#define E_STR_ALLOC    RED("Memory allocation failed")
+#define _E_ALLOC _E(E_STR_ALLOC)
+
 /* Color code for dlog */
 #define RED(X)         "\033[0;31m" X "\033[0m"
 #define GREEN(X)       "\033[0;32m" X "\033[0m"
index b908114..77357e3 100644 (file)
@@ -121,7 +121,7 @@ int ServiceProxy::call(const std::string& methodName, GVariant* inParam, IServic
        ResultCbData* cbData = new(std::nothrow) ResultCbData;
        if (!cbData) {
                g_variant_unref(inParam);
-               _E("Memory allocation failed");
+               _E_ALLOC;
                return E_NO_MEM;
        }
 
index ab0b8d2..0a58e4b 100644 (file)
@@ -134,14 +134,14 @@ static int __executionCb(void *userData, int dim, char** value, char** column)
                        } else {
                                builder.add(__toString(value[i]));
                        }
-               } catch(std::exception& e) {
+               } catch (const std::exception& e) {
                        builder.add(__toString(value[i]));
                }
        }
 
        try {
                cbData->queryResult->push_back(builder.build());
-       } catch (std::exception& e) {
+       } catch (const std::exception& e) {
                _E("Exception: %s", e.what());
                return E_FAILED;
        }
@@ -156,7 +156,7 @@ bool Database::execute(const std::string& query, const std::string& columnTypes,
        _SD("%s", query.c_str());
 
        ExecutionCbData* cbData = new(std::nothrow) ExecutionCbData(&columnTypes, columnNames, queryResult);
-       IF_FAIL_RETURN_TAG(cbData, false, _E, "Memory allocation failed");
+       IF_FAIL_RETURN_TAG(cbData, false, _E, E_STR_ALLOC);
 
        char* err = NULL;
        int ret = sqlite3_exec(__dbHandle, query.c_str(), __executionCb, cbData, &err);
index 240f6ae..f332417 100644 (file)
@@ -43,8 +43,7 @@ bool ClientBase::__getCredential()
        if (__credential)
                return true;
 
-       __credential = new(std::nothrow) Credential(__hostService->getConnection(), __busName);
-       IF_FAIL_RETURN_TAG(__credential, false, _E, "Memory allocation failed");
+       __credential = new Credential(__hostService->getConnection(), __busName);
 
        return true;
 }
index 51455d5..4a24920 100644 (file)
@@ -128,7 +128,7 @@ void ServiceBase::notifyUserNew()
        IF_FAIL_VOID(__threadRunning.load());
 
        GSource* gSrc = g_idle_source_new();
-       IF_FAIL_VOID_TAG(gSrc, _E, "Memory allocation failed");
+       IF_FAIL_VOID_TAG(gSrc, _E, E_STR_ALLOC);
 
        g_source_set_callback(gSrc, __onUserActivated, this, NULL);
        g_source_attach(gSrc, __mainContext);
@@ -141,7 +141,7 @@ void ServiceBase::notifyUserRemoved()
        IF_FAIL_VOID(__threadRunning.load());
 
        GSource* gSrc = g_idle_source_new();
-       IF_FAIL_VOID_TAG(gSrc, _E, "Memory allocation failed");
+       IF_FAIL_VOID_TAG(gSrc, _E, E_STR_ALLOC);
 
        g_source_set_callback(gSrc, __onUserDeactivated, this, NULL);
        g_source_attach(gSrc, __mainContext);
@@ -260,10 +260,7 @@ void ServiceBase::__onMethodCalled(const std::string& sender,
        ClientBase* client = __getClient(sender);
        IF_FAIL_VOID(client);
 
-       MethodCall* methodCall = new(std::nothrow) MethodCall(client, name, param, invocation);
-       IF_FAIL_VOID_TAG(methodCall, _E, "Memory allocation failed");
-
-       client->onMethodCalled(methodCall);
+       client->onMethodCalled(new MethodCall(client, name, param, invocation));
 }
 
 ClientBase* ServiceBase::__getClient(const std::string& busName)
@@ -274,7 +271,7 @@ ClientBase* ServiceBase::__getClient(const std::string& busName)
                return iter->second.client;
 
        ClientBase* client = createClient(busName);
-       IF_FAIL_RETURN_TAG(client, NULL, _E, "Memory allocation failed");
+       IF_FAIL_RETURN_TAG(client, NULL, _E, "Client creation failed");
 
        if (!client->isVerified()) {
                delete client;
index 91eff91..90217e7 100644 (file)
@@ -106,15 +106,10 @@ unsigned int Timer::addIdle(ITimerListener* listener)
 {
        INIT_CONTEXT;
 
-       ListenerInfo* info = new(std::nothrow) ListenerInfo(this, listener);
-       IF_FAIL_RETURN_TAG(info, 0, _E, "Memory allocation failed");
-
        GSource* gSrc = g_idle_source_new();
-       if (!gSrc) {
-               _E("Memory allocation failed");
-               delete info;
-               return 0;
-       }
+       IF_FAIL_RETURN_TAG(gSrc, 0, _E, E_STR_ALLOC);
+
+       ListenerInfo* info = new ListenerInfo(this, listener);
 
        info->timerId = TIMER_ID;
        info->gSrc = gSrc;
@@ -133,15 +128,10 @@ unsigned int Timer::addTimeout(unsigned int intervalMs, ITimerListener* listener
 {
        INIT_CONTEXT;
 
-       ListenerInfo* info = new(std::nothrow) ListenerInfo(this, listener);
-       IF_FAIL_RETURN_TAG(info, 0, _E, "Memory allocation failed");
-
        GSource* gSrc = g_timeout_source_new(intervalMs);
-       if (!gSrc) {
-               _E("Memory allocation failed");
-               delete info;
-               return 0;
-       }
+       IF_FAIL_RETURN_TAG(gSrc, 0, _E, E_STR_ALLOC);
+
+       ListenerInfo* info = new ListenerInfo(this, listener);
 
        info->timerId = TIMER_ID;
        info->intervalMs = intervalMs;
@@ -188,8 +178,7 @@ unsigned int Timer::addAlarm(unsigned int intervalMin, ITimerListener* listener)
 
        int alarmId, result;
 
-       ListenerInfo* info = new(std::nothrow) ListenerInfo(this, listener);
-       IF_FAIL_RETURN_TAG(info, 0, _E, "Memory allocation failed");
+       ListenerInfo* info = new ListenerInfo(this, listener);
 
        info->intervalMs = intervalMin * MILLIS_PER_MIN;
 
@@ -215,7 +204,7 @@ int Timer::__alarmMgrCb(int alarmId, void *userData)
        _D("Id: %u (%d), Interval: %u ms", info->timerId, info->alarmId, info->intervalMs);
 
        GSource* gSrc = g_idle_source_new();
-       IF_FAIL_RETURN_TAG(gSrc, 0, _E, "Memory allocation failed");
+       IF_FAIL_RETURN_TAG(gSrc, 0, _E, E_STR_ALLOC);
 
        g_source_set_callback(gSrc, __onAlarmExpired, userData, NULL);
        g_source_attach(gSrc, info->timer->__context);
index ac8855b..bc0ce33 100644 (file)
@@ -67,7 +67,7 @@ EXPORT_API std::vector<std::string> util::tokenizeString(const std::string& in,
        std::vector<std::string> tokens;
        char* inputStr = g_strdup(in.c_str());
 
-       IF_FAIL_RETURN_TAG(inputStr, tokens, _E, "Memory allocation failed");
+       IF_FAIL_RETURN_TAG(inputStr, tokens, _E, E_STR_ALLOC);
 
        char* savePtr = NULL;
        char* token = strtok_r(inputStr, delim, &savePtr);
index 20cdb8e..94eea95 100644 (file)
@@ -54,7 +54,7 @@ bool Tuple::__parse()
        __elements = new(std::nothrow) GVariant*[__numElements];
        if (!__elements) {
                __numElements = 0;
-               _E("Memory allocation failed");
+               _E_ALLOC;
                return false;
        }
 
@@ -139,7 +139,7 @@ shared_ptr<Tuple> Tuple::duplicate(shared_ptr<Tuple> tuple)
 
    try {
           return std::make_shared<Tuple>(gv);
-   } catch (std::exception& e) {
+   } catch (const std::exception& e) {
           _E("Exception: %s", e.what());
           g_variant_unref(gv);
           throw;
@@ -176,7 +176,7 @@ vector<shared_ptr<Tuple>> Tuple::buildFrom(GVariant* gVar)
        if (g_variant_is_of_type(gVar, G_VARIANT_TYPE_TUPLE)) {
                try {
                        tuples.push_back(std::make_shared<Tuple>(gVar));
-               } catch (std::exception& e) {
+               } catch (const std::exception& e) {
                        _E("Exception: %s", e.what());
                        g_variant_unref(gVar);
                }
@@ -192,7 +192,7 @@ vector<shared_ptr<Tuple>> Tuple::buildFrom(GVariant* gVar)
                        }
                        try {
                                tuples.push_back(std::make_shared<Tuple>(child));
-                       } catch (std::exception& e) {
+                       } catch (const std::exception& e) {
                                _E("Exception: %s", e.what());
                                g_variant_unref(child);
                        }
@@ -221,7 +221,7 @@ bool Tuple::Builder::__init()
 {
        if (!__gvBuilder) {
                __gvBuilder = g_variant_builder_new(G_VARIANT_TYPE_TUPLE);
-               IF_FAIL_RETURN_TAG(__gvBuilder, false, _E, "Memory allocation failed");
+               IF_FAIL_RETURN_TAG(__gvBuilder, false, _E, E_STR_ALLOC);
        }
        return true;
 }
@@ -261,7 +261,7 @@ shared_ptr<Tuple> Tuple::Builder::build()
 
        try {
                return std::make_shared<Tuple>(gVar);
-       } catch (std::exception& e) {
+       } catch (const std::exception& e) {
           _E("Exception: %s", e.what());
                g_variant_unref(gVar);
                throw;