From 6d155e5f4a036a614515a27280f3ff0974740f9e Mon Sep 17 00:00:00 2001 From: leopz Date: Thu, 11 Jun 2020 19:59:55 +0800 Subject: [PATCH] fix codedex --- mindspore/ccsrc/debug/anf_ir_utils.cc | 10 +++++++--- mindspore/ccsrc/ir/primitive_base.h | 2 +- mindspore/ccsrc/pipeline/pipeline.cc | 2 +- mindspore/ccsrc/utils/log_adapter.cc | 2 +- mindspore/ccsrc/utils/utils.h | 12 ++++++------ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/mindspore/ccsrc/debug/anf_ir_utils.cc b/mindspore/ccsrc/debug/anf_ir_utils.cc index 36fdd5a300..11504b7cdf 100644 --- a/mindspore/ccsrc/debug/anf_ir_utils.cc +++ b/mindspore/ccsrc/debug/anf_ir_utils.cc @@ -1982,7 +1982,11 @@ class IrParser { MS_LOG(EXCEPTION) << "Cast to type 'PrimitivePyPtr' error"; } } else { - ptr = std::make_shared(id.substr(strlen("PrimitivePy::")), py_obj); + auto len = strlen("PrimitivePy::"); + if (id.size() < len) { + return TOK_ERROR; + } + ptr = std::make_shared(id.substr(len), py_obj); } *val_ptr = ptr; @@ -1999,7 +2003,7 @@ class IrParser { return next; } - Token ParseValueGraphAndNamespace(const std::string &id, ValuePtr *val_ptr) { + Token ParseValueGraphAndNamespace(const std::string &id, ValuePtr *const val_ptr) { if (Match(id, "MultitypeFuncGraph::")) { std::string name = id.substr(strlen("MultitypeFuncGraph::")); auto mt_func_graph = std::make_shared(name); @@ -2039,7 +2043,7 @@ class IrParser { } } - Token ParseValueBasic(const FuncGraphPtr &func_graph, const std::string &id, ValuePtr *val_ptr, + Token ParseValueBasic(const FuncGraphPtr &func_graph, const std::string &id, ValuePtr *const val_ptr, AnfNodePtr *const node_ptr = nullptr) { if (id == "None") { *val_ptr = std::make_shared(); diff --git a/mindspore/ccsrc/ir/primitive_base.h b/mindspore/ccsrc/ir/primitive_base.h index 8bf8db3d1f..ffaa12c4d5 100644 --- a/mindspore/ccsrc/ir/primitive_base.h +++ b/mindspore/ccsrc/ir/primitive_base.h @@ -90,7 +90,7 @@ class Primitive : public Named { } const std::unordered_map &attrs() const { return attrs_; } - std::unordered_map &evaluate_added_attrs() { return evaluate_added_attrs_; } + const std::unordered_map &evaluate_added_attrs() const { return evaluate_added_attrs_; } // if Primitive has any attribute, for Primitives like scalar_add, return, etc, don't have any attribute. bool HasAttr() const { return !attrs_.empty(); } diff --git a/mindspore/ccsrc/pipeline/pipeline.cc b/mindspore/ccsrc/pipeline/pipeline.cc index 7df5c6fea0..44b98aa2af 100644 --- a/mindspore/ccsrc/pipeline/pipeline.cc +++ b/mindspore/ccsrc/pipeline/pipeline.cc @@ -646,7 +646,7 @@ void ProcessVmArgInner(const py::tuple &args, const ResourcePtr &res, VectorRef } } -void ExecutorPy::ProcessVmArg(const py::tuple &args, const std::string &phase, VectorRef *arg_list) { +void ExecutorPy::ProcessVmArg(const py::tuple &args, const std::string &phase, VectorRef *const arg_list) { ProcessVmArgInner(args, GetResource(phase), arg_list); } diff --git a/mindspore/ccsrc/utils/log_adapter.cc b/mindspore/ccsrc/utils/log_adapter.cc index 10f49c7036..d16fbead9b 100644 --- a/mindspore/ccsrc/utils/log_adapter.cc +++ b/mindspore/ccsrc/utils/log_adapter.cc @@ -289,7 +289,7 @@ class LogConfigLexer { return '\0'; } - LogConfigToken GetNext(std::string *ptr) { + LogConfigToken GetNext(std::string *const ptr) { #ifdef DEBUG std::string text; auto tok = GetNextInner(&text); diff --git a/mindspore/ccsrc/utils/utils.h b/mindspore/ccsrc/utils/utils.h index b2771f4b9b..92e16ff945 100644 --- a/mindspore/ccsrc/utils/utils.h +++ b/mindspore/ccsrc/utils/utils.h @@ -261,12 +261,12 @@ const std::set kNeedTransFormatSet = {kOpFormat_FRAC_Z, kOpFo kOpFormat_FRACTAL_Z_C04}; static inline void ChangeFileMode(const std::string &file_name, mode_t mode) { - if (access(file_name.c_str(), F_OK) != 0) { - MS_LOG(DEBUG) << "File `" << file_name << "` does not exist."; - return; - } - if (chmod(file_name.c_str(), mode) != 0) { - MS_LOG(WARNING) << "Change file `" << file_name << "` to mode " << std::oct << mode << " fail."; + try { + if (chmod(file_name.c_str(), mode) != 0) { + MS_LOG(WARNING) << "Change file `" << file_name << "` to mode " << std::oct << mode << " fail."; + } + } catch (std::exception &e) { + MS_LOG(DEBUG) << "File `" << file_name << "` change mode failed! May be not exist."; } } } // namespace mindspore