Project

General

Profile

This project is closed and read-only.

Actions

Bug #400

closed

Possible bug in IO#ungetc

Bug #400: Possible bug in IO#ungetc

Added by Anonymous about 18 years ago. Updated over 15 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
[ruby-core:18092]

Description

=begin
According to the documentation for IO#ungetc:

bq.
"Only one character may be pushed back before a subsequent
read operation (that is, you will be able to read only the
last of several characters that have been pushed back)."

But that doesn't seem to be the case:

file.txt
Voici la ligne une.
Qui è la linea due.
Aquí está la línea tres.
Ist hier Linie vier.
Está aqui a linha cinco.
Here is line six.

Rubyspec:

 @file = File.open("file.txt", "r")
 @file.getc
 10.times { @file.ungetc(90) }
 @file.ungetc(80)
 @file.read(1).should == "P"
 @file.readline.should == "oici la ligne une.\n"

 #=> IO#ungetc pushing back only one character FAILED
     Expected "ZZZZZZZZZZoici la ligne une.\n"
     to equal "oici la ligne une.\n"

Are we misunderstanding the documentation and this works as expected or is it a bug indeed?
=end

Updated by shyouhei (Shyouhei Urabe) about 18 years ago Actions #1

=begin
That depends. As C standard only guarantees one ungetc at a time, multiple ungetc may or may not be doable, depending on your (underlying) libc's stdio implementation. It is nicer for programmers not to do multiple ungetc to earn maximum portability, so saying no in documents is basically a good thing I think.
=end

Updated by nobu (Nobuyoshi Nakada) about 18 years ago Actions #2

=begin
Hi,

At Sun, 3 Aug 2008 10:13:57 +0900,
Anonymous wrote in [ruby-core:18092]:

According to the documentation for IO#ungetc:

bq.
"Only one character may be pushed back before a subsequent
read operation (that is, you will be able to read only the
last of several characters that have been pushed back)."

But that doesn't seem to be the case:

It depends on the behavior of underlying stdio. The doc should
be:

"Only one character is guaranteed ...

--
Nobu Nakada

=end

Updated by febuiles (Federico Builes) about 18 years ago Actions #3

=begin
Thanks for your input, I'll modify the specs to reflect this behavior then.
=end

Updated by nobu (Nobuyoshi Nakada) about 18 years ago Actions #4

  • Status changed from Open to Closed

=begin

=end

Actions

Also available in: PDF Atom