Commit a016d1d0 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge branch 'dearblue-mruby-io'

parents 76355dee 6de1c64a
......@@ -144,22 +144,12 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
switch (o.w) {
case MRB_Qfalse:
case MRB_Qnil:
return MRB_TT_FALSE;
case MRB_Qtrue:
return MRB_TT_TRUE;
case MRB_Qundef:
return MRB_TT_UNDEF;
}
if (mrb_fixnum_p(o)) {
return MRB_TT_FIXNUM;
}
if (mrb_symbol_p(o)) {
return MRB_TT_SYMBOL;
}
return o.value.bp->tt;
return !mrb_bool(o) ? MRB_TT_FALSE :
mrb_true_p(o) ? MRB_TT_TRUE :
mrb_fixnum_p(o) ? MRB_TT_FIXNUM :
mrb_symbol_p(o) ? MRB_TT_SYMBOL :
mrb_undef_p(o) ? MRB_TT_UNDEF :
o.value.bp->tt;
}
#endif /* MRUBY_BOXING_WORD_H */
......@@ -4526,6 +4526,7 @@ parse_string(parser_state *p)
case 'm': f |= 4; break;
case 'u': f |= 16; break;
case 'n': f |= 32; break;
case 'o': break;
default: tokadd(p, re_opt); break;
}
}
......
......@@ -123,8 +123,8 @@ class IO
def write(string)
str = string.is_a?(String) ? string : string.to_s
return str.size unless str.size > 0
if 0 < @buf.length
return 0 if str.empty?
unless @buf.empty?
# reset real pos ignore buf
seek(pos, SEEK_SET)
end
......@@ -140,8 +140,8 @@ class IO
def eof?
_check_readable
begin
buf = _read_buf
return buf.size == 0
_read_buf
return @buf.empty?
rescue EOFError
return true
end
......@@ -150,7 +150,7 @@ class IO
def pos
raise IOError if closed?
sysseek(0, SEEK_CUR) - @buf.length
sysseek(0, SEEK_CUR) - @buf.bytesize
end
alias_method :tell, :pos
......@@ -170,8 +170,13 @@ class IO
end
def _read_buf
return @buf if @buf && @buf.size > 0
@buf = sysread(BUF_SIZE)
return @buf if @buf && @buf.bytesize >= 4 # maximum UTF-8 character is 4 bytes
@buf ||= ""
begin
@buf += sysread(BUF_SIZE)
rescue EOFError => e
raise e if @buf.empty?
end
end
def ungetc(substr)
......@@ -253,12 +258,14 @@ class IO
break
end
if limit && limit <= @buf.bytesize
array.push IO._bufread(@buf, limit)
if limit && limit <= @buf.size
array.push @buf[0, limit]
@buf[0, limit] = ""
break
elsif idx = @buf.index(rs)
len = idx + rs.bytesize
array.push IO._bufread(@buf, len)
len = idx + rs.size
array.push @buf[0, len]
@buf[0, len] = ""
break
else
array.push @buf
......@@ -281,7 +288,9 @@ class IO
def readchar
_read_buf
IO._bufread(@buf, 1)
c = @buf[0]
@buf[0] = ""
c
end
def getc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment