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