* io.c (io_read): takes optional second argument to specify a

string to be written.  the string should not be frozen.

* io.c (rb_io_sysread): ditto.

* lib/getoptlong.rb (GetoptLong::Error): provide a common ancestor
  for GetoptLong error classes (RCR#129).

* re.c (rb_reg_copy_object): fixed memory leak.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-12-11 09:32:41 +00:00
Родитель 1b19c063b8
Коммит 2498da0ea0
4 изменённых файлов: 60 добавлений и 21 удалений

Просмотреть файл

@ -1,9 +1,25 @@
Wed Dec 11 17:54:59 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_read): takes optional second argument to specify a
string to be written. the string should not be frozen.
* io.c (rb_io_sysread): ditto.
Wed Dec 11 11:30:28 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ext/digest/digest.c (rb_digest_base_copy): renamed "become".
* ext/stringio/stringio.c (strio_copy): ditto.
Wed Dec 11 00:45:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/getoptlong.rb (GetoptLong::Error): provide a common ancestor
for GetoptLong error classes (RCR#129).
Tue Dec 10 17:42:39 2002 2002 K.Kosako <kosako@sofnec.co.jp>
* re.c (rb_reg_copy_object): fixed memory leak.
Tue Dec 10 17:30:35 2002 Tanaka Akira <akr@m17n.org>
* pack.c (utf8_limits): fix the limit of 4 bytes UTF-8 sequence.

45
io.c
Просмотреть файл

@ -734,11 +734,11 @@ remain_size(fptr)
}
static VALUE
read_all(fptr, siz)
read_all(fptr, siz, str)
OpenFile *fptr;
long siz;
{
VALUE str;
{
long bytes = 0;
long n;
off_t pos = 0;
@ -746,7 +746,12 @@ read_all(fptr, siz)
if (feof(fptr->f)) return Qnil;
READ_CHECK(fptr->f);
if (!siz) siz = BUFSIZ;
if (NIL_P(str)) {
str = rb_tainted_str_new(0, siz);
}
else {
rb_str_resize(str, siz);
}
pos = io_tell(fptr);
for (;;) {
n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
@ -776,12 +781,12 @@ io_read(argc, argv, io)
long n, len;
VALUE length, str;
rb_scan_args(argc, argv, "01", &length);
rb_scan_args(argc, argv, "02", &length, &str);
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (NIL_P(length)) {
return read_all(fptr, remain_size(fptr));
return read_all(fptr, remain_size(fptr), str);
}
len = NUM2LONG(length);
@ -790,8 +795,18 @@ io_read(argc, argv, io)
}
if (feof(fptr->f)) return Qnil;
if (NIL_P(str)) {
str = rb_str_new(0, len);
if (len == 0) return str;
}
else {
StringValue(str);
rb_str_modify(str);
if (len == 0) {
rb_str_resize(str, 0);
return str;
}
}
READ_CHECK(fptr->f);
n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
@ -967,7 +982,7 @@ rb_io_getline(rs, fptr)
VALUE str = Qnil;
if (NIL_P(rs)) {
str = read_all(fptr, 0);
str = read_all(fptr, 0, Qnil);
}
else if (rs == rb_default_rs) {
return rb_io_getline_fast(fptr, '\n');
@ -1498,13 +1513,16 @@ rb_io_syswrite(io, str)
}
static VALUE
rb_io_sysread(io, len)
VALUE io, len;
rb_io_sysread(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
VALUE len, str;
OpenFile *fptr;
long n, ilen;
VALUE str;
rb_scan_args(argc, argv, "11", &len, &str);
ilen = NUM2LONG(len);
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
@ -1512,7 +1530,14 @@ rb_io_sysread(io, len)
if (READ_DATA_PENDING(fptr->f)) {
rb_raise(rb_eIOError, "sysread for buffered IO");
}
if (NIL_P(str)) {
str = rb_str_new(0, ilen);
}
else {
StringValue(str);
rb_str_modify(str);
rb_str_resize(str, ilen);
}
n = fileno(fptr->f);
rb_thread_wait_fd(fileno(fptr->f));
@ -3086,7 +3111,7 @@ rb_f_backquote(obj, str)
if (NIL_P(port)) return rb_str_new(0,0);
GetOpenFile(port, fptr);
result = read_all(fptr, remain_size(fptr));
result = read_all(fptr, remain_size(fptr), Qnil);
rb_io_close(port);
@ -3919,7 +3944,7 @@ Init_IO()
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 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_cIO, "sysread", rb_io_sysread, -1);
rb_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
rb_define_alias(rb_cIO, "to_i", "fileno");

Просмотреть файл

@ -33,10 +33,11 @@ class GetoptLong
#
# Error types.
#
class AmbigousOption < StandardError; end
class NeedlessArgument < StandardError; end
class MissingArgument < StandardError; end
class InvalidOption < StandardError; end
class Error < StandardError; end
class AmbigousOption < Error; end
class NeedlessArgument < Error; end
class MissingArgument < Error; end
class InvalidOption < Error; end
#
# Initializer.

3
re.c
Просмотреть файл

@ -1318,9 +1318,6 @@ rb_reg_copy_object(copy, re)
if (!rb_obj_is_instance_of(re, rb_obj_class(copy))) {
rb_raise(rb_eTypeError, "wrong argument type");
}
RREGEXP(copy)->ptr = 0;
RREGEXP(copy)->len = 0;
RREGEXP(copy)->str = 0;
rb_reg_check(re);
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
rb_reg_options(re));