Bug #1687: ARGF.lineno Always Returns 0 for ARGF.chars and ARGF.bytes
http://redmine.ruby-lang.org/issues/show/1687
Author: Run Paint Run Run
Status: Open, Priority: Normal
Category: core
ruby -v: ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux]
The ARGF.chars and ARGF.bytes iterators (along with their aliases) don't
set ARGF.lineno. It always returns 0, irrespective of the actual line
number. While the case could be made that line numbers don't make much
sense when dealing with bytes, they certainly do for characters.
1.8 HEAD appears to return the number of the file descriptor instead...
$ ruby -v
ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux]
ARGF.chars { print ARGF.lineno } #=> 0000..000
$ ruby8 -v
ruby 1.8.8dev (2009-06-17) [i686-linux]
ARGF.bytes { print ARGF.lineno } #=> 333....333
on 2009-06-25 04:20
on 2009-06-25 07:23
Hi, At Thu, 25 Jun 2009 11:19:55 +0900, Run Paint Run Run wrote in [ruby-core:24024]: > The ARGF.chars and ARGF.bytes iterators (along with their > aliases) don't set ARGF.lineno. It always returns 0, > irrespective of the actual line number. While the case could > be made that line numbers don't make much sense when dealing > with bytes, they certainly do for characters. It's actually "gets'ed count". > ARGF.bytes { print ARGF.lineno } #=> 333....333 What do you mean? Seems like both work properly. $ echo -e 'aaaa\nbbb' |./ruby -ve 'gets; ARGF.chars{print ARGF.lineno};puts' ruby 1.8.8dev (2009-06-23 ruby_1_8 23825) [i686-linux] 1111 $ echo -e 'aaaa\nbbb' |./ruby -ve 'ARGF.chars{print ARGF.lineno};puts' ruby 1.8.8dev (2009-06-23 ruby_1_8 23825) [i686-linux] 000000000 $ echo -e 'aaaa\nbbb' |./ruby -ve 'gets; ARGF.chars{print ARGF.lineno};puts' ruby 1.9.2dev (2009-06-25 trunk 23851) [i686-linux] 1111 $ echo -e 'aaaa\nbbb' |./ruby -ve 'ARGF.chars{print ARGF.lineno};puts' ruby 1.9.2dev (2009-06-25 trunk 23851) [i686-linux] 000000000
on 2009-06-25 07:54
Issue #1687 has been updated by Run Paint Run Run.
Nobu, thanks for looking.
Using the .lines iterator, ARGF.lineno returns the correct line number:
$ cat argf.rb
ARGF.lines { |l| p ARGF.lineno }
$ echo -e "foo\nbar\nglark" >file
$ ruby argf.rb file
1
2
3
Using the .chars iterator, it always returns 0:
$ cat argf.rb
ARGF.chars { |c| p ARGF.lineno }
$ ruby argf.rb file
0
0
...
0
0
Using .bytes has the same result:
$ cat argf.rb
ARGF.bytes { |b| p ARGF.lineno }
$ ruby argf.rb file
0
0
...
0
0
On 1.8, the last two examples always print 1.
Am I missing something obvious here? :-)
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1687
on 2009-06-25 08:57
Issue #1687 has been updated by Nobuyoshi Nakada. Status changed from Open to Closed % Done changed from 0 to 100 Applied in changeset r23852. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1687
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.