-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #548: use ==
instead of in
for string comparison in Python/.tpl
#551
base: develop
Are you sure you want to change the base?
Fix #548: use ==
instead of in
for string comparison in Python/.tpl
#551
Conversation
The use of `in` for string comparison results in `"name" in "name2"` giving a false positive; the right thing is to use `==`. In peripheral_subsystem.sv.tpl, this may result in the peripheral being added twice, or being added when it shouldn't. This has been fixed in this commit. In addition, the way in which dict keys are handled has been changed from iterating through all the keys to just finding the relevant key.
This is the same issue that was found at bug esl-epfl#548, although in this case it has not shown any adverse effects *for now*. Nevertheless, it is never a bad idea to fix it as well just in case. Also fixed file `pad_cfg.hjson` which incorrectly adds a comma after quoteless string `active: low,` which isn't valid Hjson. This worked before because `"low" in "low,"` is technically true, but this was just one bug hiding another bug. This issue affects several other files and will be reported separately.
@@ -219,7 +219,7 @@ def __init__(self, name, cell_name, pad_type, pad_mapping, index, pad_active, pa | |||
self.pad_mapping = pad_mapping | |||
self.pad_mux_list = pad_mux_list | |||
|
|||
if('low' in pad_active): | |||
if pad_active == 'low': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if there are commas ,
in the hjson file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't. Not in a valid Hjson file at least.
https://hjson.github.io/syntax.html
Do not add commas or comments as they would become part of the string.
Note that I fixed the affected Hjson file in this commit, so that should not be an issue in this particular case.
(But feel free to ditch the second commit of the PR and pull only the first one if you're not sure about that yet.)
Also see issue #552 which I created just now, immediately after submitting this PR, as I realized about that issue while dealing with this one.
For some reason this PR didn't trigger the CI. Do you have any ideas why @cousteaulecommandant? I see we also left this one slide and it's related to #638 |
Not really, I don't know why. I'll see if I have time to rebase the PR and see if that triggers the CI, although maybe it's wiser to wait for #638 to be merged to avoid/solve any possible merge conflict. |
Sounds like a plan, let's wait for the other PR to be merged then and rebase to see if it triggers the CI |
The use of
in
for string comparison results in"name" in "name2"
giving a false positive; the right thing is to use==
.In peripheral_subsystem.sv.tpl, this may result in the peripheral being added twice, or being added when it shouldn't. This was reported in #548, and has been fixed in this PR.
This misuse of
in
also occurs in mcu_gen.py and has been fixed as well.In addition, this PR also changes the way in which dict keys are handled, from iterating through all the keys to just finding the relevant key, which is more readable (and efficient).