From 7cbfa4711033e7f0d6b730a2ad22fd1caa84beea Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 29 Sep 2017 13:56:20 +0200 Subject: Fix undef. assign warning in set_user_value() Previously we'd crash instead of printing the warning, because we didn't pass 'filename' and 'linenr' to _stderr_msg(). This code path currently can't be reached via load_config() and needs an explicit set_user_value(), so the bug went undetected. Fix by breaking out a separate _warn_undef_assign() that defaults 'filename' and 'linenr' to None, similar to _warn(). --- kconfiglib.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 274f0fd..ffb3ce6 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -486,11 +486,10 @@ class Config(object): sym._set_user_value_no_invalidate(val, True) else: - if self._print_undef_assign: - _stderr_msg('note: attempt to assign the value "{}" ' - "to the undefined symbol {}." - .format(val, name), - line_feeder.filename, line_feeder.linenr) + self._warn_undef_assign( + 'attempt to assign the value "{}" to the undefined ' + "symbol {}".format(val, name), + line_feeder.filename, line_feeder.linenr) else: unset_match = unset_re_match(line) if unset_match: @@ -1909,10 +1908,17 @@ class Config(object): "Locations: " + locations_str) def _warn(self, msg, filename=None, linenr=None): - """For printing warnings to stderr.""" + """For printing general warnings.""" if self._print_warnings: _stderr_msg("warning: " + msg, filename, linenr) + def _warn_undef_assign(self, msg, filename=None, linenr=None): + """For printing warnings for assignments to undefined variables. We + treat this is a separate category of warnings to avoid spamming lots of + warnings.""" + if self._print_undef_assign: + _stderr_msg("warning: " + msg, filename, linenr) + class Item(object): """Base class for symbols and other Kconfig constructs. Subclasses are @@ -2568,11 +2574,10 @@ class Symbol(Item): if not self._is_defined: filename, linenr = self._ref_locations[0] - if self._config._print_undef_assign: - _stderr_msg('note: attempt to assign the value "{}" to {}, ' - "which is referenced at {}:{} but never defined. " - "Assignment ignored." - .format(v, self._name, filename, linenr)) + self._config._warn_undef_assign( + 'attempt to assign the value "{}" to {}, which is referenced ' + "at {}:{} but never defined. Assignment ignored." + .format(v, self._name, filename, linenr)) return # Check if the value is valid for our type -- cgit v1.2.3