From 388d539328df4ce6b76e135937d809d84a238c73 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Thu, 24 May 2018 15:11:54 +0800 Subject: [PATCH] enforce open file failed --- src/io.cpp | 17 ++++++++++++----- src/io.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index f0c625b915..0c06f76ca3 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -12,20 +12,24 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#include "io.h" +#include #include #include "common/log.h" -#include "framework/framework.pb.h" -#include "framework/lod_tensor.h" -#include "framework/program/program_desc.h" +#include "common/enforce.h" #include "framework/scope.h" #include "framework/tensor.h" -#include "io.h" +#include "framework/lod_tensor.h" +#include "framework/framework.pb.h" +#include "framework/program/program_desc.h" namespace paddle_mobile { void ReadBinaryFile(const std::string &filename, std::string *contents) { std::ifstream fin(filename, std::ios::in | std::ios::binary); + PADDLE_MOBILE_ENFORCE(fin.is_open(), + "open file: %s failed", filename.c_str()); fin.seekg(0, std::ios::end); contents->clear(); contents->resize(fin.tellg()); @@ -38,7 +42,8 @@ template void Loader::LoadVar(framework::LoDTensor *tensor, const std::string &file_path) { std::ifstream is(file_path); - + PADDLE_MOBILE_ENFORCE(is.is_open(), + "open file: %s failed", file_path.c_str()); std::fpos pos; pos = is.tellg(); // save current position is.seekg(0, std::ios::end); @@ -238,6 +243,8 @@ const framework::Program Loader::Load( var.type().type() != framework::proto::VarType::FETCH_LIST) { std::string file_path = dirname + "/" + var.name(); std::ifstream is(file_path); + PADDLE_MOBILE_ENFORCE(is.is_open(), + "open file: %s failed", file_path.c_str()); std::fpos pos; pos = is.tellg(); // save current position is.seekg(0, std::ios::end); diff --git a/src/io.h b/src/io.h index 7a8d5863eb..bbc0c0c6eb 100644 --- a/src/io.h +++ b/src/io.h @@ -18,8 +18,8 @@ limitations under the License. */ #include "common/types.h" #include "framework/lod_tensor.h" -#include "framework/paddle_mobile_object.h" #include "framework/program/program.h" +#include "framework/paddle_mobile_object.h" namespace paddle_mobile { -- GitLab