[config] fix static init ordering issue

pull/1179/head
Tim Stack 10 months ago
parent 3ae3515f44
commit 7dfecc556f

@ -202,6 +202,12 @@ struct string_fragment {
return memcmp(this->data(), sf.data(), sf.length()) == 0;
}
int operator<(const string_fragment& rhs) const
{
return strncmp(
this->data(), rhs.data(), std::min(this->length(), rhs.length()));
}
bool iequal(const string_fragment& sf) const
{
if (this->length() != sf.length()) {

@ -1430,6 +1430,8 @@ const json_path_container lnav_config_handlers = json_path_container {
class active_key_map_listener : public lnav_config_listener {
public:
active_key_map_listener() : lnav_config_listener(__FILE__) {}
void reload_config(error_reporter& reporter) override
{
lnav_config.lc_active_keymap = lnav_config.lc_ui_keymaps["default"];

@ -42,10 +42,17 @@ public:
using error_reporter = const std::function<void(
const void*, const lnav::console::user_message& msg)>;
lnav_config_listener()
template<typename T, std::size_t N>
lnav_config_listener(const T (&src_file)[N])
: lcl_name(string_fragment::from_const(src_file))
{
this->lcl_next = LISTENER_LIST;
LISTENER_LIST = this;
auto** curr = &LISTENER_LIST;
while (*curr != nullptr && (*curr)->lcl_name < this->lcl_name) {
curr = &(*curr)->lcl_next;
}
this->lcl_next = *curr;
*curr = this;
}
virtual ~lnav_config_listener() = default;
@ -54,7 +61,8 @@ public:
virtual void unload_config() {}
static void unload_all() {
static void unload_all()
{
auto* lcl = LISTENER_LIST;
while (lcl != nullptr) {
lcl->unload_config();
@ -65,6 +73,7 @@ public:
static lnav_config_listener* LISTENER_LIST;
lnav_config_listener* lcl_next;
string_fragment lcl_name;
};
#endif

@ -52,6 +52,8 @@ struct compiled_cond_expr {
};
struct expressions : public lnav_config_listener {
expressions() : lnav_config_listener(__FILE__) {}
void reload_config(error_reporter& reporter) override
{
auto& lnav_db = injector::get<auto_sqlite3&>();

@ -50,6 +50,8 @@ struct compiled_watch_expr {
};
struct expressions : public lnav_config_listener {
expressions() : lnav_config_listener(__FILE__) {}
void reload_config(error_reporter& reporter) override
{
auto& lnav_db = injector::get<auto_sqlite3&>();
@ -98,9 +100,7 @@ struct expressions : public lnav_config_listener {
}
}
void unload_config() override {
this->e_watch_exprs.clear();
}
void unload_config() override { this->e_watch_exprs.clear(); }
std::map<std::string, compiled_watch_expr> e_watch_exprs;
};

@ -1845,6 +1845,8 @@ struct compiled_header_expr {
};
struct format_header_expressions : public lnav_config_listener {
format_header_expressions() : lnav_config_listener(__FILE__) {}
auto_sqlite3 e_db;
std::map<intern_string_t, std::map<std::string, compiled_header_expr>>
e_header_exprs;

@ -182,7 +182,8 @@ const bookmark_type_t textview_curses::BM_USER_EXPR("user-expr");
const bookmark_type_t textview_curses::BM_SEARCH("search");
const bookmark_type_t textview_curses::BM_META("meta");
textview_curses::textview_curses() : tc_search_action(noop_func{})
textview_curses::textview_curses()
: lnav_config_listener(__FILE__), tc_search_action(noop_func{})
{
this->set_data_source(this);
}

@ -498,6 +498,8 @@ static std::string COLOR_NAMES[] = {
class color_listener : public lnav_config_listener {
public:
color_listener() : lnav_config_listener(__FILE__) {}
void reload_config(error_reporter& reporter) override
{
if (!view_colors::initialized) {

@ -55,6 +55,18 @@
✘ error: invalid JSON
reason: parse error: premature EOF
 --> {test_dir}/bad-config2/formats/invalid-config/config.truncated.json:3
✘ error: invalid value for property “/ui/theme-defs/invalid-theme/styles/text/color”
reason: invalid color -- “InvalidColor”
 |  reason: Unknown color: 'InvalidColor'. See https://jonasjacek.github.io/colors/ for a list of supported color names
 --> {test_dir}/bad-config2/configs/invalid-theme/config.json:8
 = help: Property Synopsis
/ui/theme-defs/invalid-theme/styles/text/color #hex|color_name
Description
The foreground color value for this style. The value can be the name of an xterm color, the hexadecimal value, or a theme variable reference.
Examples
#fff
Green
$black
✘ error: missing value for property “/log/annotations/org.lnav.test.no-condition/condition”
reason: SQL expression is invalid
 |  reason: incomplete input
@ -70,15 +82,3 @@
/log/annotations/org.lnav.test.no-handler/handler <script>
Description
The script to execute to generate the annotation content. A JSON object with the log message content will be sent to the script on the standard input
✘ error: invalid value for property “/ui/theme-defs/invalid-theme/styles/text/color”
reason: invalid color -- “InvalidColor”
 |  reason: Unknown color: 'InvalidColor'. See https://jonasjacek.github.io/colors/ for a list of supported color names
 --> {test_dir}/bad-config2/configs/invalid-theme/config.json:8
 = help: Property Synopsis
/ui/theme-defs/invalid-theme/styles/text/color #hex|color_name
Description
The foreground color value for this style. The value can be the name of an xterm color, the hexadecimal value, or a theme variable reference.
Examples
#fff
Green
$black

Loading…
Cancel
Save