summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-09-29 13:56:20 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2017-09-29 14:48:54 +0200
commit7cbfa4711033e7f0d6b730a2ad22fd1caa84beea (patch)
tree1e39fa9543b6c4a0a29043cf3059739638129af4
parent5fea36ffd71d8f908133d091860ef4b139cc7e81 (diff)
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().
-rw-r--r--kconfiglib.py27
1 files changed, 16 insertions, 11 deletions
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