io-extra 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.1.1 - 8-Sep-2008
2
+ * Added the IO.pread_ptr method. This returns the buffer address
3
+ rather than the buffer itself.
4
+ * Added limited support for OS X.
5
+ * Minor refactoring of the IO.pread method.
6
+
1
7
  == 1.1.0 - 28-Aug-2008
2
8
  * Added IO.pread and IO.pwrite methods for those platforms that
3
9
  support them.
data/ext/extconf.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'mkmf'
2
2
  require 'fileutils'
3
+ require 'rbconfig'
3
4
 
4
5
  dir_config('io')
5
6
 
@@ -9,4 +10,8 @@ have_func('directio')
9
10
  have_func('pread')
10
11
  have_func('pwrite')
11
12
 
13
+ if Config::CONFIG['host_os'] =~ /darwin/i
14
+ $CPPFLAGS += " -D_MACOS"
15
+ end
16
+
12
17
  create_makefile('io/extra', 'io')
data/ext/io/extra.c CHANGED
@@ -25,8 +25,13 @@
25
25
  *
26
26
  *--
27
27
  * The manual approach was copied from the closefrom() man page on Solaris 9.
28
+ * Not implemented on OS X because the getrlimit function is busted.
28
29
  */
29
30
  static VALUE io_closefrom(VALUE klass, VALUE v_low_fd){
31
+ #ifdef _MACOS
32
+ rb_raise(rb_eNotImpError, "IO.closefrom is not implemented on this platform");
33
+ #endif
34
+
30
35
  #ifdef HAVE_CLOSEFROM
31
36
  closefrom(NUM2INT(v_low_fd));
32
37
  #else
@@ -136,19 +141,38 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
136
141
  * the +fd+, +length+ and +offset+ arguments are all mandatory.
137
142
  */
138
143
  static VALUE s_io_pread(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
139
- size_t result;
140
144
  int fd = NUM2INT(v_fd);
141
145
  size_t nbyte = NUM2ULONG(v_nbyte);
142
146
  off_t offset = NUM2ULONG(v_offset);
143
- char buf[nbyte+1];
147
+ char* buf = malloc(nbyte + 1);
144
148
 
145
- result = pread(fd, buf, nbyte, offset);
146
-
147
- if(result == -1)
149
+ if(pread(fd, buf, nbyte, offset) == -1)
148
150
  rb_sys_fail("pread");
149
151
 
150
152
  return rb_str_new2(buf);
151
153
  }
154
+
155
+ /*
156
+ * IO.pread_ptr(fd, length, offset)
157
+ *
158
+ * This is identical to IO.pread, except that it returns the pointer address
159
+ * of the string, instead of the actual buffer.
160
+ *--
161
+ * This was added because, in some cases, the IO.pread buffer might return
162
+ * an empty string. In such situations we are unable to get the actual pointer
163
+ * address with pure Ruby.
164
+ */
165
+ static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
166
+ int fd = NUM2INT(v_fd);
167
+ size_t nbyte = NUM2ULONG(v_nbyte);
168
+ off_t offset = NUM2ULONG(v_offset);
169
+ uintptr_t* vector = malloc(nbyte + 1);
170
+
171
+ if(pread(fd, vector, nbyte, offset) == -1)
172
+ rb_sys_fail("pread");
173
+
174
+ return ULL2NUM(vector[0]);
175
+ }
152
176
  #endif
153
177
 
154
178
  #ifdef HAVE_PWRITE
@@ -203,12 +227,13 @@ void Init_extra(){
203
227
 
204
228
  #ifdef HAVE_PREAD
205
229
  rb_define_singleton_method(rb_cIO, "pread", s_io_pread, 3);
230
+ rb_define_singleton_method(rb_cIO, "pread_ptr", s_io_pread_ptr, 3);
206
231
  #endif
207
232
 
208
233
  #ifdef HAVE_PWRITE
209
234
  rb_define_singleton_method(rb_cIO, "pwrite", s_io_pwrite, 3);
210
235
  #endif
211
236
 
212
- /* 1.1.0: The version of this package. This a string. */
213
- rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.1.0"));
237
+ /* 1.1.1: The version of this package. This a string. */
238
+ rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.1.1"));
214
239
  }
