summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-14 07:07:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-14 07:07:55 +0000
commitfc9664d3d853af61ee48265eaf4788ffd7970403 (patch)
tree182da57d1302b6a6c0e15482a553d26d103abeb2 /ext
parent794a52fc6e0da1f7ecc85f6eaef9e88742238f71 (diff)
downloadruby-fc9664d3d853af61ee48265eaf4788ffd7970403.tar.gz
ruby-fc9664d3d853af61ee48265eaf4788ffd7970403.tar.xz
ruby-fc9664d3d853af61ee48265eaf4788ffd7970403.zip
* ext/stringio/stringio.c (strio_ungetbyte): encoding should not
be effective. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index bc605da2a..9bb5ed8a2 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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;
}
/*