* 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:
parent
1b19c063b8
commit
2498da0ea0
16
ChangeLog
16
ChangeLog
@ -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>
|
Wed Dec 11 11:30:28 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* ext/digest/digest.c (rb_digest_base_copy): renamed "become".
|
* ext/digest/digest.c (rb_digest_base_copy): renamed "become".
|
||||||
|
|
||||||
* ext/stringio/stringio.c (strio_copy): ditto.
|
* 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>
|
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.
|
* pack.c (utf8_limits): fix the limit of 4 bytes UTF-8 sequence.
|
||||||
|
53
io.c
53
io.c
@ -734,11 +734,11 @@ remain_size(fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
read_all(fptr, siz)
|
read_all(fptr, siz, str)
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
long siz;
|
long siz;
|
||||||
{
|
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
{
|
||||||
long bytes = 0;
|
long bytes = 0;
|
||||||
long n;
|
long n;
|
||||||
off_t pos = 0;
|
off_t pos = 0;
|
||||||
@ -746,7 +746,12 @@ read_all(fptr, siz)
|
|||||||
if (feof(fptr->f)) return Qnil;
|
if (feof(fptr->f)) return Qnil;
|
||||||
READ_CHECK(fptr->f);
|
READ_CHECK(fptr->f);
|
||||||
if (!siz) siz = BUFSIZ;
|
if (!siz) siz = BUFSIZ;
|
||||||
str = rb_tainted_str_new(0, siz);
|
if (NIL_P(str)) {
|
||||||
|
str = rb_tainted_str_new(0, siz);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_str_resize(str, siz);
|
||||||
|
}
|
||||||
pos = io_tell(fptr);
|
pos = io_tell(fptr);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
|
n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
|
||||||
@ -776,12 +781,12 @@ io_read(argc, argv, io)
|
|||||||
long n, len;
|
long n, len;
|
||||||
VALUE length, str;
|
VALUE length, str;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &length);
|
rb_scan_args(argc, argv, "02", &length, &str);
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
if (NIL_P(length)) {
|
if (NIL_P(length)) {
|
||||||
return read_all(fptr, remain_size(fptr));
|
return read_all(fptr, remain_size(fptr), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = NUM2LONG(length);
|
len = NUM2LONG(length);
|
||||||
@ -790,8 +795,18 @@ io_read(argc, argv, io)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (feof(fptr->f)) return Qnil;
|
if (feof(fptr->f)) return Qnil;
|
||||||
str = rb_str_new(0, len);
|
if (NIL_P(str)) {
|
||||||
if (len == 0) return 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);
|
READ_CHECK(fptr->f);
|
||||||
n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
|
n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
|
||||||
@ -967,7 +982,7 @@ rb_io_getline(rs, fptr)
|
|||||||
VALUE str = Qnil;
|
VALUE str = Qnil;
|
||||||
|
|
||||||
if (NIL_P(rs)) {
|
if (NIL_P(rs)) {
|
||||||
str = read_all(fptr, 0);
|
str = read_all(fptr, 0, Qnil);
|
||||||
}
|
}
|
||||||
else if (rs == rb_default_rs) {
|
else if (rs == rb_default_rs) {
|
||||||
return rb_io_getline_fast(fptr, '\n');
|
return rb_io_getline_fast(fptr, '\n');
|
||||||
@ -1498,13 +1513,16 @@ rb_io_syswrite(io, str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_sysread(io, len)
|
rb_io_sysread(argc, argv, io)
|
||||||
VALUE io, len;
|
int argc;
|
||||||
|
VALUE *argv;
|
||||||
|
VALUE io;
|
||||||
{
|
{
|
||||||
|
VALUE len, str;
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
long n, ilen;
|
long n, ilen;
|
||||||
VALUE str;
|
|
||||||
|
|
||||||
|
rb_scan_args(argc, argv, "11", &len, &str);
|
||||||
ilen = NUM2LONG(len);
|
ilen = NUM2LONG(len);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
@ -1512,7 +1530,14 @@ rb_io_sysread(io, len)
|
|||||||
if (READ_DATA_PENDING(fptr->f)) {
|
if (READ_DATA_PENDING(fptr->f)) {
|
||||||
rb_raise(rb_eIOError, "sysread for buffered IO");
|
rb_raise(rb_eIOError, "sysread for buffered IO");
|
||||||
}
|
}
|
||||||
str = rb_str_new(0, ilen);
|
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);
|
n = fileno(fptr->f);
|
||||||
rb_thread_wait_fd(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);
|
if (NIL_P(port)) return rb_str_new(0,0);
|
||||||
|
|
||||||
GetOpenFile(port, fptr);
|
GetOpenFile(port, fptr);
|
||||||
result = read_all(fptr, remain_size(fptr));
|
result = read_all(fptr, remain_size(fptr), Qnil);
|
||||||
|
|
||||||
rb_io_close(port);
|
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, "each_byte", rb_io_each_byte, 0);
|
||||||
|
|
||||||
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
|
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_method(rb_cIO, "fileno", rb_io_fileno, 0);
|
||||||
rb_define_alias(rb_cIO, "to_i", "fileno");
|
rb_define_alias(rb_cIO, "to_i", "fileno");
|
||||||
|
@ -33,10 +33,11 @@ class GetoptLong
|
|||||||
#
|
#
|
||||||
# Error types.
|
# Error types.
|
||||||
#
|
#
|
||||||
class AmbigousOption < StandardError; end
|
class Error < StandardError; end
|
||||||
class NeedlessArgument < StandardError; end
|
class AmbigousOption < Error; end
|
||||||
class MissingArgument < StandardError; end
|
class NeedlessArgument < Error; end
|
||||||
class InvalidOption < StandardError; end
|
class MissingArgument < Error; end
|
||||||
|
class InvalidOption < Error; end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Initializer.
|
# Initializer.
|
||||||
|
3
re.c
3
re.c
@ -1318,9 +1318,6 @@ rb_reg_copy_object(copy, re)
|
|||||||
if (!rb_obj_is_instance_of(re, rb_obj_class(copy))) {
|
if (!rb_obj_is_instance_of(re, rb_obj_class(copy))) {
|
||||||
rb_raise(rb_eTypeError, "wrong argument type");
|
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_check(re);
|
||||||
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
|
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
|
||||||
rb_reg_options(re));
|
rb_reg_options(re));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user