From: 오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 7 Aug 2018 10:43:45 +0000 (+0900) Subject: [neurun] Use std::nothrow for exception handling (#2184) X-Git-Tag: 0.2~338 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3b9a01f2b365e60de5e25a540084f5313072788;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Use std::nothrow for exception handling (#2184) Use std::nothrow for - Handle exception - Set returned reference by parameter nullptr Signed-off-by: Hyeongseok Oh --- diff --git a/runtimes/neurun/src/frontend/compilation.cc b/runtimes/neurun/src/frontend/compilation.cc index f8b9a57..c0639a3 100644 --- a/runtimes/neurun/src/frontend/compilation.cc +++ b/runtimes/neurun/src/frontend/compilation.cc @@ -1,5 +1,7 @@ #include +#include + #include "model.h" #include "compilation.h" @@ -18,12 +20,11 @@ int ANeuralNetworksCompilation_create(ANeuralNetworksModel *model, model->release(internal); - ANeuralNetworksCompilation *compilation_ptr = new ANeuralNetworksCompilation(internal); - if (compilation_ptr == nullptr) + *compilation = new (std::nothrow) ANeuralNetworksCompilation(internal); + if (*compilation == nullptr) { return ANEURALNETWORKS_OUT_OF_MEMORY; } - *compilation = compilation_ptr; return ANEURALNETWORKS_NO_ERROR; } diff --git a/runtimes/neurun/src/frontend/execution.cc b/runtimes/neurun/src/frontend/execution.cc index 04a7210..0a331c1 100644 --- a/runtimes/neurun/src/frontend/execution.cc +++ b/runtimes/neurun/src/frontend/execution.cc @@ -1,5 +1,7 @@ #include +#include + #include "compilation.h" #include "execution.h" #include "event.h" @@ -21,12 +23,11 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation, compilation->publish(plan); - ANeuralNetworksExecution *execution_ptr = new ANeuralNetworksExecution{plan}; - if (execution_ptr == nullptr) + *execution = new (std::nothrow) ANeuralNetworksExecution{plan}; + if (*execution == nullptr) { return ANEURALNETWORKS_OUT_OF_MEMORY; } - *execution = execution_ptr; return ANEURALNETWORKS_NO_ERROR; } @@ -127,12 +128,11 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, } // TODO: Handle event - ANeuralNetworksEvent *event_ptr = new ANeuralNetworksEvent{}; - if (event_ptr == nullptr) + *event = new (std::nothrow) ANeuralNetworksEvent{}; + if (*event == nullptr) { return ANEURALNETWORKS_OUT_OF_MEMORY; } - *event = event_ptr; const auto &plan = execution->plan(); const auto &model = plan.model(); diff --git a/runtimes/neurun/src/frontend/memory.cc b/runtimes/neurun/src/frontend/memory.cc index cf2177d..d2f850f 100644 --- a/runtimes/neurun/src/frontend/memory.cc +++ b/runtimes/neurun/src/frontend/memory.cc @@ -1,5 +1,6 @@ #include #include +#include #include "memory.h" @@ -11,12 +12,11 @@ int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t return ANEURALNETWORKS_UNEXPECTED_NULL; } - ANeuralNetworksMemory *memory_ptr = new ANeuralNetworksMemory{size, protect, fd, offset}; - if (memory_ptr == nullptr) + *memory = new (std::nothrow) ANeuralNetworksMemory{size, protect, fd, offset}; + if (*memory == nullptr) { return ANEURALNETWORKS_OUT_OF_MEMORY; } - *memory = memory_ptr; return ANEURALNETWORKS_NO_ERROR; } diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index fc6c852..9f0ac0d 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -3,6 +3,7 @@ #include #include +#include #include "model.h" #include "memory.h" @@ -14,15 +15,12 @@ int ANeuralNetworksModel_create(ANeuralNetworksModel **model) return ANEURALNETWORKS_UNEXPECTED_NULL; } - ANeuralNetworksModel *model_ptr = new ANeuralNetworksModel{}; - - if (model_ptr == nullptr) + *model = new (std::nothrow) ANeuralNetworksModel{}; + if (*model == nullptr) { return ANEURALNETWORKS_OUT_OF_MEMORY; } - *model = model_ptr; - return ANEURALNETWORKS_NO_ERROR; }