]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify ArgsInfo::arch_args
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 2 May 2020 10:46:39 +0000 (12:46 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 May 2020 18:25:58 +0000 (20:25 +0200)
src/ArgsInfo.hpp
src/argprocessing.cpp
src/ccache.cpp

index 19d76c6b0fe2dbfe827493d2c0cd0c8fd807ba78..5200304929c497bb038e5ee43dd910ba204af1f6 100644 (file)
@@ -94,10 +94,8 @@ struct ArgsInfo
   // Files referenced by -fsanitize-blacklist options.
   std::vector<std::string> 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<std::string> arch_args;
 
   // Relocating debuginfo in the format old=new.
   char** debug_prefix_maps = nullptr;
index 934ea7c60d2dfdc8388015c57d182c457f4ea94f..51f1a7bcc3454e782442999f23c108d2e880e9ac 100644 (file)
@@ -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);
index 4afc16f7c3817e6935959812ab5b1020f6e93c6b..ba5bdb23de5f48dcd2c4567b27a911a4caf60cdc 100644 (file)
@@ -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;
         }