io-extra 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.2.6 - 22-May-2011
2
+ * Fixed a potential memory leak in the pread_ptr method where malloc'ed
3
+ memory was not freed if the pread function call failed. Thanks go to
4
+ Eric Wong for the spot.
5
+ * Added the IO#ttyname method.
6
+ * Added the (empty) .gemtest file for test.rubygems.org.
7
+
1
8
  == 1.2.5 - 23-Mar-2011
2
9
  * Use rb_thread_blocking_region internally for IO.pread and IO.pwrite. Thanks
3
10
  go to Eric Wong for the patch.
data/MANIFEST CHANGED
@@ -7,4 +7,5 @@
7
7
  * examples/example_io_extra.rb
8
8
  * ext/extconf.rb
9
9
  * ext/io/extra.c
10
- * test/test_io_extra.rb
10
+ * test/test_io_extra.rb
11
+ *.gemtest
@@ -15,6 +15,7 @@ have_func('pwrite')
15
15
  have_func('writev')
16
16
  have_func('rb_str_set_len', 'ruby.h')
17
17
  have_func('rb_thread_blocking_region')
18
+ have_func('ttyname')
18
19
 
19
20
  case RbConfig::CONFIG['host_os']
20
21
  when /darwin/i
@@ -367,15 +367,17 @@ static VALUE s_io_pread(VALUE klass, VALUE fd, VALUE nbyte, VALUE offset){
367
367
  * address with pure Ruby.
368
368
  */
369
369
  static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
370
- int fd = NUM2INT(v_fd);
371
- size_t nbyte = NUM2ULONG(v_nbyte);
372
- off_t offset = NUM2OFFT(v_offset);
373
- uintptr_t* vector = malloc(nbyte + 1);
370
+ int fd = NUM2INT(v_fd);
371
+ size_t nbyte = NUM2ULONG(v_nbyte);
372
+ off_t offset = NUM2OFFT(v_offset);
373
+ uintptr_t* vector = malloc(nbyte + 1);
374
374
 
375
- if(pread(fd, vector, nbyte, offset) == -1)
376
- rb_sys_fail("pread");
375
+ if(pread(fd, vector, nbyte, offset) == -1){
376
+ free(vector);
377
+ rb_sys_fail("pread");
378
+ }
377
379
 
378
- return ULL2NUM(vector[0]);
380
+ return ULL2NUM(vector[0]);
379
381
  }
380
382
  #endif
381
383
 
@@ -538,6 +540,29 @@ static VALUE s_io_writev(VALUE klass, VALUE fd, VALUE ary) {
538
540
  }
539
541
  #endif
540
542
 
543
+ #ifdef HAVE_TTYNAME
544
+ /*
545
+ * io.ttyname
546
+ *
547
+ * Returns the ttyname associated with the IO object, or nil if the IO
548
+ * object isn't associated with a tty.
549
+ *
550
+ * Example:
551
+ *
552
+ * STDOUT.ttyname # => '/dev/ttyp1'
553
+ */
554
+ static VALUE io_get_ttyname(VALUE self){
555
+ VALUE v_return = Qnil;
556
+
557
+ int fd = NUM2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
558
+
559
+ if(isatty(fd))
560
+ v_return = rb_str_new2(ttyname(fd));
561
+
562
+ return v_return;
563
+ }
564
+ #endif
565
+
541
566
  /* Adds the IO.closefrom, IO.fdwalk class methods, as well as the IO#directio
542
567
  * and IO#directio? instance methods (if supported on your platform).
543
568
  */
@@ -579,6 +604,10 @@ void Init_extra(){
579
604
  rb_define_singleton_method(rb_cIO, "writev", s_io_writev, 2);
580
605
  #endif
581
606
 
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"));
607
+ #ifdef HAVE_TTYNAME
608
+ rb_define_method(rb_cIO, "ttyname", io_get_ttyname, 0);
609
+ #endif
610
+
611
+ /* 1.2.6: The version of this library. This a string. */
612
+ rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.2.6"));
584
613
  }
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  end
9
9
 
