io-extra 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.2.5 - 23-Mar-2011
2
+ * Use rb_thread_blocking_region internally for IO.pread and IO.pwrite. Thanks
3
+ go to Eric Wong for the patch.
4
+
1
5
  == 1.2.4 - 22-Mar-2011
2
6
  * Use NUM2OFFT where appropriate. Fixes potential 32 vs 64 bit issues. Thanks
3
7
  go to Eric Wong for the spot and patch.
@@ -314,6 +314,20 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
314
314
  #endif
315
315
 
316
316
  #ifdef HAVE_PREAD
317
+ struct pread_args {
318
+ int fd;
319
+ void *buf;
320
+ size_t nbyte;
321
+ off_t offset;
322
+ };
323
+
324
+ static VALUE nogvl_pread(void *ptr)
325
+ {
326
+ struct pread_args *args = ptr;
327
+
328
+ return (VALUE)pread(args->fd, args->buf, args->nbyte, args->offset);
329
+ }
330
+
317
331
  /*
318
332
  * IO.pread(fd, length, offset)
319
333
  *
@@ -321,16 +335,22 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
321
335
  * position in the file without changing the file pointer. And unlike IO.read,
322
336
  * the +fd+, +length+ and +offset+ arguments are all mandatory.
323
337
  */
324
- static VALUE s_io_pread(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
325
- int fd = NUM2INT(v_fd);
326
- size_t nbyte = NUM2ULONG(v_nbyte);
327
- off_t offset = NUM2OFFT(v_offset);
328
- VALUE str = rb_str_new(NULL, nbyte);
329
- ssize_t nread = pread(fd, RSTRING_PTR(str), nbyte, offset);
338
+ static VALUE s_io_pread(VALUE klass, VALUE fd, VALUE nbyte, VALUE offset){
339
+ struct pread_args args;
340
+ VALUE str;
341
+ ssize_t nread;
342
+
343
+ args.fd = NUM2INT(fd);
344
+ args.nbyte = NUM2ULONG(nbyte);
345
+ args.offset = NUM2OFFT(offset);
346
+ str = rb_str_new(NULL, args.nbyte);
347
+ args.buf = RSTRING_PTR(str);
348
+
349
+ nread = (ssize_t)rb_thread_blocking_region(nogvl_pread, &args, RUBY_UBF_IO, 0);
330
350
 
331
- if (nread < 0)
351
+ if (nread == -1)
332
352
  rb_sys_fail("pread");
333
- if ((size_t)nread != nbyte)
353
+ if ((size_t)nread != args.nbyte)
334
354
  rb_str_set_len(str, nread);
335
355
 
336
356
  return str;
@@ -360,6 +380,20 @@ static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offs
360
380
  #endif
361
381
 
362
382
  #ifdef HAVE_PWRITE
383
+ struct pwrite_args {
384
+ int fd;
385
+ const void *buf;
386
+ size_t nbyte;
387
+ off_t offset;
388
+ };
389
+
390
+ static VALUE nogvl_pwrite(void *ptr)
391
+ {
392
+ struct pwrite_args *args = ptr;
393
+
394
+ return (VALUE)pwrite(args->fd, args->buf, args->nbyte, args->offset);
395
+ }
396
+
363
397
  /*
364
398
  * IO.pwrite(fd, buf, offset)
365
399
  *
@@ -371,15 +405,16 @@ static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offs
371
405
  *
372
406
  * Returns the number of bytes written.
373
407
  */
374
- static VALUE s_io_pwrite(VALUE klass, VALUE v_fd, VALUE v_buf, VALUE v_offset){
408
+ static VALUE s_io_pwrite(VALUE klass, VALUE fd, VALUE buf, VALUE offset){
375
409
  ssize_t result;
410
+ struct pwrite_args args;
411
+
412
+ args.fd = NUM2INT(fd);
413
+ args.buf = RSTRING_PTR(buf);
414
+ args.nbyte = RSTRING_LEN(buf);
415
+ args.offset = NUM2OFFT(offset);
376
416
 
377
- result = pwrite(
378
- NUM2INT(v_fd),
379
- RSTRING_PTR(v_buf),
380
- RSTRING_LEN(v_buf),
381
- NUM2OFFT(v_offset)
382
- );
417
+ result = (ssize_t)rb_thread_blocking_region(nogvl_pwrite, &args, RUBY_UBF_IO, 0);
383
418
 
384
419
  if(result == -1)
385
420
  rb_sys_fail("pwrite");
@@ -544,6 +579,6 @@ void Init_extra(){
544
579
  rb_define_singleton_method(rb_cIO, "writev", s_io_writev, 2);
545
580
  #endif
546
581
 
547
- /* 1.2.4: The version of this library. This a string. */
548
- rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.2.4"));
582
+ /* 1.2.5: The version of this library. This a string. */
583
+ rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.2.5"));
549
584
  }
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |spec|
5
- if RbConfig::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw/i
5
+ if RbConfig::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw|windows/i
6
6
  STDERR.puts 'Not supported on this platform. Exiting.'
7
7
  exit(-1)
8
8
  end
9
9
 
10
10
  spec.name = 'io-extra'
11
- spec.version = '1.2.4'
11
+ spec.version = '1.2.5'
12
12
  spec.author = 'Daniel J. Berger'
13
13
  spec.license = 'Artistic 2.0'
14
14
  spec.email = 'djberg96@gmail.com'
@@ -20,7 +20,7 @@ class TC_IO_Extra < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  def test_version
23
- assert_equal('1.2.4', IO::EXTRA_VERSION)
23
+ assert_equal('1.2.5', IO::EXTRA_VERSION)
24
24
  end
25
25
 
26
26
  def test_direct_constant
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-extra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 4
10
- version: 1.2.4
9
+ - 5
10
+ version: 1.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel J. Berger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-22 00:00:00 -06:00
18
+ date: 2011-03-23 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency