From c2d3d4431c2958b06d3765e41bc1a5ac35454b59 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 30 Nov 2017 09:12:25 +1300 Subject: [PATCH] Make all read-only data arrays static and const A lot already were, but this wasn't consistently the case. --- xapian-core/bin/xapian-compact.cc | 2 +- xapian-core/bin/xapian-inspect.cc | 2 +- xapian-core/bin/xapian-replicate-server.cc | 2 +- xapian-core/bin/xapian-replicate.cc | 2 +- xapian-core/examples/quest.cc | 8 +++--- xapian-core/queryparser/lemon.c | 8 +++--- xapian-core/tests/api_anydb.cc | 7 ++--- xapian-core/tests/api_backend.cc | 14 +++++---- xapian-core/tests/api_db.cc | 24 +++++++++------- xapian-core/tests/api_matchspy.cc | 4 +-- xapian-core/tests/api_opsynonym.cc | 2 +- xapian-core/tests/api_opvalue.cc | 46 +++++++++++++++--------------- xapian-core/tests/api_percentages.cc | 4 +-- xapian-core/tests/api_query.cc | 4 +-- xapian-core/tests/api_queryparser.cc | 4 +-- xapian-core/tests/api_serialise.cc | 2 +- xapian-core/tests/api_snippets.cc | 2 +- xapian-core/tests/api_sorting.cc | 4 +-- xapian-core/tests/api_unicode.cc | 8 +++--- xapian-core/tests/api_weight.cc | 10 +++---- xapian-core/tests/api_wrdb.cc | 4 +-- xapian-core/tests/harness/testsuite.cc | 2 +- xapian-core/tests/perftest/freemem.cc | 4 +-- 23 files changed, 87 insertions(+), 82 deletions(-) diff --git a/xapian-core/bin/xapian-compact.cc b/xapian-core/bin/xapian-compact.cc index 80c836972..cebb48e33 100644 --- a/xapian-core/bin/xapian-compact.cc +++ b/xapian-core/bin/xapian-compact.cc @@ -107,7 +107,7 @@ int main(int argc, char **argv) { const char * opts = "b:nFmqs"; - const struct option long_opts[] = { + static const struct option long_opts[] = { {"fuller", no_argument, 0, 'F'}, {"no-full", no_argument, 0, 'n'}, {"multipass", no_argument, 0, 'm'}, diff --git a/xapian-core/bin/xapian-inspect.cc b/xapian-core/bin/xapian-inspect.cc index 0be2a4455..8615476ca 100644 --- a/xapian-core/bin/xapian-inspect.cc +++ b/xapian-core/bin/xapian-inspect.cc @@ -152,7 +152,7 @@ do_until(GlassCursor & cursor, const string & target) int main(int argc, char **argv) { - const struct option long_opts[] = { + static const struct option long_opts[] = { {"help", no_argument, 0, OPT_HELP}, {"version", no_argument, 0, OPT_VERSION}, {NULL, 0, 0, 0} diff --git a/xapian-core/bin/xapian-replicate-server.cc b/xapian-core/bin/xapian-replicate-server.cc index ed8cc5927..9184be237 100644 --- a/xapian-core/bin/xapian-replicate-server.cc +++ b/xapian-core/bin/xapian-replicate-server.cc @@ -52,7 +52,7 @@ int main(int argc, char **argv) { const char * opts = "I:p:o"; - const struct option long_opts[] = { + static const struct option long_opts[] = { {"interface", required_argument, 0, 'I'}, {"port", required_argument, 0, 'p'}, {"one-shot", no_argument, 0, 'o'}, diff --git a/xapian-core/bin/xapian-replicate.cc b/xapian-core/bin/xapian-replicate.cc index 3703981f8..85c0ffb14 100644 --- a/xapian-core/bin/xapian-replicate.cc +++ b/xapian-core/bin/xapian-replicate.cc @@ -73,7 +73,7 @@ int main(int argc, char **argv) { const char * opts = "h:p:m:i:r:t:ofqv"; - const struct option long_opts[] = { + static const struct option long_opts[] = { {"host", required_argument, 0, 'h'}, {"port", required_argument, 0, 'p'}, {"master", required_argument, 0, 'm'}, diff --git a/xapian-core/examples/quest.cc b/xapian-core/examples/quest.cc index 9c199c340..440adb025 100644 --- a/xapian-core/examples/quest.cc +++ b/xapian-core/examples/quest.cc @@ -36,7 +36,7 @@ using namespace std; #define PROG_DESC "Xapian command line search tool" // Stopwords: -static const char * sw[] = { +static const char * const sw[] = { "a", "about", "an", "and", "are", "as", "at", "be", "by", "en", @@ -49,7 +49,7 @@ static const char * sw[] = { }; struct qp_flag { const char * s; unsigned f; }; -static qp_flag flag_tab[] = { +static const qp_flag flag_tab[] = { { "auto_multiword_synonyms", Xapian::QueryParser::FLAG_AUTO_MULTIWORD_SYNONYMS }, { "auto_synonyms", Xapian::QueryParser::FLAG_AUTO_SYNONYMS }, { "boolean", Xapian::QueryParser::FLAG_BOOLEAN }, @@ -71,7 +71,7 @@ inline bool operator<(const qp_flag & f1, const qp_flag & f2) { } struct qp_op { const char * s; unsigned f; }; -static qp_op op_tab[] = { +static const qp_op op_tab[] = { { "and", Xapian::Query::OP_AND }, { "elite_set", Xapian::Query::OP_ELITE_SET }, { "max", Xapian::Query::OP_MAX }, @@ -104,7 +104,7 @@ enum { }; struct wt { const char * s; int f; }; -static wt wt_tab[] = { +static const wt wt_tab[] = { { "bb2", WEIGHT_BB2 }, { "bm25", WEIGHT_BM25 }, { "bm25+", WEIGHT_BM25PLUS }, diff --git a/xapian-core/queryparser/lemon.c b/xapian-core/queryparser/lemon.c index 0b4c332eb..162d3b046 100644 --- a/xapian-core/queryparser/lemon.c +++ b/xapian-core/queryparser/lemon.c @@ -197,7 +197,7 @@ struct s_options { void(*func)(); const char *message; }; -int OptInit(char**,struct s_options*,FILE*); +int OptInit(char**,const struct s_options*,FILE*); int OptNArgs(void); char *OptArg(int); void OptErr(int); @@ -1529,7 +1529,7 @@ int main(int argc, char **argv) static int mhflag = 0; static int nolinenosflag = 0; static int noResort = 0; - static struct s_options options[] = { + static const struct s_options options[] = { {OPT_FLAG, "b", (void*)&basisflag, 0, "Print only the basis in report."}, {OPT_FLAG, "c", (void*)&compress, 0, "Don't compress the action table."}, {OPT_FSTR, "D", 0, handle_D_option, "Define an %ifdef macro."}, @@ -1784,7 +1784,7 @@ static char *msort( } /************************ From the file "option.c" **************************/ static char **argv; -static struct s_options *op; +static const struct s_options *op; static FILE *errstream; #define ISOPT(X) ((X)[0]=='-'||(X)[0]=='+'||strchr((X),'=')!=0) @@ -1956,7 +1956,7 @@ static int handleswitch(int i, FILE *err) return errcnt; } -int OptInit(char **a, struct s_options *o, FILE *err) +int OptInit(char **a, const struct s_options *o, FILE *err) { int errcnt = 0; argv = a; diff --git a/xapian-core/tests/api_anydb.cc b/xapian-core/tests/api_anydb.cc index f452c24d6..568ad2255 100644 --- a/xapian-core/tests/api_anydb.cc +++ b/xapian-core/tests/api_anydb.cc @@ -2226,7 +2226,7 @@ DEFINE_TESTCASE(scaleweight1, backend) { Xapian::Enquire enq(db); Xapian::QueryParser qp; - static const char * queries[] = { + static const char * const queries[] = { "pad", "milk fridge", "leave milk on fridge", @@ -2235,16 +2235,15 @@ DEFINE_TESTCASE(scaleweight1, backend) { "leave \"milk on fridge\"", "notpresent", "leave \"milk notpresent\"", - NULL }; static const double multipliers[] = { -1000000, -2.5, -1, -0.5, 0, 0.5, 1, 2.5, 1000000, 0, 0 }; - for (const char **qstr = queries; *qstr; ++qstr) { + for (auto qstr : queries) { tout.str(string()); - Xapian::Query query1 = qp.parse_query(*qstr); + Xapian::Query query1 = qp.parse_query(qstr); tout << "query1: " << query1.get_description() << endl; for (const double *multp = multipliers; multp[0] != multp[1]; ++multp) { double mult = *multp; diff --git a/xapian-core/tests/api_backend.cc b/xapian-core/tests/api_backend.cc index 4041ae3fc..8ff4dd05c 100644 --- a/xapian-core/tests/api_backend.cc +++ b/xapian-core/tests/api_backend.cc @@ -860,7 +860,7 @@ DEFINE_TESTCASE(failedreplace2, glass) { DEFINE_TESTCASE(phrase3, positional) { Xapian::Database db = get_database("apitest_phrase"); - const char * phrase_words[] = { "phrase", "near" }; + static const char * const phrase_words[] = { "phrase", "near" }; Xapian::Query q(Xapian::Query::OP_NEAR, phrase_words, phrase_words + 2, 12); q = Xapian::Query(Xapian::Query::OP_AND_MAYBE, Xapian::Query("pad"), q); @@ -1165,13 +1165,13 @@ make_phrasebug1_db(Xapian::WritableDatabase &db, const string &) /// Regression test for ticket#653, fixed in 1.3.2 and 1.2.19. DEFINE_TESTCASE(phrasebug1, generated && positional) { Xapian::Database db = get_database("phrasebug1", make_phrasebug1_db); - const char * qterms[] = { "katrina", "hurricane" }; + static const char * const qterms[] = { "katrina", "hurricane" }; Xapian::Enquire e(db); Xapian::Query q(Xapian::Query::OP_PHRASE, qterms, qterms + 2, 5); e.set_query(q); Xapian::MSet mset = e.get_mset(0, 100); TEST_EQUAL(mset.size(), 0); - const char * qterms2[] = { "hurricane", "katrina" }; + static const char * const qterms2[] = { "hurricane", "katrina" }; Xapian::Query q2(Xapian::Query::OP_PHRASE, qterms2, qterms2 + 2, 5); e.set_query(q2); mset = e.get_mset(0, 100); @@ -1465,7 +1465,9 @@ DEFINE_TESTCASE(exactxor1, backend) { Xapian::Database db = get_database("apitest_simpledata"); Xapian::Enquire enq(db); - const char * words[4] = { "blank", "test", "paragraph", "banana" }; + static const char * const words[4] = { + "blank", "test", "paragraph", "banana" + }; Xapian::Query q(Xapian::Query::OP_XOR, words, words + 4); enq.set_query(q); enq.set_weighting_scheme(Xapian::BoolWeight()); @@ -1475,7 +1477,9 @@ DEFINE_TESTCASE(exactxor1, backend) { // Test improved lower bound in 1.3.7 (earlier versions gave 0). TEST_EQUAL(mset.get_matches_lower_bound(), 2); - const char * words2[4] = { "queri", "test", "paragraph", "word" }; + static const char * const words2[4] = { + "queri", "test", "paragraph", "word" + }; Xapian::Query q2(Xapian::Query::OP_XOR, words2, words2 + 4); enq.set_query(q2); enq.set_weighting_scheme(Xapian::BoolWeight()); diff --git a/xapian-core/tests/api_db.cc b/xapian-core/tests/api_db.cc index cee793645..afdf4775b 100644 --- a/xapian-core/tests/api_db.cc +++ b/xapian-core/tests/api_db.cc @@ -1534,15 +1534,15 @@ DEFINE_TESTCASE(sortrel1, backend) { enquire.set_sort_by_value(1, true); enquire.set_query(Xapian::Query("woman")); - const Xapian::docid order1[] = { 1,2,3,4,5,6,7,8,9 }; - const Xapian::docid order2[] = { 2,1,3,6,5,4,7,9,8 }; - const Xapian::docid order3[] = { 3,2,1,6,5,4,9,8,7 }; - const Xapian::docid order4[] = { 7,8,9,4,5,6,1,2,3 }; - const Xapian::docid order5[] = { 9,8,7,6,5,4,3,2,1 }; - const Xapian::docid order6[] = { 7,9,8,6,5,4,2,1,3 }; - const Xapian::docid order7[] = { 7,9,8,6,5,4,2,1,3 }; - const Xapian::docid order8[] = { 2,6,7,1,5,9,3,4,8 }; - const Xapian::docid order9[] = { 7,6,2,9,5,1,8,4,3 }; + static const Xapian::docid order1[] = { 1,2,3,4,5,6,7,8,9 }; + static const Xapian::docid order2[] = { 2,1,3,6,5,4,7,9,8 }; + static const Xapian::docid order3[] = { 3,2,1,6,5,4,9,8,7 }; + static const Xapian::docid order4[] = { 7,8,9,4,5,6,1,2,3 }; + static const Xapian::docid order5[] = { 9,8,7,6,5,4,3,2,1 }; + static const Xapian::docid order6[] = { 7,9,8,6,5,4,2,1,3 }; + static const Xapian::docid order7[] = { 7,9,8,6,5,4,2,1,3 }; + static const Xapian::docid order8[] = { 2,6,7,1,5,9,3,4,8 }; + static const Xapian::docid order9[] = { 7,6,2,9,5,1,8,4,3 }; Xapian::MSet mset; size_t i; @@ -1659,7 +1659,7 @@ DEFINE_TESTCASE(netstats1, remote) { BackendManagerLocal local_manager; local_manager.set_datadir(test_driver::get_srcdir() + "/testdata/"); - const char * words[] = { "paragraph", "word" }; + static const char * const words[] = { "paragraph", "word" }; Xapian::Query query(Xapian::Query::OP_OR, words, words + 2); const size_t MSET_SIZE = 10; @@ -1760,7 +1760,9 @@ class MyWeight : public Xapian::Weight { DEFINE_TESTCASE(userweight1, backend && !remote) { Xapian::Enquire enquire(get_database("apitest_simpledata")); enquire.set_weighting_scheme(MyWeight()); - const char * query[] = { "this", "line", "paragraph", "rubbish" }; + static const char * const query[] = { + "this", "line", "paragraph", "rubbish" + }; enquire.set_query(Xapian::Query(Xapian::Query::OP_OR, query, query + sizeof(query) / sizeof(query[0]))); Xapian::MSet mymset1 = enquire.get_mset(0, 100); diff --git a/xapian-core/tests/api_matchspy.cc b/xapian-core/tests/api_matchspy.cc index 5259aa440..5f299513b 100644 --- a/xapian-core/tests/api_matchspy.cc +++ b/xapian-core/tests/api_matchspy.cc @@ -160,7 +160,7 @@ DEFINE_TESTCASE(matchspy2, generated) TEST_EQUAL(spy1.get_total(), 25); TEST_EQUAL(spy3.get_total(), 25); - static const char * results[] = { + static const char * const results[] = { "|1:1|2:9|3:3|4:7|5:1|6:3|8:1|", "|0:2|1:3|2:3|3:3|4:3|5:3|6:2|7:2|8:2|9:2|", "|1:9|2:16|", @@ -210,7 +210,7 @@ DEFINE_TESTCASE(matchspy4, generated) TEST_EQUAL(spyb1.get_total(), 25); TEST_EQUAL(spyb3.get_total(), 25); - static const char * results[] = { + static const char * const results[] = { "|2:9|4:7|3:3|6:3|1:1|5:1|8:1|", "|1:3|2:3|3:3|4:3|5:3|0:2|6:2|7:2|8:2|9:2|", "|", diff --git a/xapian-core/tests/api_opsynonym.cc b/xapian-core/tests/api_opsynonym.cc index 8e6c6f467..d40669a72 100644 --- a/xapian-core/tests/api_opsynonym.cc +++ b/xapian-core/tests/api_opsynonym.cc @@ -55,7 +55,7 @@ struct synonym1_data_type { }; #define NOQ Xapian::Query::MatchNothing -static synonym1_data_type synonym1_data[] = { +static const synonym1_data_type synonym1_data[] = { { // Single term - all 33 results should be same weight. 33, 0, 1, diff --git a/xapian-core/tests/api_opvalue.cc b/xapian-core/tests/api_opvalue.cc index ab58f87ed..ba8d0372f 100644 --- a/xapian-core/tests/api_opvalue.cc +++ b/xapian-core/tests/api_opvalue.cc @@ -39,12 +39,12 @@ using namespace std; DEFINE_TESTCASE(valuerange1, backend) { Xapian::Database db(get_database("apitest_phrase")); Xapian::Enquire enq(db); - static const char * vals[] = { - "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z", NULL + static const char * const vals[] = { + "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z" }; - for (const char **start = vals; *start; ++start) { - for (const char **end = vals; *end; ++end) { - Xapian::Query query(Xapian::Query::OP_VALUE_RANGE, 1, *start, *end); + for (auto start : vals) { + for (auto end : vals) { + Xapian::Query query(Xapian::Query::OP_VALUE_RANGE, 1, start, end); enq.set_query(query); Xapian::MSet mset = enq.get_mset(0, 20); // Check that documents in the MSet match the value range filter. @@ -53,15 +53,15 @@ DEFINE_TESTCASE(valuerange1, backend) { for (i = mset.begin(); i != mset.end(); ++i) { matched.insert(*i); string value = db.get_document(*i).get_value(1); - TEST_REL(value,>=,*start); - TEST_REL(value,<=,*end); + TEST_REL(value,>=,start); + TEST_REL(value,<=,end); } // Check that documents not in the MSet don't match the value range filter. for (Xapian::docid j = db.get_lastdocid(); j != 0; --j) { if (matched.find(j) == matched.end()) { string value = db.get_document(j).get_value(1); - tout << value << " < '" << *start << "' or > '" << *end << "'" << endl; - TEST(value < *start || value > *end); + tout << value << " < '" << start << "' or > '" << end << "'" << endl; + TEST(value < start || value > end); } } } @@ -283,11 +283,11 @@ DEFINE_TESTCASE(valuerange7, generated) { DEFINE_TESTCASE(valuege1, backend) { Xapian::Database db(get_database("apitest_phrase")); Xapian::Enquire enq(db); - static const char * vals[] = { - "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z", NULL + static const char * const vals[] = { + "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z" }; - for (const char **start = vals; *start; ++start) { - Xapian::Query query(Xapian::Query::OP_VALUE_GE, 1, *start); + for (auto start : vals) { + Xapian::Query query(Xapian::Query::OP_VALUE_GE, 1, start); enq.set_query(query); Xapian::MSet mset = enq.get_mset(0, 20); // Check that documents in the MSet match the value range filter. @@ -296,16 +296,16 @@ DEFINE_TESTCASE(valuege1, backend) { for (i = mset.begin(); i != mset.end(); ++i) { matched.insert(*i); string value = db.get_document(*i).get_value(1); - tout << "'" << *start << "' <= '" << value << "'" << endl; - TEST_REL(value,>=,*start); + tout << "'" << start << "' <= '" << value << "'" << endl; + TEST_REL(value,>=,start); } // Check that documents not in the MSet don't match the value range // filter. for (Xapian::docid j = db.get_lastdocid(); j != 0; --j) { if (matched.find(j) == matched.end()) { string value = db.get_document(j).get_value(1); - tout << value << " < '" << *start << "'" << endl; - TEST_REL(value,<,*start); + tout << value << " < '" << start << "'" << endl; + TEST_REL(value,<,start); } } } @@ -329,11 +329,11 @@ DEFINE_TESTCASE(valuege2, backend) { DEFINE_TESTCASE(valuele1, backend) { Xapian::Database db(get_database("apitest_phrase")); Xapian::Enquire enq(db); - static const char * vals[] = { - "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z", NULL + static const char * const vals[] = { + "", " ", "a", "aa", "abcd", "e", "g", "h", "hzz", "i", "l", "z" }; - for (const char **end = vals; *end; ++end) { - Xapian::Query query(Xapian::Query::OP_VALUE_LE, 1, *end); + for (auto end : vals) { + Xapian::Query query(Xapian::Query::OP_VALUE_LE, 1, end); enq.set_query(query); Xapian::MSet mset = enq.get_mset(0, 20); // Check that documents in the MSet match the value range filter. @@ -342,14 +342,14 @@ DEFINE_TESTCASE(valuele1, backend) { for (i = mset.begin(); i != mset.end(); ++i) { matched.insert(*i); string value = db.get_document(*i).get_value(1); - TEST_REL(value,<=,*end); + TEST_REL(value,<=,end); } // Check that documents not in the MSet don't match the value range // filter. for (Xapian::docid j = db.get_lastdocid(); j != 0; --j) { if (matched.find(j) == matched.end()) { string value = db.get_document(j).get_value(1); - TEST_REL(value,>,*end); + TEST_REL(value,>,end); } } } diff --git a/xapian-core/tests/api_percentages.cc b/xapian-core/tests/api_percentages.cc index ca97f2cce..b9e508390 100644 --- a/xapian-core/tests/api_percentages.cc +++ b/xapian-core/tests/api_percentages.cc @@ -208,7 +208,7 @@ DEFINE_TESTCASE(topercent3, remote) { Xapian::Enquire enquire(db); enquire.set_sort_by_value(1, false); - const char * terms[] = { "paragraph", "banana" }; + static const char * const terms[] = { "paragraph", "banana" }; enquire.set_query(Xapian::Query(Xapian::Query::OP_OR, terms, terms + 2)); Xapian::MSet mset = enquire.get_mset(0, 20); @@ -346,7 +346,7 @@ DEFINE_TESTCASE(checkzeromaxpartopt1, backend && !remote) { Xapian::Enquire enquire(db); // "this" indexes all documents, so will get replaced with MatchAll // internally. - const char * terms[] = { "this", "spoken", "blank" }; + static const char * const terms[] = { "this", "spoken", "blank" }; enquire.set_query(Xapian::Query(Xapian::Query::OP_OR, terms, terms + 3)); ZWeight wt; enquire.set_weighting_scheme(wt); diff --git a/xapian-core/tests/api_query.cc b/xapian-core/tests/api_query.cc index ff4b916e3..1f7afe381 100644 --- a/xapian-core/tests/api_query.cc +++ b/xapian-core/tests/api_query.cc @@ -169,7 +169,7 @@ DEFINE_TESTCASE(possubqueries1, writable) { DEFINE_TESTCASE(xor3, backend) { Xapian::Database db = get_database("apitest_simpledata"); - const char * subqs[] = { + static const char * const subqs[] = { "hack", "which", "paragraph", "is", "return" }; // Document where the subqueries run out *does* match XOR: @@ -281,7 +281,7 @@ DEFINE_TESTCASE(queryintro1, !backend) { DEFINE_TESTCASE(phrasealldocs1, backend) { Xapian::Database db = get_database("apitest_declen"); Xapian::Query q; - const char * phrase[] = { "this", "is", "the" }; + static const char * const phrase[] = { "this", "is", "the" }; q = Xapian::Query(q.OP_AND_NOT, Xapian::Query("paragraph"), Xapian::Query(q.OP_PHRASE, phrase, phrase + 3)); diff --git a/xapian-core/tests/api_queryparser.cc b/xapian-core/tests/api_queryparser.cc index 43c5318a7..092d53360 100644 --- a/xapian-core/tests/api_queryparser.cc +++ b/xapian-core/tests/api_queryparser.cc @@ -1289,7 +1289,7 @@ static const test test_stop_queries[] = { DEFINE_TESTCASE(qp_stopper1, !backend) { Xapian::QueryParser qp; - const char * stopwords[] = { "a", "an", "the" }; + static const char * const stopwords[] = { "a", "an", "the" }; Xapian::SimpleStopper stop(stopwords, stopwords + 3); qp.set_stopper(&stop); qp.set_default_op(Xapian::Query::OP_AND); @@ -2179,7 +2179,7 @@ DEFINE_TESTCASE(qp_fieldproc3, !backend) { DEFINE_TESTCASE(qp_stoplist1, !backend) { Xapian::QueryParser qp; - const char * stopwords[] = { "a", "an", "the" }; + static const char * const stopwords[] = { "a", "an", "the" }; Xapian::SimpleStopper stop(stopwords, stopwords + 3); qp.set_stopper(&stop); diff --git a/xapian-core/tests/api_serialise.cc b/xapian-core/tests/api_serialise.cc index f37d3f548..2a5ba5972 100644 --- a/xapian-core/tests/api_serialise.cc +++ b/xapian-core/tests/api_serialise.cc @@ -207,7 +207,7 @@ DEFINE_TESTCASE(serialise_query1, !backend) { TEST_EQUAL(q.get_description(), q2.get_description()); TEST_EQUAL(q.get_description(), "Query((hello@1 OR world@1))"); - static const char * phrase[] = { "shaken", "not", "stirred" }; + static const char * const phrase[] = { "shaken", "not", "stirred" }; q = Xapian::Query(q.OP_PHRASE, phrase, phrase + 3); q = Xapian::Query(q.OP_OR, Xapian::Query("007"), q); q = Xapian::Query(q.OP_SCALE_WEIGHT, q, 3.14); diff --git a/xapian-core/tests/api_snippets.cc b/xapian-core/tests/api_snippets.cc index 4c9296f88..1e5faa0c6 100644 --- a/xapian-core/tests/api_snippets.cc +++ b/xapian-core/tests/api_snippets.cc @@ -172,7 +172,7 @@ DEFINE_TESTCASE(snippetmisc1, generated) { enquire.set_weighting_scheme(Xapian::BoolWeight()); Xapian::Stem stem("en"); - static const char * words[] = { "do", "we", "have" }; + static const char * const words[] = { "do", "we", "have" }; Xapian::Query q(Xapian::Query::OP_PHRASE, words, words + 3); enquire.set_query(q); Xapian::MSet mset = enquire.get_mset(0, 6); diff --git a/xapian-core/tests/api_sorting.cc b/xapian-core/tests/api_sorting.cc index ab7576554..408d663a6 100644 --- a/xapian-core/tests/api_sorting.cc +++ b/xapian-core/tests/api_sorting.cc @@ -35,7 +35,7 @@ DEFINE_TESTCASE(sortfunctor1, backend && !remote) { enquire.set_query(Xapian::Query("woman")); { - const int keys[] = { 3, 1 }; + static const int keys[] = { 3, 1 }; Xapian::MultiValueKeyMaker sorter(keys, keys + 2); enquire.set_sort_by_key(&sorter, true); @@ -275,7 +275,7 @@ DEFINE_TESTCASE(sortfunctorempty1, backend && !remote) { } DEFINE_TESTCASE(multivaluekeymaker1, !backend) { - const int keys[] = { 0, 1, 2, 3 }; + static const int keys[] = { 0, 1, 2, 3 }; Xapian::MultiValueKeyMaker sorter(keys, keys + 4); Xapian::Document doc; diff --git a/xapian-core/tests/api_unicode.cc b/xapian-core/tests/api_unicode.cc index 238f4918e..012fb7e5e 100644 --- a/xapian-core/tests/api_unicode.cc +++ b/xapian-core/tests/api_unicode.cc @@ -435,7 +435,7 @@ DEFINE_TESTCASE(utf8convert1, !backend) { } DEFINE_TESTCASE(unicodepredicates1, !backend) { - const unsigned wordchars[] = { + static const unsigned wordchars[] = { // DECIMAL_DIGIT_NUMBER '0', '7', '9', 0x11D51, // (added in Unicode 10.0.0) @@ -467,7 +467,7 @@ DEFINE_TESTCASE(unicodepredicates1, !backend) { 0x11d47, // Added in Unicode 10.0.0 0 }; - const unsigned currency[] = { + static const unsigned currency[] = { // CURRENCY_SYMBOL '$', 0xa3, // CURRENCY_SYMBOL (added in Unicode 6.2.0) @@ -478,14 +478,14 @@ DEFINE_TESTCASE(unicodepredicates1, !backend) { 0x20bf, 0 }; - const unsigned whitespace[] = { + static const unsigned whitespace[] = { // CONTROL '\t', '\n', '\f', '\r', // SPACE_SEPARATOR ' ', 0 }; - const unsigned other[] = { + static const unsigned other[] = { // DASH_PUNCTUATION (added in Unicode 5.1.0) 0x5be, // OTHER_SYMBOL diff --git a/xapian-core/tests/api_weight.cc b/xapian-core/tests/api_weight.cc index aebdd7aa6..2c028a838 100644 --- a/xapian-core/tests/api_weight.cc +++ b/xapian-core/tests/api_weight.cc @@ -1298,15 +1298,13 @@ DEFINE_TESTCASE(checkstatsweight3, backend && !remote && !multi) { Xapian::Database db = get_database("apitest_simpledata"); Xapian::Enquire enquire(db); Xapian::TermIterator a; - static const char * testcases[] = { + static const char * const testcases[] = { "a", // a* matches all documents, but no term matches all. "pa", // Expands to only "paragraph", matching 5. "zulu", // No matches. "th", // Term "this" matches all documents. - NULL }; - for (const char ** p = testcases; *p; ++p) { - const char * pattern = *p; + for (auto pattern : testcases) { Xapian::Query q(Xapian::Query::OP_WILDCARD, pattern); tout << q.get_description() << endl; enquire.set_query(q); @@ -1520,7 +1518,9 @@ DEFINE_TESTCASE(boolweight1, !backend) { DEFINE_TESTCASE(coordweight1, backend) { Xapian::Enquire enquire(get_database("apitest_simpledata")); enquire.set_weighting_scheme(Xapian::CoordWeight()); - const char * terms[] = { "this", "line", "paragraph", "rubbish" }; + static const char * const terms[] = { + "this", "line", "paragraph", "rubbish" + }; Xapian::Query query(Xapian::Query::OP_OR, terms, terms + sizeof(terms) / sizeof(terms[0])); enquire.set_query(query); diff --git a/xapian-core/tests/api_wrdb.cc b/xapian-core/tests/api_wrdb.cc index b8505dd59..c10b229cc 100644 --- a/xapian-core/tests/api_wrdb.cc +++ b/xapian-core/tests/api_wrdb.cc @@ -1374,7 +1374,7 @@ DEFINE_TESTCASE(phraseorneartoand1, writable) { Xapian::Enquire enquire(db); Xapian::MSet mymset; - const char * q1[] = { "all", "1" }; + static const char * const q1[] = { "all", "1" }; enquire.set_query(Xapian::Query(Xapian::Query::OP_PHRASE, q1, q1 + 2)); mymset = enquire.get_mset(0, 10); TEST_EQUAL(2, mymset.size()); @@ -1383,7 +1383,7 @@ DEFINE_TESTCASE(phraseorneartoand1, writable) { mymset = enquire.get_mset(0, 10); TEST_EQUAL(2, mymset.size()); - const char * q2[] = { "1", "2" }; + static const char * const q2[] = { "1", "2" }; enquire.set_query(Xapian::Query(Xapian::Query::OP_PHRASE, q2, q2 + 2)); mymset = enquire.get_mset(0, 10); TEST_EQUAL(0, mymset.size()); diff --git a/xapian-core/tests/harness/testsuite.cc b/xapian-core/tests/harness/testsuite.cc index c7afae12e..3808a3441 100644 --- a/xapian-core/tests/harness/testsuite.cc +++ b/xapian-core/tests/harness/testsuite.cc @@ -765,7 +765,7 @@ test_driver::parse_command_line(int argc, char **argv) } #endif - const struct option long_opts[] = { + static const struct option long_opts[] = { {"verbose", no_argument, 0, 'v'}, {"abort-on-error", no_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, diff --git a/xapian-core/tests/perftest/freemem.cc b/xapian-core/tests/perftest/freemem.cc index e043be256..bd4c8790f 100644 --- a/xapian-core/tests/perftest/freemem.cc +++ b/xapian-core/tests/perftest/freemem.cc @@ -85,7 +85,7 @@ get_free_physical_memory() #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) /* FreeBSD: */ struct vmtotal vm_info; - int mib[2] = { + static const int mib[2] = { CTL_VM, #ifdef VM_TOTAL VM_TOTAL @@ -146,7 +146,7 @@ get_total_physical_memory() #elif defined CTL_VM && (defined VM_TOTAL || defined VM_METER) /* FreeBSD: */ struct vmtotal vm_info; - int mib[2] = { + static const int mib[2] = { CTL_VM, #ifdef VM_TOTAL VM_TOTAL -- 2.11.4.GIT