@@ -15,33 +15,40 @@ class TC_IO_Extra < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_version
18
- assert_equal('1.1.0', IO::EXTRA_VERSION)
18
+ assert_equal('1.1.1', IO::EXTRA_VERSION)
19
19
  end
20
20
 
21
- def test_directio
22
- assert_respond_to(@fh, :directio?)
23
- assert_nothing_raised{ @fh.directio? }
24
- end
21
+ unless Config::CONFIG['host_os'] =~ /darwin/i
22
+ def test_directio
23
+ assert_respond_to(@fh, :directio?)
24
+ assert_nothing_raised{ @fh.directio? }
25
+ end
25
26
 
26
- def test_directio_set
27
- assert_respond_to(@fh, :directio=)
28
- assert_raises(StandardError){ @fh.directio = 99 }
29
- assert_nothing_raised{ @fh.directio = IO::DIRECTIO_ON }
30
- end
27
+ def test_directio_set
28
+ assert_respond_to(@fh, :directio=)
29
+ assert_raises(StandardError){ @fh.directio = 99 }
30
+ assert_nothing_raised{ @fh.directio = IO::DIRECTIO_ON }
31
+ end
31
32
 
32
- def test_constants
33
- assert_not_nil(IO::DIRECTIO_ON)
34
- assert_not_nil(IO::DIRECTIO_OFF)
35
- end
33
+ def test_constants
34
+ assert_not_nil(IO::DIRECTIO_ON)
35
+ assert_not_nil(IO::DIRECTIO_OFF)
36
+ end
36
37
 
37
- def test_fdwalk
38
- assert_respond_to(IO, :fdwalk)
39
- assert_nothing_raised{ IO.fdwalk(0){ } }
38
+ def test_fdwalk
39
+ assert_respond_to(IO, :fdwalk)
40
+ assert_nothing_raised{ IO.fdwalk(0){ } }
41
+ end
40
42
  end
41
43
 
42
44
  def test_closefrom
43
45
  assert_respond_to(IO, :closefrom)
44
- assert_nothing_raised{ IO.closefrom(3) }
46
+
47
+ if Config::CONFIG['host_os'] =~ /darwin/i
48
+ assert_raise(NotImplementedError){ IO.closefrom(3) }
49
+ else
50
+ assert_nothing_raised{ IO.closefrom(3) }
51
+ end
45
52
  end
46
53
 
47
54
  def test_pread
@@ -51,6 +58,13 @@ class TC_IO_Extra < Test::Unit::TestCase
51
58
  assert_equal("quick", IO.pread(@fh.fileno, 5, 4))
52
59
  end
53
60
 
61
+ def test_pread_ptr
62
+ @fh.close rescue nil
63
+ @fh = File.open(@file)
64
+ assert_respond_to(IO, :pread_ptr)
65
+ assert_kind_of(Fixnum, IO.pread_ptr(@fh.fileno, 5, 4))
66
+ end
67
+
54
68
  def test_pwrite
55
69
  assert_respond_to(IO, :pwrite)
56
70
  assert_nothing_raised{ IO.pwrite(@fh.fileno, "HAL", 0) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-extra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-28 00:00:00 -06:00
12
+ date: 2008-09-08 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: 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).
16
+ description: Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, and IO.pwrite class methods as well as the IO#directio and IO#directio? instance methods (for those platforms that support them).
17
17
  email: djberg96@gmail.com
18
18
  executables: []
19
19
 
@@ -55,6 +55,6 @@ rubyforge_project: shards
55
55
  rubygems_version: 1.2.0
56
56
  signing_key:
57
57
  specification_version: 2
58
- 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).
58
+ summary: Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, and IO.pwrite class methods as well as the IO#directio and IO#directio? instance methods (for those platforms that support them).
59
59
  test_files:
60
60
  - test/test_io_extra.rb