Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cousteaulecommandant
Copy link
Contributor

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).

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':
Copy link
Member

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants