diff --git a/.gitignore b/.gitignore index e236684..2514b52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.build/ /.bundle/ /.yardoc /Gemfile.lock diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 24f3cc1..a689e6e 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -34,6 +34,7 @@ STRINGIO_VERSION = "3.2.1"; # define NUM2ULEN(num) NUM2ULONG(num) # define LEN2NUM(num) LONG2NUM(num) # define ULEN2NUM(num) ULONG2NUM(num) +# define PRIdLEN "ld" typedef long rb_len_t; typedef unsigned long rb_ulen_t; #endif @@ -959,15 +960,14 @@ strio_seek(int argc, VALUE *argv, VALUE self) if (CLOSED(self)) { rb_raise(rb_eIOError, "closed stream"); } - switch (whence) { - case Qnil: - case INT2FIX(0): + switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) { + case 0: offset = 0; break; - case INT2FIX(1): + case 1: offset = ptr->pos; break; - case INT2FIX(2): + case 2: if (NIL_P(ptr->string)) { offset = 0; } @@ -1734,7 +1734,7 @@ strio_read(int argc, VALUE *argv, VALUE self) if (!NIL_P(argv[0])) { len = NUM2LEN(argv[0]); if (len < 0) { - rb_raise(rb_eArgError, "negative length %ld given", len); + rb_raise(rb_eArgError, "negative length %"PRIdLEN" given", len); } if (eos_p(ptr)) { if (!NIL_P(str)) rb_str_resize(str, 0); diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 413f5a4..fd88de5 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -513,6 +513,8 @@ def test_seek assert_raise(Errno::EINVAL) { f.seek(-1) } f.seek(-1, 2) assert_equal("4", f.getc) + f.seek(-2, 2.0) + assert_equal("3", f.getc) assert_raise(Errno::EINVAL) { f.seek(1, 3) } f.close assert_raise(IOError) { f.seek(0) }