diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 47c2c50b95..6ae9e805b5 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -810,11 +810,11 @@ strio_ungetbyte(VALUE self, VALUE c) return Qnil; case T_FIXNUM: case T_BIGNUM: ; - /* rb_int_modulo() not visible from exts */ - VALUE v = rb_funcall(c, rb_intern("modulo"), 1, INT2FIX(256)); - unsigned char cc = NUM2INT(v) & 0xFF; - c = rb_str_new((const char *)&cc, 1); - break; + /* rb_int_and() not visible from exts */ + VALUE v = rb_funcall(c, '&', 1, INT2FIX(0xff)); + const char cc = NUM2INT(v) & 0xFF; + strio_unget_bytes(ptr, &cc, 1); + return Qnil; default: SafeStringValue(c); } diff --git a/string.c b/string.c index 2fbe36b1b8..ccf4796d3b 100644 --- a/string.c +++ b/string.c @@ -5421,7 +5421,7 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value) pos += len; VALUE v = rb_to_int(value); - VALUE w = rb_int_modulo(v, INT2FIX(256)); + VALUE w = rb_int_and(v, INT2FIX(0xff)); unsigned char byte = NUM2INT(w) & 0xFF; if (!str_independent(str))