From 029591ad90b72eed7904a0250bdc3c6028f8aaf2 Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Mon, 27 Jan 2020 19:57:23 +0100 Subject: [PATCH] Context: move ignore_headers_len, remove cc_reset() --- Makefile.in | 1 - src/Context.cpp | 5 ++++ src/Context.hpp | 4 ++++ src/ccache.cpp | 34 ++++++--------------------- src/legacy_globals.cpp | 6 ----- src/legacy_globals.hpp | 4 ---- src/manifest.cpp | 1 - unittest/test_argument_processing.cpp | 1 - 8 files changed, 16 insertions(+), 40 deletions(-) diff --git a/Makefile.in b/Makefile.in index ebd29d833..465772642 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,7 +59,6 @@ non_third_party_sources = \ src/hash.cpp \ src/hashutil.cpp \ src/language.cpp \ - src/legacy_globals.cpp \ src/legacy_util.cpp \ src/lockfile.cpp \ src/logging.cpp \ diff --git a/src/Context.cpp b/src/Context.cpp index 699bb2308..2d73cc13b 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -32,4 +32,9 @@ Context::~Context() args_free(orig_args); free(result_name); + + for (size_t i = 0; i < ignore_headers_len; i++) { + free(ignore_headers[i]); + } + free(ignore_headers); } diff --git a/src/Context.hpp b/src/Context.hpp index 56358cf2c..cc1e53e78 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -89,4 +89,8 @@ struct Context : NonCopyable // The .gch/.pch/.pth file used for compilation. std::string included_pch_file; + + // List of headers to ignore. + char** ignore_headers = nullptr; + size_t ignore_headers_len = 0; }; diff --git a/src/ccache.cpp b/src/ccache.cpp index d93d7cf6c..805fc8de0 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -35,7 +35,6 @@ #include "hash.hpp" #include "hashutil.hpp" #include "language.hpp" -#include "legacy_globals.hpp" #include "logging.hpp" #include "manifest.hpp" #include "result.hpp" @@ -480,8 +479,8 @@ do_remember_include_file(Context& ctx, canonical_len -= 2; } - for (size_t i = 0; i < ignore_headers_len; i++) { - char* ignore = ignore_headers[i]; + for (size_t i = 0; i < ctx.ignore_headers_len; i++) { + char* ignore = ctx.ignore_headers[i]; size_t ignore_len = strlen(ignore); if (ignore_len > canonical_len) { continue; @@ -699,16 +698,16 @@ process_preprocessed_file(Context& ctx, return false; } - ignore_headers = NULL; - ignore_headers_len = 0; + ctx.ignore_headers = nullptr; + ctx.ignore_headers_len = 0; if (!ctx.config.ignore_headers_in_manifest().empty()) { char *header, *p, *q, *saveptr = NULL; p = x_strdup(ctx.config.ignore_headers_in_manifest().c_str()); q = p; while ((header = strtok_r(q, PATH_DELIM, &saveptr))) { - ignore_headers = static_cast( - x_realloc(ignore_headers, (ignore_headers_len + 1) * sizeof(char*))); - ignore_headers[ignore_headers_len++] = x_strdup(header); + ctx.ignore_headers = static_cast(x_realloc( + ctx.ignore_headers, (ctx.ignore_headers_len + 1) * sizeof(char*))); + ctx.ignore_headers[ctx.ignore_headers_len++] = x_strdup(header); q = NULL; } free(p); @@ -3520,25 +3519,6 @@ initialize(int argc, char* argv[]) return *ctx; } -template -static void -free_and_nullify(T*& ptr) -{ - free(ptr); - ptr = NULL; -} - -// Reset the global state. Used by the test suite. -void -cc_reset() -{ - for (size_t i = 0; i < ignore_headers_len; i++) { - free_and_nullify(ignore_headers[i]); - } - free_and_nullify(ignore_headers); - ignore_headers_len = 0; -} - // Make a copy of stderr that will not be cached, so things like distcc can // send networking errors to it. static void diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 1bac9882a..f1c23fc29 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -18,11 +18,5 @@ #include "legacy_globals.hpp" -// List of headers to ignore. -char** ignore_headers; - -// Size of headers to ignore list. -size_t ignore_headers_len; - // How long (in microseconds) to wait before breaking a stale lock. unsigned lock_staleness_limit = 2000000; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index bb083fc7e..8dba783bd 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -29,7 +29,3 @@ // variable descriptions are in the .cpp file extern unsigned lock_staleness_limit; - -extern char** ignore_headers; - -extern size_t ignore_headers_len; diff --git a/src/manifest.cpp b/src/manifest.cpp index ccdee31df..764a94871 100644 --- a/src/manifest.cpp +++ b/src/manifest.cpp @@ -29,7 +29,6 @@ #include "ccache.hpp" #include "hash.hpp" #include "hashutil.hpp" -#include "legacy_globals.hpp" #include "logging.hpp" // Manifest data format diff --git a/unittest/test_argument_processing.cpp b/unittest/test_argument_processing.cpp index caadfb069..37cd5f732 100644 --- a/unittest/test_argument_processing.cpp +++ b/unittest/test_argument_processing.cpp @@ -23,7 +23,6 @@ #include "../src/Util.hpp" #include "../src/args.hpp" #include "../src/ccache.hpp" -#include "../src/legacy_globals.hpp" #include "../src/stats.hpp" #include "framework.hpp" #include "util.hpp" -- 2.47.2