# # # patch "database.cc" # from [c96663fc818db68864f8754d6bdc1bac842a2458] # to [30ebb5c3bf65fb86be75fa613e6f603443b241db] # # patch "globish.cc" # from [e7da31307bd447174113a1c37d69395da088d05a] # to [942cfee157ecd028adfbe0a81f2a49b74aa8b1fd] # # patch "restrictions.cc" # from [69361677eaddd7346cd72dab35896609948f0a5d] # to [2f74d8ea5a5f5dab8299a32bbd5ee6476a610976] # # patch "sanity.cc" # from [a25e5e09451b0ea2219c650a1a64502148ab5005] # to [d3c9ad4e290d48f5df7ed588ae883986e3ca0e8b] # # patch "sanity.hh" # from [4ba3c209ddf14a22609ec8e5b41e409551b74602] # to [67a009db0bbdd3565a7021f61e5b1e4a7194f480] # ============================================================ --- database.cc c96663fc818db68864f8754d6bdc1bac842a2458 +++ database.cc 30ebb5c3bf65fb86be75fa613e6f603443b241db @@ -1053,23 +1053,14 @@ database_impl::fetch(results & res, // Ensure that exactly the right number of parameters were given I(params == int(query.args.size())); - // profiling finds this logging to be quite expensive - if (global_sanity.debug_p()) - L(FL("binding %d parameters for %s") % params % query.sql_cmd); + L(FL("binding %d parameters for %s") % params % query.sql_cmd); for (int param = 1; param <= params; param++) { // profiling finds this logging to be quite expensive if (global_sanity.debug_p()) { - string log; - switch (query.args[param-1].type) - { - case query_param::text: - case query_param::blob: - log = query.args[param-1].data; - break; - } + string log(query.args[param-1].data); if (log.size() > constants::log_line_sz) log = log.substr(0, constants::log_line_sz); ============================================================ --- globish.cc e7da31307bd447174113a1c37d69395da088d05a +++ globish.cc 942cfee157ecd028adfbe0a81f2a49b74aa8b1fd @@ -364,8 +364,7 @@ do_match(string::const_iterator sb, stri unsigned int sc, pc; string::const_iterator s(sb); - if (global_sanity.debug_p()) // decode() is expensive - L(FL("subpattern: '%s' against '%s'") % string(s,se) % decode(p,pe)); + L(FL("subpattern: '%s' against '%s'") % string(s,se) % decode(p,pe)); while (p < pe) { @@ -430,9 +429,8 @@ do_match(string::const_iterator sb, stri // starting from places in s where that character appears. if (pc >= ' ') { - if (global_sanity.debug_p()) - L(FL("after *: looking for '%c' in '%c%s'") - % (char)pc % (char)sc % string(s, se)); + L(FL("after *: looking for '%c' in '%c%s'") + % (char)pc % (char)sc % string(s, se)); p++; for (;;) { @@ -445,8 +443,7 @@ do_match(string::const_iterator sb, stri } else { - if (global_sanity.debug_p()) - L(FL("metacharacter after *: doing it the slow way")); + L(FL("metacharacter after *: doing it the slow way")); s--; do { ============================================================ --- restrictions.cc 69361677eaddd7346cd72dab35896609948f0a5d +++ restrictions.cc 2f74d8ea5a5f5dab8299a32bbd5ee6476a610976 @@ -377,12 +377,8 @@ node_restriction::includes(roster_t cons } else { - if (global_sanity.debug_p()) - { - // printing this slows down "log ". - L(FL("(debug) default exclude of nid %d path '%s'") - % nid % fp); - } + L(FL("(debug) default exclude of nid %d path '%s'") + % nid % fp); return false; } } ============================================================ --- sanity.cc a25e5e09451b0ea2219c650a1a64502148ab5005 +++ sanity.cc d3c9ad4e290d48f5df7ed588ae883986e3ca0e8b @@ -189,28 +189,34 @@ sanity::debug_p() bool sanity::debug_p() { - I(imp); + if (!imp) + throw std::logic_error("sanity::debug_p called " + "before sanity::initialize"); return imp->debug; } bool sanity::quiet_p() { - I(imp); + if (!imp) + throw std::logic_error("sanity::quiet_p called " + "before sanity::initialize"); return imp->quiet; } -// These functions can be called before sanity::initialize() if there -// is a bug, and therefore must not use I() if imp is unavailable, as -// that will cause infinite recursion (invariant_failure calls log). +bool +sanity::reallyquiet_p() +{ + if (!imp) + throw std::logic_error("sanity::reallyquiet_p called " + "before sanity::initialize"); + return imp->reallyquiet; +} void sanity::log(plain_format const & fmt, char const * file, int line) { - if (!imp) - throw std::logic_error("sanity::log called before sanity::initialize"); - string str = do_format(fmt, file, line); if (str.size() > constants::log_line_sz) @@ -222,17 +228,14 @@ sanity::log(plain_format const & fmt, copy(str.begin(), str.end(), back_inserter(imp->logbuf)); if (str[str.size() - 1] != '\n') imp->logbuf.push_back('\n'); - if (imp->debug) - inform_log(str); + + inform_log(str); } void sanity::progress(i18n_format const & i18nfmt, char const * file, int line) { - if (!imp) - throw std::logic_error("sanity::progress called before sanity::initialize"); - string str = do_format(i18nfmt, file, line); if (str.size() > constants::log_line_sz) @@ -244,17 +247,14 @@ sanity::progress(i18n_format const & i18 copy(str.begin(), str.end(), back_inserter(imp->logbuf)); if (str[str.size() - 1] != '\n') imp->logbuf.push_back('\n'); - if (! imp->quiet) - inform_message(str); + + inform_message(str); } void sanity::warning(i18n_format const & i18nfmt, char const * file, int line) { - if (!imp) - throw std::logic_error("sanity::warning called before sanity::initialize"); - string str = do_format(i18nfmt, file, line); if (str.size() > constants::log_line_sz) @@ -267,8 +267,8 @@ sanity::warning(i18n_format const & i18n copy(str2.begin(), str2.end(), back_inserter(imp->logbuf)); if (str[str.size() - 1] != '\n') imp->logbuf.push_back('\n'); - if (! imp->reallyquiet) - inform_warning(str); + + inform_warning(str); } void @@ -276,8 +276,12 @@ sanity::naughty_failure(char const * exp char const * file, int line) { string message; - log(FL("%s:%d: usage constraint '%s' violated") % file % line % expr, - file, line); + if (!imp) + throw std::logic_error("sanity::naughty_failure occured " + "before sanity::initialize"); + if (imp->debug) + log(FL("%s:%d: usage constraint '%s' violated") % file % line % expr, + file, line); prefix_lines_with(_("misuse: "), do_format(explain, file, line), message); gasp(); throw informative_failure(message); @@ -288,8 +292,12 @@ sanity::error_failure(char const * expr, char const * file, int line) { string message; - log(FL("%s:%d: detected error '%s' violated") % file % line % expr, - file, line); + if (!imp) + throw std::logic_error("sanity::error_failure occured " + "before sanity::initialize"); + if (imp->debug) + log(FL("%s:%d: detected error '%s' violated") % file % line % expr, + file, line); gasp(); prefix_lines_with(_("error: "), do_format(explain, file, line), message); throw informative_failure(message); @@ -299,7 +307,11 @@ sanity::invariant_failure(char const * e sanity::invariant_failure(char const * expr, char const * file, int line) { char const * pattern = N_("%s:%d: invariant '%s' violated"); - log(FL(pattern) % file % line % expr, file, line); + if (!imp) + throw std::logic_error("sanity::invariant_failure occured " + "before sanity::initialize"); + if (imp->debug) + log(FL(pattern) % file % line % expr, file, line); gasp(); throw logic_error((F(pattern) % file % line % expr).str()); } @@ -313,8 +325,12 @@ sanity::index_failure(char const * vec_e { char const * pattern = N_("%s:%d: index '%s' = %d overflowed vector '%s' with size %d"); - log(FL(pattern) % file % line % idx_expr % idx % vec_expr % sz, - file, line); + if (!imp) + throw std::logic_error("sanity::index_failure occured " + "before sanity::initialize"); + if (imp->debug) + log(FL(pattern) % file % line % idx_expr % idx % vec_expr % sz, + file, line); gasp(); throw logic_error((F(pattern) % file % line % idx_expr % idx % vec_expr % sz).str()); ============================================================ --- sanity.hh 4ba3c209ddf14a22609ec8e5b41e409551b74602 +++ sanity.hh 67a009db0bbdd3565a7021f61e5b1e4a7194f480 @@ -59,6 +59,8 @@ struct sanity { // command line (and needs to look at this to do so). bool quiet_p(); + bool reallyquiet_p(); + void log(plain_format const & fmt, char const * file, int line); void progress(i18n_format const & fmt, @@ -286,15 +288,27 @@ plain_format FL(const char * str); plain_format FL(const char * str); // L is for logging, you can log all you want -#define L(fmt) global_sanity.log(fmt, __FILE__, __LINE__) +#define L(fmt) \ +do { \ + if (global_sanity.debug_p()) \ + global_sanity.log(fmt, __FILE__, __LINE__); \ +} while (0) // P is for progress, log only stuff which the user might // normally like to see some indication of progress of -#define P(fmt) global_sanity.progress(fmt, __FILE__, __LINE__) +#define P(fmt) \ +do { \ + if (!global_sanity.quiet_p()) \ + global_sanity.progress(fmt, __FILE__, __LINE__); \ +} while (0) // W is for warnings, which are handled like progress only // they are only issued once and are prefixed with "warning: " -#define W(fmt) global_sanity.warning(fmt, __FILE__, __LINE__) +#define W(fmt) \ +do { \ + if (!global_sanity.reallyquiet_p()) \ + global_sanity.warning(fmt, __FILE__, __LINE__); \ +} while (0) // invariants and assertions