Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1063)

#18960: First line can be executed twice

Can't Edit
Can't Publish+Mail
Start Review
Created:
5 years, 9 months ago by storchaka+cpython
Modified:
5 years, 9 months ago
Reviewers:
benjamin, bp+pybugs
CC:
lemburg, loewis, terry.reedy, Benjamin Peterson, ezio.melotti, Arfrever, devnull_psf.upfronthosting.co.za, storchaka
Visibility:
Public.

Patch Set 1 #

Total comments: 4

Patch Set 2 #

Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Lib/idlelib/IOBinding.py View 1 2 chunks +3 lines, -0 lines 0 comments Download
Lib/lib2to3/pgen2/tokenize.py View 1 2 chunks +3 lines, -0 lines 0 comments Download
Lib/test/test_source_encoding.py View 1 2 chunks +46 lines, -1 line 0 comments Download
Lib/test/test_tokenize.py View 1 1 chunk +33 lines, -0 lines 0 comments Download
Lib/tokenize.py View 1 2 chunks +3 lines, -0 lines 0 comments Download
Parser/tokenizer.c View 1 3 chunks +22 lines, -4 lines 0 comments Download
Tools/scripts/findnocoding.py View 1 2 chunks +3 lines, -1 line 0 comments Download

Messages

Total messages: 3
Benjamin Peterson
It's silly how many copies of tokenize we have.... https://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c File Parser/tokenizer.c (right): https://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c#newcode296 Parser/tokenizer.c:296: ...
5 years, 9 months ago #1
storchaka_gmail.com
http://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c File Parser/tokenizer.c (right): http://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c#newcode296 Parser/tokenizer.c:296: if (i >= size || s[i] == '#' || ...
5 years, 9 months ago #2
bp+pybugs_benjamin-peterson.org
5 years, 9 months ago #3
On 2014/01/04 09:20:49, storchaka wrote:
> http://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c
> File Parser/tokenizer.c (right):
> 
> http://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c#newcode296
> Parser/tokenizer.c:296: if (i >= size || s[i] == '#' || s[i] == '\n' || s[i]
==
> '\r') {
> On 2014/01/03 23:16:55, Benjamin Peterson wrote:
> > I think the rest of these conditions would be better expressed with a switch
> > statement.
> 
> It is not easy to break a loop from a switch statement. Resulting code looks
too
> complicated.
> 
>         for (i = 0; i < size; i++) {
>             switch (line[i]) {
>                 case '#':
>                 case '\r':
>                 case '\n':
>                     break;
>                 case ' ':
>                 case '\t':
>                 case '\014':
>                     continue;
>                 default:
>                     tok->read_coding_spec = 1;
>             }
>             break;
>         }

Since the only thing after the loop is a return statement, you could just
return.

> 
> http://bugs.python.org/review/18960/diff/10449/Parser/tokenizer.c#newcode499
> Parser/tokenizer.c:499: if (pos == -1 || lseek(fd, (off_t)pos, SEEK_SET) ==
> (off_t)-1) {
> On 2014/01/03 23:16:55, Benjamin Peterson wrote:
> > Does this do anything?
> 
> Due to buffering in FILE the offset of low-level OS file (accessed via file
> number) is different from the offset of high-level C file.
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+