mirror of https://github.com/djcb/mu.git
lib: fix clang compatibility / warnings
This commit is contained in:
parent
d2e6cfdf70
commit
c0da564bba
|
@ -49,7 +49,7 @@ struct EmailHash {
|
||||||
{
|
{
|
||||||
std::size_t djb = 5381; // djb hash
|
std::size_t djb = 5381; // djb hash
|
||||||
for (const auto c : email)
|
for (const auto c : email)
|
||||||
djb = ((djb << 5) + djb) + g_ascii_tolower(c);
|
djb = ((djb << 5) + djb) + static_cast<size_t>(g_ascii_tolower(c));
|
||||||
return djb;
|
return djb;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -66,7 +66,7 @@ struct ContactInfoHash {
|
||||||
{
|
{
|
||||||
std::size_t djb = 5381; // djb hash
|
std::size_t djb = 5381; // djb hash
|
||||||
for (const auto c : ci.email)
|
for (const auto c : ci.email)
|
||||||
djb = ((djb << 5) + djb) + g_ascii_tolower(c);
|
djb = ((djb << 5) + djb) + static_cast<size_t>(g_ascii_tolower(c));
|
||||||
return djb;
|
return djb;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,6 +75,9 @@ static_assert(message_flag_info("attach")->flag == MessageFlags::HasAttachment);
|
||||||
static_assert(!message_flag_info("fnorb"));
|
static_assert(!message_flag_info("fnorb"));
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(message_flag_info('D')->shortcut_lower() == 'd');
|
||||||
|
static_assert(message_flag_info('u')->shortcut_lower() == 'u');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* message_flags_from_expr
|
* message_flags_from_expr
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -92,6 +92,16 @@ struct MessageFlagInfo {
|
||||||
char shortcut; /**< Shortcut character */
|
char shortcut; /**< Shortcut character */
|
||||||
std::string_view name; /**< Name of the flag */
|
std::string_view name; /**< Name of the flag */
|
||||||
MessageFlagCategory category; /**< Flag category */
|
MessageFlagCategory category; /**< Flag category */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lower-case version of shortcut
|
||||||
|
*
|
||||||
|
* @return lower-case shortcut
|
||||||
|
*/
|
||||||
|
constexpr char shortcut_lower() const {
|
||||||
|
return shortcut >= 'A' && shortcut <= 'Z' ?
|
||||||
|
shortcut + ('a' - 'A') : shortcut;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2011-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2011-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -87,7 +87,7 @@ add_list_post(Sexp::List& list, MuMsg* msg)
|
||||||
|
|
||||||
if (g_regex_match(rx, list_post, (GRegexMatchFlags)0, &minfo)) {
|
if (g_regex_match(rx, list_post, (GRegexMatchFlags)0, &minfo)) {
|
||||||
auto address = (char*)g_match_info_fetch(minfo, 1);
|
auto address = (char*)g_match_info_fetch(minfo, 1);
|
||||||
MuMsgContact contact{NULL, address};
|
MuMsgContact contact{NULL, address, {}, {}};
|
||||||
list.add_prop(":list-post", Sexp::make_list(make_contact_sexp(&contact)));
|
list.add_prop(":list-post", Sexp::make_list(make_contact_sexp(&contact)));
|
||||||
g_free(address);
|
g_free(address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ process_value(const std::string& field, const std::string& value)
|
||||||
|
|
||||||
case MU_MSG_FIELD_ID_FLAGS:
|
case MU_MSG_FIELD_ID_FLAGS:
|
||||||
if (const auto info{message_flag_info(value)}; info)
|
if (const auto info{message_flag_info(value)}; info)
|
||||||
return std::string(1, ::tolower(info->shortcut));
|
return std::string(1, info->shortcut_lower());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -55,7 +55,6 @@ constexpr auto RootMaildirKey = "maildir"; // XXX: make this 'root-maildir
|
||||||
constexpr auto ContactsKey = "contacts";
|
constexpr auto ContactsKey = "contacts";
|
||||||
constexpr auto PersonalAddressesKey = "personal-addresses";
|
constexpr auto PersonalAddressesKey = "personal-addresses";
|
||||||
constexpr auto CreatedKey = "created";
|
constexpr auto CreatedKey = "created";
|
||||||
constexpr auto LastIndexKey = "last-index"; /* time of last index */
|
|
||||||
constexpr auto BatchSizeKey = "batch-size";
|
constexpr auto BatchSizeKey = "batch-size";
|
||||||
constexpr auto DefaultBatchSize = 250'000U;
|
constexpr auto DefaultBatchSize = 250'000U;
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ constexpr auto ExpectedSchemaVersion = MU_STORE_SCHEMA_VERSION;
|
||||||
*
|
*
|
||||||
* @return the hash
|
* @return the hash
|
||||||
*/
|
*/
|
||||||
size_t get_hash64 (const char* str)
|
uint64_t get_hash64 (const char* str)
|
||||||
{
|
{
|
||||||
guint32 djbhash;
|
guint32 djbhash;
|
||||||
guint32 bkdrhash;
|
guint32 bkdrhash;
|
||||||
|
|
|
@ -196,7 +196,7 @@ test_mu_maildir_flags_from_path(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
[[maybe_unused]] static void
|
||||||
assert_matches_regexp(const char* str, const char* rx)
|
assert_matches_regexp(const char* str, const char* rx)
|
||||||
{
|
{
|
||||||
if (!g_regex_match_simple(rx, str, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) {
|
if (!g_regex_match_simple(rx, str, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ using namespace Mu;
|
||||||
struct Case {
|
struct Case {
|
||||||
const std::string expr;
|
const std::string expr;
|
||||||
const std::string expected;
|
const std::string expected;
|
||||||
WarningVec warnings;
|
WarningVec warnings{};
|
||||||
};
|
};
|
||||||
|
|
||||||
using CaseVec = std::vector<Case>;
|
using CaseVec = std::vector<Case>;
|
||||||
|
|
|
@ -162,6 +162,16 @@ Command::get_int(const Parameters& params, const std::string& argname)
|
||||||
return ::atoi(it->value().c_str());
|
return ::atoi(it->value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<unsigned>
|
||||||
|
Command::get_unsigned(const Parameters& params, const std::string& argname)
|
||||||
|
{
|
||||||
|
if (auto val = get_int(params, argname); val && *val >= 0)
|
||||||
|
return val;
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<bool>
|
std::optional<bool>
|
||||||
Command::get_bool(const Parameters& params, const std::string& argname)
|
Command::get_bool(const Parameters& params, const std::string& argname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,6 +63,7 @@ using ArgMap = std::unordered_map<std::string, ArgInfo>;
|
||||||
using Parameters = Sexp::Seq;
|
using Parameters = Sexp::Seq;
|
||||||
|
|
||||||
std::optional<int> get_int(const Parameters& parms, const std::string& argname);
|
std::optional<int> get_int(const Parameters& parms, const std::string& argname);
|
||||||
|
std::optional<unsigned> get_unsigned(const Parameters& parms, const std::string& argname);
|
||||||
std::optional<bool> get_bool(const Parameters& parms, const std::string& argname);
|
std::optional<bool> get_bool(const Parameters& parms, const std::string& argname);
|
||||||
std::optional<std::string> get_string(const Parameters& parms, const std::string& argname);
|
std::optional<std::string> get_string(const Parameters& parms, const std::string& argname);
|
||||||
std::optional<std::string> get_symbol(const Parameters& parms, const std::string& argname);
|
std::optional<std::string> get_symbol(const Parameters& parms, const std::string& argname);
|
||||||
|
@ -76,6 +77,7 @@ static inline int
|
||||||
get_int_or(const Parameters& parms, const std::string& arg, int alt = 0) {
|
get_int_or(const Parameters& parms, const std::string& arg, int alt = 0) {
|
||||||
return get_int(parms, arg).value_or(alt);
|
return get_int(parms, arg).value_or(alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
get_bool_or(const Parameters& parms, const std::string& arg, bool alt = false) {
|
get_bool_or(const Parameters& parms, const std::string& arg, bool alt = false) {
|
||||||
return get_bool(parms, arg).value_or(alt);
|
return get_bool(parms, arg).value_or(alt);
|
||||||
|
|
|
@ -103,7 +103,7 @@ struct Error final : public std::exception {
|
||||||
* DTOR
|
* DTOR
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
virtual ~Error() = default;
|
virtual ~Error() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the descriptiove message.
|
* Get the descriptiove message.
|
||||||
|
|
|
@ -38,7 +38,9 @@ template <typename T> using Result = tl::expected<T, Error>;
|
||||||
* @return a success Result<T>
|
* @return a success Result<T>
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename Result<T>::expected
|
class Result<T>::expected
|
||||||
|
// note: "class", not "typename";
|
||||||
|
// https://stackoverflow.com/questions/46412754/class-name-injection-and-constructors
|
||||||
Ok(T&& t)
|
Ok(T&& t)
|
||||||
{
|
{
|
||||||
return std::move(t);
|
return std::move(t);
|
||||||
|
|
|
@ -296,7 +296,7 @@ struct Sexp {
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return is_prop_list(list().begin() + 1, list().end());
|
return is_prop_list(list().begin() + 1, list().end());
|
||||||
};
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Sexp(Type typearg, std::string&& valuearg) : type_{typearg}, value_{std::move(valuearg)}
|
Sexp(Type typearg, std::string&& valuearg) : type_{typearg}, value_{std::move(valuearg)}
|
||||||
|
|
|
@ -401,8 +401,8 @@ mu_util_get_hash (const char* str)
|
||||||
bkdrseed = 1313;
|
bkdrseed = 1313;
|
||||||
|
|
||||||
for(unsigned u = 0U; str[u]; ++u) {
|
for(unsigned u = 0U; str[u]; ++u) {
|
||||||
djbhash = ((djbhash << 5) + djbhash) + str[u];
|
djbhash = ((djbhash << 5) + djbhash) + (unsigned)str[u];
|
||||||
bkdrhash = bkdrhash * bkdrseed + str[u];
|
bkdrhash = bkdrhash * bkdrseed + (unsigned)str[u];
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = djbhash;
|
hash = djbhash;
|
||||||
|
|
|
@ -191,13 +191,13 @@ struct StopWatch {
|
||||||
StopWatch(const std::string name) : start_{Clock::now()}, name_{name} {}
|
StopWatch(const std::string name) : start_{Clock::now()}, name_{name} {}
|
||||||
~StopWatch()
|
~StopWatch()
|
||||||
{
|
{
|
||||||
const auto us{to_us(Clock::now() - start_)};
|
const auto us{static_cast<double>(to_us(Clock::now() - start_))};
|
||||||
if (us > 2000000)
|
if (us > 2000000)
|
||||||
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000.0);
|
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000);
|
||||||
else if (us > 2000)
|
else if (us > 2000)
|
||||||
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000.0);
|
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000);
|
||||||
else
|
else
|
||||||
g_debug("%s: finished after %" G_GINT64_FORMAT " us", name_.c_str(), us);
|
g_debug("%s: finished after %g us", name_.c_str(), us);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -304,8 +304,8 @@ private:
|
||||||
constexpr ET operator~(ET e) { return MU_TO_ENUM(ET, ~(MU_TO_NUM(ET, e))); } \
|
constexpr ET operator~(ET e) { return MU_TO_ENUM(ET, ~(MU_TO_NUM(ET, e))); } \
|
||||||
constexpr bool any_of(ET e) { return MU_TO_NUM(ET, e) != 0; } \
|
constexpr bool any_of(ET e) { return MU_TO_NUM(ET, e) != 0; } \
|
||||||
constexpr bool none_of(ET e) { return MU_TO_NUM(ET, e) == 0; } \
|
constexpr bool none_of(ET e) { return MU_TO_NUM(ET, e) == 0; } \
|
||||||
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
|
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
|
||||||
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; }
|
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; } \
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For unit tests, assert two std::string's are equal.
|
* For unit tests, assert two std::string's are equal.
|
||||||
|
|
|
@ -51,8 +51,8 @@ struct OutputInfo {
|
||||||
Option<QueryMatch&> match_info;
|
Option<QueryMatch&> match_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto FirstOutput{OutputInfo{0, true, false}};
|
constexpr auto FirstOutput{OutputInfo{0, true, false, {}, {}}};
|
||||||
constexpr auto LastOutput{OutputInfo{0, false, true}};
|
constexpr auto LastOutput{OutputInfo{0, false, true, {}, {}}};
|
||||||
|
|
||||||
using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*, GError**)>;
|
using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*, GError**)>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue