Project

General

Profile

Feature #6670 » 0001-Deprecate-lines-bytes-chars-codepoints-of-IO-likes.patch

knu (Akinori MUSHA), 11/27/2012 11:56 PM

View differences:

ChangeLog
Tue Nov 27 23:45:47 2012 Akinori MUSHA <knu@iDaemons.org>
* io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints):
Deprecate IO#{lines,bytes,chars,codepoints} and those of ARGF.
[Feature #6670]
* ext/stringio/stringio.c (strio_lines, strio_bytes, strio_chars)
(strio_codepoints): Deprecate
StringIO#{lines,bytes,chars,codepoints}. [Feature #6670]
* ext/zlib/zlib.c (rb_gzreader_lines, rb_gzreader_bytes):
Deprecate Zlib::GzipReader#{lines,bytes}. [Feature #6670]
Tue Nov 27 22:03:09 2012 Akinori MUSHA <knu@iDaemons.org>
* string.c (rb_str_enumerate_chars, rb_str_enumerate_codepoints)
NEWS
* extended method:
* Hash#default_proc= can be passed nil to clear the default proc.
* IO
* deprecated methods:
* IO#lines, #bytes, #chars and #codepoints are deprecated.
* Kernel
* added method:
* added Kernel#Hash conversion method like Array() or Float().
......
* Shellwords#shelljoin() accepts non-string objects in the given
array, each of which is stringified using to_s.
* stringio
* deprecated methods:
* StringIO#lines, #bytes, #chars and #codepoints are deprecated.
* syslog
* Added Syslog::Logger which provides a Logger API atop Syslog.
* Syslog::Priority, Syslog::Level, Syslog::Option and Syslog::Macros
......
* Added support for the new deflate strategies Zlib::RLE and Zlib::FIXED.
* Zlib streams are now processed without the GVL. This allows gzip, zlib and
deflate streams to be processed in parallel.
* deprecated methods:
* Zlib::GzipReader#lines and #bytes are deprecated.
=== Language changes
......
works because str.lines returns an array. Replace lines with
each_line in such cases.
* IO#lines
* IO#chars
* IO#codepoints
* IO#bytes
* ARGF#lines
* ARGF#chars
* ARGF#codepoints
* ARGF#bytes
* StringIO#lines
* StringIO#chars
* StringIO#codepoints
* StringIO#bytes
* Zlib::GzipReader#lines
* Zlib::GzipReader#bytes
These methods are deprecated in favor of each_line, each_byte,
each_char and each_codepoint.
* Signal.trap
See above.
ext/stringio/stringio.c
/*
* call-seq:
* strio.bytes {|byte| block } -> strio
* strio.bytes -> anEnumerator
*
* strio.each_byte {|byte| block } -> strio
* strio.each_byte -> anEnumerator
*
......
}
/*
* This is a deprecated alias for <code>each_byte</code>.
*/
static VALUE
strio_bytes(VALUE self)
{
rb_warn("StringIO#bytes is deprecated; use #each_byte instead");
if (!rb_block_given_p())
return rb_enumeratorize(self, ID2SYM(rb_intern("each_byte")), 0, 0);
return strio_each_byte(self);
}
/*
* call-seq:
* strio.getc -> string or nil
*
......
/*
* call-seq:
* strio.chars {|char| block } -> strio
* strio.chars -> anEnumerator
*
* strio.each_char {|char| block } -> strio
* strio.each_char -> anEnumerator
*
......
}
/*
* This is a deprecated alias for <code>each_char</code>.
*/
static VALUE
strio_chars(VALUE self)
{
rb_warn("StringIO#chars is deprecated; use #each_char instead");
if (!rb_block_given_p())
return rb_enumeratorize(self, ID2SYM(rb_intern("each_char")), 0, 0);
return strio_each_char(self);
}
/*
* call-seq:
* strio.codepoints {|c| block } -> strio
* strio.codepoints -> anEnumerator
*
* strio.each_codepoint {|c| block } -> strio
* strio.each_codepoint -> anEnumerator
*
......
return self;
}
/*
* This is a deprecated alias for <code>each_codepoint</code>.
*/
static VALUE
strio_codepoints(VALUE self)
{
rb_warn("StringIO#codepoints is deprecated; use #each_codepoint instead");
if (!rb_block_given_p())
return rb_enumeratorize(self, ID2SYM(rb_intern("each_codepoint")), 0, 0);
return strio_each_codepoint(self);
}
/* Boyer-Moore search: copied from regex.c */
static void
bm_init_skip(long *skip, const char *pat, long m)
......
* strio.each_line(sep,limit) {|line| block } -> strio
* strio.each_line(...) -> anEnumerator
*
* strio.lines(sep=$/) {|line| block } -> strio
* strio.lines(limit) {|line| block } -> strio
* strio.lines(sep,limit) {|line| block } -> strio
* strio.lines(...) -> anEnumerator
*
* See IO#each.
*/
static VALUE
......
}
/*
* This is a deprecated alias for <code>each_line</code>.
*/
static VALUE
strio_lines(int argc, VALUE *argv, VALUE self)
{
rb_warn("StringIO#lines is deprecated; use #each_line instead");
if (!rb_block_given_p())
return rb_enumeratorize(self, ID2SYM(rb_intern("each_line")), argc, argv);
return strio_each(argc, argv, self);
}
/*
* call-seq:
* strio.readlines(sep=$/) -> array
* strio.readlines(limit) -> array
......
rb_define_method(StringIO, "each", strio_each, -1);
rb_define_method(StringIO, "each_line", strio_each, -1);
rb_define_method(StringIO, "lines", strio_each, -1);
rb_define_method(StringIO, "lines", strio_lines, -1);
rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
rb_define_method(StringIO, "bytes", strio_each_byte, 0);
rb_define_method(StringIO, "bytes", strio_bytes, 0);
rb_define_method(StringIO, "each_char", strio_each_char, 0);
rb_define_method(StringIO, "chars", strio_each_char, 0);
rb_define_method(StringIO, "chars", strio_chars, 0);
rb_define_method(StringIO, "each_codepoint", strio_each_codepoint, 0);
rb_define_method(StringIO, "codepoints", strio_each_codepoint, 0);
rb_define_method(StringIO, "codepoints", strio_codepoints, 0);
rb_define_method(StringIO, "getc", strio_getc, 0);
rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1);
ext/zlib/zlib.c
}
/*
* Document-method: Zlib::GzipReader#bytes
*
* This is a deprecated alias for <code>each_byte</code>.
*/
static VALUE
rb_gzreader_bytes(VALUE obj)
{
rb_warn("Zlib::GzipReader#bytes is deprecated; use #each_byte instead");
if (!rb_block_given_p())
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_byte")), 0, 0);
return rb_gzreader_each_byte(obj);
}
/*
* Document-method: Zlib::GzipReader#ungetc
*
* See Zlib::GzipReader documentation for a description.
......
}
/*
* Document-method: Zlib::GzipReader#lines
*
* This is a deprecated alias for <code>each_line</code>.
*/
static VALUE
rb_gzreader_lines(int argc, VALUE *argv, VALUE obj)
{
rb_warn("Zlib::GzipReader#lines is deprecated; use #each_line instead");
if (!rb_block_given_p())
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_line")), argc, argv);
return rb_gzreader_each_line(argc, argv, obj);
}
/*
* Document-method: Zlib::GzipReader#readlines
*
* See Zlib::GzipReader documentation for a description.
......
rb_define_method(cGzipReader, "readbyte", rb_gzreader_readbyte, 0);
rb_define_method(cGzipReader, "each_byte", rb_gzreader_each_byte, 0);
rb_define_method(cGzipReader, "each_char", rb_gzreader_each_char, 0);
rb_define_method(cGzipReader, "bytes", rb_gzreader_each_byte, 0);
rb_define_method(cGzipReader, "bytes", rb_gzreader_bytes, 0);
rb_define_method(cGzipReader, "ungetc", rb_gzreader_ungetc, 1);
rb_define_method(cGzipReader, "ungetbyte", rb_gzreader_ungetbyte, 1);
rb_define_method(cGzipReader, "gets", rb_gzreader_gets, -1);
rb_define_method(cGzipReader, "readline", rb_gzreader_readline, -1);
rb_define_method(cGzipReader, "each", rb_gzreader_each, -1);
rb_define_method(cGzipReader, "each_line", rb_gzreader_each, -1);
rb_define_method(cGzipReader, "lines", rb_gzreader_each, -1);
rb_define_method(cGzipReader, "lines", rb_gzreader_lines, -1);
rb_define_method(cGzipReader, "readlines", rb_gzreader_readlines, -1);
/* The OS code of current host */
io.c
* ios.each_line(sep,limit) {|line| block } -> ios
* ios.each_line(...) -> an_enumerator
*
* ios.lines(sep=$/) {|line| block } -> ios
* ios.lines(limit) {|line| block } -> ios
* ios.lines(sep,limit) {|line| block } -> ios
* ios.lines(...) -> an_enumerator
*
* Executes the block for every line in <em>ios</em>, where lines are
* separated by <i>sep</i>. <em>ios</em> must be opened for
* reading or an <code>IOError</code> will be raised.
......
}
/*
* This is a deprecated alias for <code>each_line</code>.
*/
static VALUE
rb_io_lines(int argc, VALUE *argv, VALUE io)
{
rb_warn("IO#lines is deprecated; use #each_line instead");
if (!rb_block_given_p())
return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
return rb_io_each_line(argc, argv, io);
}
/*
* call-seq:
* ios.bytes {|byte| block } -> ios
* ios.bytes -> an_enumerator
*
* ios.each_byte {|byte| block } -> ios
* ios.each_byte -> an_enumerator
*
......
return io;
}
/*
* This is a deprecated alias for <code>each_byte</code>.
*/
static VALUE
rb_io_bytes(VALUE io)
{
rb_warn("IO#bytes is deprecated; use #each_byte instead");
if (!rb_block_given_p())
return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
return rb_io_each_byte(io);
}
static VALUE
io_getc(rb_io_t *fptr, rb_encoding *enc)
{
......
/*
* call-seq:
* ios.chars {|c| block } -> ios
* ios.chars -> an_enumerator
*
* ios.each_char {|c| block } -> ios
* ios.each_char -> an_enumerator
*
......
return io;
}
/*
* This is a deprecated alias for <code>each_char</code>.
*/
static VALUE
rb_io_chars(VALUE io)
{
rb_warn("IO#chars is deprecated; use #each_char instead");
if (!rb_block_given_p())
return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
return rb_io_each_char(io);
}
/*
* call-seq:
......
return io;
}
/*
* This is a deprecated alias for <code>each_codepoint</code>.
*/
static VALUE
rb_io_codepoints(VALUE io)
{
rb_warn("IO#codepoints is deprecated; use #each_codepoint instead");
if (!rb_block_given_p())
return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0);
return rb_io_each_codepoint(io);
}
/*
......
* ARGF.each_line(sep=$/,limit) {|line| block } -> ARGF
* ARGF.each_line(...) -> an_enumerator
*
* ARGF.lines(sep=$/) {|line| block } -> ARGF
* ARGF.lines(sep=$/,limit) {|line| block } -> ARGF
* ARGF.lines(...) -> an_enumerator
*
* Returns an enumerator which iterates over each line (separated by _sep_,
* which defaults to your platform's newline character) of each file in
* +ARGV+. If a block is supplied, each line in turn will be yielded to the
......
}
/*
* This is a deprecated alias for <code>each_line</code>.
*/
static VALUE
argf_lines(int argc, VALUE *argv, VALUE argf)
{
rb_warn("ARGF#lines is deprecated; use #each_line instead");
if (!rb_block_given_p())
return rb_enumeratorize(argf, ID2SYM(rb_intern("each_line")), argc, argv);
return argf_each_line(argc, argv, argf);
}
/*
* call-seq:
* ARGF.bytes {|byte| block } -> ARGF
* ARGF.bytes -> an_enumerator
......
}
/*
* This is a deprecated alias for <code>each_byte</code>.
*/
static VALUE
argf_bytes(VALUE argf)
{
rb_warn("ARGF#bytes is deprecated; use #each_byte instead");
if (!rb_block_given_p())
return rb_enumeratorize(argf, ID2SYM(rb_intern("each_byte")), 0, 0);
return argf_each_byte(argf);
}
/*
* call-seq:
* ARGF.chars {|char| block } -> ARGF
* ARGF.chars -> an_enumerator
*
* ARGF.each_char {|char| block } -> ARGF
* ARGF.each_char -> an_enumerator
*
......
}
/*
* This is a deprecated alias for <code>each_char</code>.
*/
static VALUE
argf_chars(VALUE argf)
{
rb_warn("ARGF#chars is deprecated; use #each_char instead");
if (!rb_block_given_p())
return rb_enumeratorize(argf, ID2SYM(rb_intern("each_char")), 0, 0);
return argf_each_char(argf);
}
/*
* call-seq:
* ARGF.codepoints {|codepoint| block } -> ARGF
* ARGF.codepoints -> an_enumerator
*
* ARGF.each_codepoint {|codepoint| block } -> ARGF
* ARGF.each_codepoint -> an_enumerator
*
......
}
/*
* This is a deprecated alias for <code>each_codepoint</code>.
*/
static VALUE
argf_codepoints(VALUE argf)
{
rb_warn("ARGF#codepoints is deprecated; use #each_codepoint instead");
if (!rb_block_given_p())
return rb_enumeratorize(argf, ID2SYM(rb_intern("each_codepoint")), 0, 0);
return argf_each_codepoint(argf);
}
/*
* call-seq:
* ARGF.filename -> String
* ARGF.path -> String
......
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0);
rb_define_method(rb_cIO, "each_codepoint", rb_io_each_codepoint, 0);
rb_define_method(rb_cIO, "lines", rb_io_each_line, -1);
rb_define_method(rb_cIO, "bytes", rb_io_each_byte, 0);
rb_define_method(rb_cIO, "chars", rb_io_each_char, 0);
rb_define_method(rb_cIO, "codepoints", rb_io_each_codepoint, 0);
rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
rb_define_method(rb_cIO, "chars", rb_io_chars, 0);
rb_define_method(rb_cIO, "codepoints", rb_io_codepoints, 0);
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
......
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
rb_define_method(rb_cARGF, "each_char", argf_each_char, 0);
rb_define_method(rb_cARGF, "each_codepoint", argf_each_codepoint, 0);
rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
rb_define_method(rb_cARGF, "codepoints", argf_each_codepoint, 0);
rb_define_method(rb_cARGF, "lines", argf_lines, -1);
rb_define_method(rb_cARGF, "bytes", argf_bytes, 0);
rb_define_method(rb_cARGF, "chars", argf_chars, 0);
rb_define_method(rb_cARGF, "codepoints", argf_codepoints, 0);
rb_define_method(rb_cARGF, "read", argf_read, -1);
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);
test/ruby/test_argf.rb
assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952)
end
def test_lines
ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
$stderr = $stdout
s = []
ARGF.lines {|l| s << l }
p s
SRC
assert_match(/deprecated/, f.gets)
assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read)
end
end
def test_lines
ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
$stderr = $stdout
print Marshal.dump(ARGF.bytes.to_a)
SRC
assert_match(/deprecated/, f.gets)
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
end
end
def test_bytes
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
$stderr = $stdout
print Marshal.dump(ARGF.bytes.to_a)
SRC
assert_match(/deprecated/, f.gets)
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
end
end
def test_chars
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
$stderr = $stdout
print [Marshal.dump(ARGF.chars.to_a)].pack('m')
SRC
assert_match(/deprecated/, f.gets)
assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read.unpack('m').first))
end
end
def test_codepoints
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
$stderr = $stdout
print Marshal.dump(ARGF.codepoints.to_a)
SRC
assert_match(/deprecated/, f.gets)
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
end
end
test/ruby/test_io.rb
}
end
def test_codepoints
make_tempfile {|t|
bug2959 = '[ruby-core:28650]'
a = ""
File.open(t, 'rt') {|f|
assert_warn(/deprecated/) {
f.codepoints {|c| a << c}
}
}
assert_equal("foo\nbar\nbaz\n", a, bug2959)
}
end
def test_rubydev33072
t = make_tempfile
path = t.path
......
end
def test_lines
verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.puts "foo"
w.puts "bar"
w.puts "baz"
w.close
end, proc do |r|
e = r.lines
e = nil
assert_warn(/deprecated/) {
e = r.lines
}
assert_equal("foo\n", e.next)
assert_equal("bar\n", e.next)
assert_equal("baz\n", e.next)
assert_raise(StopIteration) { e.next }
end)
ensure
$VERBOSE = verbose
end
def test_bytes
verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.binmode
w.puts "foo"
......
w.puts "baz"
w.close
end, proc do |r|
e = r.bytes
e = nil
assert_warn(/deprecated/) {
e = r.bytes
}
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
assert_equal(c.ord, e.next)
end
assert_raise(StopIteration) { e.next }
end)
ensure
$VERBOSE = verbose
end
def test_chars
verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.puts "foo"
w.puts "bar"
w.puts "baz"
w.close
end, proc do |r|
e = r.chars
e = nil
assert_warn(/deprecated/) {
e = r.chars
}
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
assert_equal(c, e.next)
end
assert_raise(StopIteration) { e.next }
end)
ensure
$VERBOSE = verbose
end
def test_readbyte
(3-3/3)