Skip to content
Browse files

- gem.extensions = ["ext/extconf.rb"] is added to the Gemfile or not …

…extension is compiled!

- Improved #read method (empty string is returned if buffer is empty)
  • Loading branch information...
1 parent 98ab1cd commit d842200cfe7f905a4d5bae382b64ae72f41f6b62 @ibc ibc committed Feb 13, 2012
Showing with 12 additions and 10 deletions.
  1. +10 −10 ext/iobuffer.c
  2. +2 −0 iobuffer.gemspec
View
20 ext/iobuffer.c
@@ -287,6 +287,9 @@ IO_Buffer_prepend(VALUE self, VALUE data)
* Read the specified abount of data from the buffer. If no value
* is given the entire contents of the buffer are returned. Any data
* read from the buffer is cleared.
+ * The given length must be greater than 0 or an exception would raise.
+ * If the buffer size is zero then an empty string is returned (regardless
+ * the given length).
*/
static VALUE
IO_Buffer_read(int argc, VALUE * argv, VALUE self)
@@ -299,18 +302,15 @@ IO_Buffer_read(int argc, VALUE * argv, VALUE self)
if (rb_scan_args(argc, argv, "01", &length_obj) == 1) {
length = NUM2INT(length_obj);
- } else {
- if (buf->size == 0)
- return rb_str_new2("");
-
- length = buf->size;
- }
-
- if (length > buf->size)
+ if(length < 1)
+ rb_raise(rb_eArgError, "length must be greater than zero");
+ if(length > buf->size)
+ length = buf->size;
+ } else
length = buf->size;
- if (length < 1)
- rb_raise(rb_eArgError, "length must be greater than zero");
+ if(buf->size == 0)
+ return rb_str_new2("");
str = rb_str_new(0, length);
buffer_read(buf, RSTRING_PTR(str), length);
View
2 iobuffer.gemspec
@@ -19,6 +19,8 @@ Gem::Specification.new do |gem|
gem.files = Dir['README.md', 'lib/**/*', 'ext/**/*.{c,rb}']
gem.require_path = 'lib'
+ gem.extensions = ["ext/extconf.rb"]
+
gem.add_development_dependency 'rake-compiler'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'

0 comments on commit d842200

Please sign in to comment.
Something went wrong with that request. Please try again.