io-extra 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.0.2 - 16-Jul-2007
2
+ * Added a Rakefile with tasks for testing and installation.
3
+ * Some doc updates and internal reorganization, but no significant code
4
+ changes.
5
+ * Fixed an "implicit declaration" build warning (the man page was
6
+ mistaken about the header file I should use).
7
+ * Minor updates to the example program.
8
+
1
9
  == 1.0.1 - 7-Jul-2006
2
10
  * Added a gemspec.
3
11
  * Added or improved the inline rdoc comments in the source.
data/MANIFEST ADDED
@@ -0,0 +1,10 @@
1
+ * MANIFEST
2
+ * README
3
+ * CHANGES
4
+ * Rakefile
5
+ * io-extra.gemspec
6
+ * doc/io_extra.txt
7
+ * examples/test.rb
8
+ * ext/extconf.rb
9
+ * ext/io/extra.c
10
+ * test/tc_ioextra.rb
data/README CHANGED
@@ -2,17 +2,20 @@
2
2
  The io-extra package provides a few extra IO methods that you may find
3
3
  handy. They are IO.closefrom, IO.fdwalk, IO#directio? and IO#directio=.
4
4
 
5
- Not supported on MS Windows.
5
+ Not supported on MS Windows or OS X.
6
6
 
7
7
  = Installation
8
- ruby extconf.rb
9
- make
10
- ruby test/tc_ioextra.rb (optional)
11
- make site-install
8
+ == Standard Installation
9
+ rake test (optional)
10
+ rake install
11
+
12
+ == Gem Installation
13
+ rake test (optional)
14
+ rake install_gem
12
15
 
13
16
  = Developer's Notes
14
- == Q) What is the difference between your implementation of IO.closefrom and a
15
- pure Ruby version that looks something like this?
17
+ You might be wondering what the difference is between my implementation of
18
+ IO.closefrom and a pure Ruby version that looks something like this:
16
19
 
17
20
  def IO.closefrom(n)
18
21
  0.upto n do |fd|
@@ -25,8 +28,8 @@ than only open file descriptors. However, I should note that this only
25
28
  applies if your platform supports the closefrom() function. In that case,
26
29
  the only advantage is speed.
27
30
 
28
- == Q) What is the difference between your implementation of IO.fdwalk and a
29
- pure Ruby version that looks something like this?
31
+ You might also be wondering what the difference is between my implementation
32
+ of IO.fdwalk and a pure Ruby version that looks something like this:
30
33
 
31
34
  def IO.fdwalk(n)
