Fix parse_log.py Python 2 print statement breaking Python 3#7103
Open
Chessing234 wants to merge 2 commits intoBVLC:masterfrom
Open
Fix parse_log.py Python 2 print statement breaking Python 3#7103Chessing234 wants to merge 2 commits intoBVLC:masterfrom
Chessing234 wants to merge 2 commits intoBVLC:masterfrom
Conversation
Blob::offset(n, c, h, w) guards the inputs with CHECK_LE(n, num()), CHECK_LE(c, channels()), CHECK_LE(h, height()), CHECK_LE(w, width()). A valid index is in [0, dim), so these allow n == num(), c == channels() etc. to pass — one past the end of the buffer, producing a stale/OOB linear offset from `((n * channels() + c) * height() + h) * width() + w`. The vector overload of offset() already uses the correct pattern (CHECK_LT(indices[i], shape(i))). Switch the four legacy-accessor checks to CHECK_LT to match. Fixes BVLC#6391.
tools/extra/parse_log.py is a shipped utility (shebang `#!/usr/bin/env
python`) that otherwise uses Python 3 compatible syntax — earlier in the
file it already calls `print('Not writing %s; no lines to write' % ...)`
using function-style print.
Line 175 is the odd one:
print 'Wrote %s' % output_filename
which is the Python 2 `print` statement. Running the script with
Python 3 fails at parse time with
"SyntaxError: Missing parentheses in call to 'print'" before any
parsing can take place, even though the rest of the file runs fine on
Python 3.
Wrap the expression in parentheses so the module imports and runs on
both Python 2.7 and Python 3.x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
`tools/extra/parse_log.py` is a ships-with-caffe utility with shebang `#!/usr/bin/env python`. The rest of the module is Python 3 compatible — the earlier `write_csv` branch even uses function-style `print('Not writing %s; no lines to write' % output_filename)`. But a single line later in the same function still uses the Python 2 `print` statement:
```python
if verbose:
print 'Wrote %s' % output_filename
```
Root cause
Running the script with Python 3 fails immediately with
at import/parse time, before any of the actual log-parsing logic can execute. The script is therefore unusable on Python 3 interpreters despite otherwise being compatible.
Fix
Wrap the format expression in parentheses so the line is valid under both Python 2.7 and Python 3.x, matching the function-style `print` already used elsewhere in the same file.