From: Joel Rosdahl Date: Sat, 2 May 2020 10:46:39 +0000 (+0200) Subject: C++-ify ArgsInfo::arch_args X-Git-Tag: v4.0~507 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ca8fd6c4f325a37dbfee3e8b9cf48818cc52d43;p=thirdparty%2Fccache.git C++-ify ArgsInfo::arch_args --- diff --git a/src/ArgsInfo.hpp b/src/ArgsInfo.hpp index 19d76c6b0..520030492 100644 --- a/src/ArgsInfo.hpp +++ b/src/ArgsInfo.hpp @@ -94,10 +94,8 @@ struct ArgsInfo // Files referenced by -fsanitize-blacklist options. std::vector sanitize_blacklists; - // Array for storing -arch options. - static constexpr int max_arch_args = 10; - size_t arch_args_size = 0; - char* arch_args[max_arch_args] = {nullptr}; + // Architectures from -arch options. + std::vector arch_args; // Relocating debuginfo in the format old=new. char** debug_prefix_maps = nullptr; diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 934ea7c60..51f1a7bcc 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -305,17 +305,9 @@ process_arg(Context& ctx, // Handle -arch options. if (str_eq(argv[i], "-arch")) { - if (args_info.arch_args_size == ArgsInfo::max_arch_args - 1) { - cc_log("Too many -arch compiler options; ccache supports at most %d", - ArgsInfo::max_arch_args); - return STATS_UNSUPPORTED_OPTION; - } - ++i; - args_info.arch_args[args_info.arch_args_size] = - x_strdup(argv[i]); // It will leak. - ++args_info.arch_args_size; - if (args_info.arch_args_size == 2) { + args_info.arch_args.emplace_back(argv[i]); + if (args_info.arch_args.size() == 2) { config.set_run_second_cpp(true); } return nullopt; @@ -1160,9 +1152,9 @@ process_args(Context& ctx, args_add(*compiler_args, "-dc"); } - for (size_t i = 0; i < args_info.arch_args_size; ++i) { + for (const auto& arch : args_info.arch_args) { args_add(*compiler_args, "-arch"); - args_add(*compiler_args, args_info.arch_args[i]); + args_add(*compiler_args, arch); } *preprocessor_args = args_copy(state.common_args); diff --git a/src/ccache.cpp b/src/ccache.cpp index 4afc16f7c..ba5bdb23d 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1790,9 +1790,9 @@ calculate_result_name(Context& ctx, } // Adding -arch to hash since cpp output is affected. - for (size_t i = 0; i < ctx.args_info.arch_args_size; ++i) { + for (const auto& arch : ctx.args_info.arch_args) { hash_delimiter(hash, "-arch"); - hash_string(hash, ctx.args_info.arch_args[i]); + hash_string(hash, arch); } struct digest* result_name = nullptr; @@ -1852,17 +1852,17 @@ calculate_result_name(Context& ctx, cc_log("Did not find result name in manifest"); } } else { - if (ctx.args_info.arch_args_size == 0) { + if (ctx.args_info.arch_args.empty()) { result_name = get_result_name_from_cpp(ctx, preprocessor_args, hash); cc_log("Got result name from preprocessor"); } else { args_add(preprocessor_args, "-arch"); - for (size_t i = 0; i < ctx.args_info.arch_args_size; ++i) { + for (size_t i = 0; i < ctx.args_info.arch_args.size(); ++i) { args_add(preprocessor_args, ctx.args_info.arch_args[i]); result_name = get_result_name_from_cpp(ctx, preprocessor_args, hash); cc_log("Got result name from preprocessor with -arch %s", - ctx.args_info.arch_args[i]); - if (i != ctx.args_info.arch_args_size - 1) { + ctx.args_info.arch_args[i].c_str()); + if (i != ctx.args_info.arch_args.size() - 1) { free(result_name); result_name = nullptr; }