32
35
  ObjectSpace.each_object(File){ |f|
@@ -35,5 +38,38 @@ pure Ruby version that looks something like this?
35
38
  end
36
39
 
37
40
  The primary difference is that this only closes Ruby file objects, not
38
- necessarily every filehandle opened by the Ruby process. Think system(), for
39
- example.
41
+ necessarily every filehandle opened by the Ruby process. For example, handles
42
+ opened via system() calls.
43
+
44
+ = Note to OS X Users
45
+ The OS X platform does not support closefrom(), fdwalk() or directio(). The
46
+ hand-crafted IO.closefrom function will not work because the getrlimit()
47
+ function on OS X does not work. Patches welcome.
48
+
49
+ = Documentation
50
+ For further documentation, see the io_extra.txt file or the inline
51
+ documentation that was generated by RDoc (if you did a gem install).
52
+
53
+ = Known Issues
54
+ None that I'm aware of. Please file any bug reports on the project page
55
+ at http://www.rubyforge.org/projects/shards.
56
+
57
+ = Future Plans
58
+ I may add the File::O_DIRECT open constant on platforms that support it.
59
+
60
+ = License
61
+ Ruby's
62
+
63
+ = Copyright
64
+ (C) 2003-2007 Daniel J. Berger
65
+ All Rights Reserved
66
+
67
+ = Warranty
68
+ This package is provided "as is" and without any express or
69
+ implied warranties, including, without limitation, the implied
70
+ warranties of merchantability and fitness for a particular purpose.
71
+
72
+ = Author
73
+ Daniel J. Berger
74
+ djberg96 at nospam at gmail dot com
75
+ imperator on IRC (irc.freenode.net)
data/doc/io_extra.txt CHANGED
@@ -1,8 +1,8 @@
1
1
  = Description
2
2
  The io-extra package provides a few extra IO methods that you may find
3
- handy. They are IO.closefrom, IO.fdwalk and IO.directio.
3
+ handy. They are IO.closefrom, IO.fdwalk and IO.directio.
4
4
 
5
- Not supported on Win32.
5
+ Not supported on MS Windows or OS X.
6
6
 
7
7
  = Synopsis
8
8
  require "io/extra"
@@ -20,7 +20,7 @@
20
20
  IO.closefrom(low_fd)
21
21
  Closes all open file descriptors greater than or equal to 'low_fd'.
22
22
 
23
- This uses your systems native closefrom() function, if supported. If not,
23
+ This uses your systems native closefrom() function, if supported. If not,
24
24
  this method uses a slightly less efficient manual approach that uses
25
25
  getrlimit() behind the scenes.
26
26
 
@@ -34,7 +34,7 @@ IO.fdwalk(low_fd){ |fh| ... }
34
34
  = Instance methods
35
35
  IO#directio?
36
36
  Returns true or false, based on whether directio has been set for the
37
- current handle. The default is false.
37
+ current handle. The default is false.
38
38
 
39
39
  Note supported on all platforms.
40
40
 
@@ -64,26 +64,5 @@ IO::DIRECTIO_OFF
64
64
  IO::EXTRA_VERSION
65
65
  Returns the current version number of this package as a String.
66
66
 
67
- = Known Bugs
68
- You may receive a warning about implicit declaration during the build
69
- process. You can ignore this.
70
-
71
- = Future Plans
72
- Eliminate warnings that occur during the build process.
73
-
74
- = License
75
- Ruby's
76
-
77
- = Copyright
78
- (C) 2003-2005 Daniel J. Berger
79
- All Rights Reserved
80
-
81
- = Warranty
82
- This package is provided "as is" and without any express or
83
- implied warranties, including, without limitation, the implied
84
- warranties of merchantability and fitness for a particular purpose.
85
-
86
- = Author
87
- Daniel J. Berger
88
- djberg96 at gmail dot com
89
- imperator on IRC (irc.freenode.net)
67
+ = Other documentation
68
+ See the README for more documentation.
data/ext/extconf.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'mkmf'
2
+ require 'fileutils'
3
+
4
+ dir_config('io')
5
+
6
+ FileUtils.cp('io/extra.c', '.')
7
+
8
+ have_func('closefrom')
9
+ have_func('fdwalk')
10
+ have_func('directio')
11
+
12
+ create_makefile('io/extra')
@@ -10,7 +10,7 @@
10
10
 
11
11
  #ifdef HAVE_DIRECTIO
12
12
  #include <sys/types.h>
13
- #include <sys/fcntl.h>
13
+ #include <fcntl.h>
14
14
  #endif
15
15
 
16
16
  /*
@@ -35,13 +35,13 @@ static VALUE io_closefrom(VALUE klass, VALUE v_low_fd){
35
35
  getrlimit(RLIMIT_NOFILE, &limits);
36
36
  lowfd = NUM2INT(v_low_fd);
37
37
 
38
- for(i = lowfd; i < limits.rlim_max; i++){
38
+ for(i = lowfd; i < limits.rlim_max; i++)
39
39
  close(i);
40
- }
41
40
  #endif
42
41
  return klass;
43
42
  }
44
43
 
44
+ #ifdef HAVE_FDWALK
45
45
  /*
46
46
  * Used by io_fdwalk. Yields a File object back to the block.
47
47
  * It's up to the user to close it.
@@ -54,7 +54,6 @@ static int close_func(void* lowfd, int fd){
54
54
  return 0;
55
55
  }
56
56
 
57
- #ifdef HAVE_FDWALK
58
57
  /*
59
58
  * call-seq:
60
59
  * IO.fdwalk(lowfd){ |fh| ... }
@@ -98,13 +97,14 @@ static VALUE io_get_directio(VALUE self){
98
97
  * IO#directio=(advice)
99
98
  *
100
99
  * Sets the advice for the current file descriptor using directio(). Valid
101
- * values are IO::DIRECTIO_ON and IO::DIRECTIO_OFF.
100
+ * values are IO::DIRECTIO_ON and IO::DIRECTIO_OFF. See the directio(3c) man
101
+ * page for more information.
102
102
  *
103
103
  * All file descriptors start at DIRECTIO_OFF, unless your filesystem has
104
104
  * been mounted using 'forcedirectio' (and supports that option).
105
105
  */
106
106
  static VALUE io_set_directio(VALUE self, VALUE v_advice){
107
- int fd, rv;
107
+ int fd;
108
108
  int advice = NUM2INT(v_advice);
109
109
 
110
110
  /* Only two possible valid values */
@@ -114,9 +114,7 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
114
114
  /* Retrieve the current file descriptor in order to pass it to directio() */
115
115
  fd = NUM2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
116
116
 
117
- rv = directio(fd, advice);
118
-
119
- if(-1 == rv)
117
+ if(directio(fd, advice) < 0)
120
118
  rb_raise(rb_eStandardError, "The directio() call failed");
121
119
 
122
120
  if(advice == DIRECTIO_ON)
@@ -139,9 +137,14 @@ void Init_extra(){
139
137
  #ifdef HAVE_DIRECTIO
140
138
  rb_define_method(rb_cIO, "directio?", io_get_directio, 0);
141
139
  rb_define_method(rb_cIO, "directio=", io_set_directio, 1);
140
+
141
+ /* 0: Applications get the default system behavior when accessing file data. */
142
142
  rb_define_const(rb_cIO, "DIRECTIO_OFF", UINT2NUM(DIRECTIO_OFF));
143
+
144
+ /* 1: File data is not cached in the system's memory pages. */
143
145
  rb_define_const(rb_cIO, "DIRECTIO_ON", UINT2NUM(DIRECTIO_ON));
144
146
  #endif
145
147
 
146
- rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.0.1"));
148
+ /* 1.0.2: The version of this package. This a string. */
149
+ rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.0.2"));
147
150
  }
data/test/tc_ioextra.rb CHANGED
@@ -1,64 +1,50 @@
1
- #################################################
1
+ ###########################################################################
2
2
  # tc_ioextra.rb
3
3
  #
4
- # Test suite for the io-extra package.
5
- #################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /io-extra/
9
- require "ftools"
10
- Dir.chdir("..") if base == "test"
11
- Dir.mkdir("io") rescue nil
12
- File.copy("extra.so","io")
13
- $LOAD_PATH.unshift(Dir.pwd)
14
- Dir.chdir("test") rescue nil
15
- end
16
-
17
- require "test/unit"
18
- require "io/extra"
4
+ # Test suite for the io-extra package. This test should be run via the
5
+ # 'rake test' task.
6
+ ###########################################################################
7
+ require 'test/unit'
8
+ require 'io/extra'
19
9
 
20
10
  class TC_IO_Extra < Test::Unit::TestCase
21
11
  def setup
22
- @file = "delete_this.txt"
23
- @fh = File.open(@file,"w+")
12
+ @file = 'delete_this.txt'
13
+ @fh = File.open(@file, 'w+')
24
14
  end
25
15
 
26
16
  def test_version
27
- assert_equal("1.0.1", IO::EXTRA_VERSION)
17
+ assert_equal('1.0.2', IO::EXTRA_VERSION)
28
18
  end
29
19
 
30
20
  def test_directio
31
- assert_respond_to(@fh,:directio?)
21
+ assert_respond_to(@fh, :directio?)
32
22
  assert_nothing_raised{ @fh.directio? }
33
23
  end
34
-
24
+
35
25
  def test_directio_set
36
- assert_respond_to(@fh,:directio=)
26
+ assert_respond_to(@fh, :directio=)
37
27
  assert_raises(StandardError){ @fh.directio = 99 }
38
28
  assert_nothing_raised{ @fh.directio = IO::DIRECTIO_ON }
39
29
  end
40
-
41
- def test_closefrom
42
- assert_respond_to(IO,:closefrom)
43
- assert_nothing_raised{ IO.closefrom(3) }
30
+
31
+ def test_constants
32
+ assert_not_nil(IO::DIRECTIO_ON)
33
+ assert_not_nil(IO::DIRECTIO_OFF)
44
34
  end
45
-
35
+
46
36
  def test_fdwalk
47
- assert_respond_to(IO,:fdwalk)
37
+ assert_respond_to(IO, :fdwalk)
48
38
  assert_nothing_raised{ IO.fdwalk(0){ } }
49
39
  end
50
-
51
- def test_constants
52
- assert_not_nil(IO::DIRECTIO_ON)
53
- assert_not_nil(IO::DIRECTIO_OFF)
40
+
41
+ def test_closefrom
42
+ assert_respond_to(IO, :closefrom)
43
+ assert_nothing_raised{ IO.closefrom(3) }
54
44
  end
55
45
 
56
- # Ignore EBADF, since some of the tests will close @fh
57
46
  def teardown
58
- begin
59
- @fh.close
60
- rescue Errno::EBADF
61
- end
47
+ @fh.close rescue nil
62
48
  @fh = nil
63
49
  File.delete(@file) if File.exists?(@file)
64
50
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: io-extra
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2006-07-07 00:00:00 -06:00
6
+ version: 1.0.2
7
+ date: 2007-07-16 00:00:00 -06:00
8
8
  summary: Adds the IO.closefrom and IO.fdwalk class methods as well as the IO#directio and IO#directio? instance methods (for those platforms that support them).
9
9
  require_paths:
10
10
  - lib
@@ -31,9 +31,10 @@ authors:
31
31
  files:
32
32
  - doc/io_extra.txt
33
33
  - test/tc_ioextra.rb
34
- - lib/io/extra.c
34
+ - ext/io/extra.c
35
35
  - CHANGES
36
36
  - README
37
+ - MANIFEST
37
38
  test_files:
38
39
  - test/tc_ioextra.rb
39
40
  rdoc_options: []
@@ -41,10 +42,11 @@ rdoc_options: []
41
42
  extra_rdoc_files:
42
43
  - CHANGES
43
44
  - README
45
+ - MANIFEST
44
46
  executables: []
45
47
 
46
48
  extensions:
47
- - extconf.rb
49
+ - ext/extconf.rb
48
50
  requirements: []
49
51
 
50
52
  dependencies: []
data/extconf.rb DELETED
@@ -1,10 +0,0 @@
1
- require "mkmf"
2
- require "ftools"
3
-
4
- File.copy("lib/io/extra.c",".")
5
-
6
- have_func("closefrom")
7
- have_func("fdwalk")
8
- have_func("directio")
9
-
10
- create_makefile("io/extra")