10
10
  spec.name = 'io-extra'
11
- spec.version = '1.2.5'
11
+ spec.version = '1.2.6'
12
12
  spec.author = 'Daniel J. Berger'
13
13
  spec.license = 'Artistic 2.0'
14
14
  spec.email = 'djberg96@gmail.com'
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.summary = 'Adds extra methods to the IO class.'
17
17
  spec.test_file = 'test/test_io_extra.rb'
18
18
  spec.extensions = ['ext/extconf.rb']
19
- spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
19
+ spec.files = Dir['**/*'] << '.gemtest'
20
20
 
21
21
  spec.extra_rdoc_files = [
22
22
  'CHANGES',
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.description = <<-EOF
34
34
  Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, IO.pwrite, and
35
- IO.writev singleton methods as well as the IO#directio and IO#directio?
36
- instance methods (for those platforms that support them).
35
+ IO.writev singleton methods as well as the IO#directio, IO#directio? and
36
+ IO#ttyname instance methods (for those platforms that support them).
37
37
  EOF
38
38
  end
@@ -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.5', IO::EXTRA_VERSION)
23
+ assert_equal('1.2.6', IO::EXTRA_VERSION)
24
24
  end
25
25
 
26
26
  def test_direct_constant
@@ -147,6 +147,12 @@ class TC_IO_Extra < Test::Unit::TestCase
147
147
  end
148
148
  end
149
149
 
150
+ def test_ttyname
151
+ assert_respond_to(@fh, :ttyname)
152
+ assert_nil(@fh.ttyname)
153
+ assert_kind_of(String, STDOUT.ttyname)
154
+ end
155
+
150
156
  def teardown
151
157
  @fh.close rescue nil
152
158
  @fh = nil
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
10
- version: 1.2.5
9
+ - 6
10
+ version: 1.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel J. Berger
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-23 00:00:00 -06:00
19
- default_executable:
18
+ date: 2011-05-22 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: test-unit
@@ -34,7 +33,7 @@ dependencies:
34
33
  version: 2.1.1
35
34
  type: :development
36
35
  version_requirements: *id001
37
- description: " Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, IO.pwrite, and\n IO.writev singleton methods as well as the IO#directio and IO#directio?\n instance methods (for those platforms that support them).\n"
36
+ description: " Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, IO.pwrite, and\n IO.writev singleton methods as well as the IO#directio, IO#directio? and\n IO#ttyname instance methods (for those platforms that support them).\n"
38
37
  email: djberg96@gmail.com
39
38
  executables: []
40
39
 
@@ -46,18 +45,18 @@ extra_rdoc_files:
46
45
  - MANIFEST
47
46
  - ext/io/extra.c
48
47
  files:
49
- - Rakefile
50
- - README
51
- - doc/io_extra.txt
52
- - io-extra.gemspec
53
48
  - CHANGES
49
+ - doc/io_extra.txt
54
50
  - examples/example_io_extra.rb
55
51
  - examples/example_pread.rb
56
- - test/test_io_extra.rb
57
- - MANIFEST
58
52
  - ext/extconf.rb
59
53
  - ext/io/extra.c
60
- has_rdoc: true
54
+ - io-extra.gemspec
55
+ - MANIFEST
56
+ - Rakefile
57
+ - README
58
+ - test/test_io_extra.rb
59
+ - .gemtest
61
60
  homepage: http://www.rubyforge.org/projects/shards
62
61
  licenses:
63
62
  - Artistic 2.0
@@ -89,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
88
  requirements: []
90
89
 
91
90
  rubyforge_project: shards
92
- rubygems_version: 1.6.2
91
+ rubygems_version: 1.8.3
93
92
  signing_key:
94
93
  specification_version: 3
95
94
  summary: Adds extra methods to the IO class.