Skip to content

Commit

Permalink
Merge pull request #312 from MrAnno/fix-no-version-inconsistency
Browse files Browse the repository at this point in the history
cfg: fix config-version incosistencies
  • Loading branch information
OverOrion authored Sep 30, 2024
2 parents d53d84f + 0872f5c commit f0b42de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/cfg-lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cfg-lexer-subst.h"
#include "cfg-block-generator.h"
#include "cfg-grammar.h"
#include "cfg.h"
#include "block-ref-parser.h"
#include "pragma-parser.h"
#include "messages.h"
Expand Down Expand Up @@ -1165,6 +1166,15 @@ cfg_lexer_preprocess(CfgLexer *self, gint tok, CFG_STYPE *yylval, CFG_LTYPE *yyl

return CLPR_LEX_AGAIN;
}
else if (cfg_lexer_get_context_type(self) != LL_CONTEXT_PRAGMA && !self->first_non_pragma_seen)
{
/* Config version must be set before the first non-pragma element to avoid
* version-specific inconsistencies (e.g. template functions). */
if (cfg_get_user_version(self->cfg) == 0)
cfg_set_current_version(self->cfg);

self->first_non_pragma_seen = TRUE;
}

return CLPR_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cfg-lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct _CfgLexer
GString *token_pretext;
GString *token_text;
GlobalConfig *cfg;
guint ignore_pragma:1;
guint first_non_pragma_seen:1, ignore_pragma:1;
};

/* pattern buffer */
Expand Down
10 changes: 5 additions & 5 deletions lib/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ cfg_set_version(GlobalConfig *self, gint version)
{
if (self->user_version != 0)
{
msg_warning("WARNING: you have multiple @version directives in your configuration, only the first one is considered",
msg_warning("WARNING: The @version directive must be placed at the top of the main configuration file "
"(preferably as the very first line), preceding any @include directives and other configuration "
"elements, otherwise, the current version will be used. If you specify multiple @version directives "
"in your configuration, only the first one will be considered",
cfg_format_config_version_tag(self),
cfg_format_version_tag("new-version", version));
cfg_format_version_tag("ignored-version", version));
return TRUE;
}
cfg_set_version_without_validation(self, version);
Expand Down Expand Up @@ -662,9 +665,6 @@ cfg_read_config(GlobalConfig *self, const gchar *fname, gchar *preprocess_into)
cfg_dump_processed_config(self->preprocess_config, preprocess_into);
}

if (self->user_version == 0)
cfg_set_current_version(self);

if (res)
{
/* successfully parsed */
Expand Down
2 changes: 2 additions & 0 deletions news/bugfix-312.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config `@version`: fixed compat-mode inconsistencies when `@version` was not specified at the top of the configuration
file or was not specified at all

0 comments on commit f0b42de

Please sign in to comment.