merges r23424 from trunk into ruby_1_9_1.

--
* ext/stringio/stringio.c (strio_ungetbyte): encoding should not
  be effective.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@23520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yugui 2009-05-21 14:48:03 +00:00
parent 6fac4c5f9f
commit ce1a4ee112
5 changed files with 68 additions and 3 deletions

View file

@ -744,8 +744,37 @@ strio_ungetc(VALUE self, VALUE c)
static VALUE
strio_ungetbyte(VALUE self, VALUE c)
{
NUM2INT(c);
return strio_ungetc(self, c);
struct StringIO *ptr = readable(StringIO(self));
char buf[1], *cp = buf;
long pos = ptr->pos, cl = 1;
VALUE str = ptr->string;
if (NIL_P(c)) return Qnil;
if (FIXNUM_P(c)) {
buf[0] = (char)FIX2INT(c);
}
else {
SafeStringValue(c);
cp = RSTRING_PTR(c);
cl = RSTRING_LEN(c);
if (cl == 0) return Qnil;
}
rb_str_modify(str);
if (cl > pos) {
char *s;
long rest = RSTRING_LEN(str) - pos;
rb_str_resize(str, rest + cl);
s = RSTRING_PTR(str);
memmove(s + cl, s + pos, rest);
pos = 0;
}
else {
pos -= cl;
}
memcpy(RSTRING_PTR(str) + pos, cp, cl);
ptr->pos = pos;
RB_GC_GUARD(c);
return Qnil;
}
/*