io-extra 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.2.4 - 22-Mar-2011
2
+ * Use NUM2OFFT where appropriate. Fixes potential 32 vs 64 bit issues. Thanks
3
+ go to Eric Wong for the spot and patch.
4
+ * Added an example program for IO.pread, and a corresponding Rake task.
5
+ * Config substituted with RbConfig, since the former is apparently going to
6
+ deprecated in 1.9. Thanks go to Eric Wong for the spot and patch.
7
+
1
8
  == 1.2.3 - 25-Oct-2010
2
9
  * Documentation updates to the README.
3
10
  * Updates to the Rakefile, including archive tasks, a default task, and
data/Rakefile CHANGED
@@ -2,33 +2,29 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rbconfig'
5
+ include RbConfig
5
6
 
6
- if Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw/i
7
+ CLEAN.include(
8
+ '**/*.gem', # Gem files
9
+ '**/*.rbc', # Rubinius
10
+ '**/*.o', # C object file
11
+ '**/*.log', # Ruby extension build log
12
+ '**/Makefile', # C Makefile
13
+ '**/conftest.dSYM', # OS X build directory
14
+ "**/*.#{CONFIG['DLEXT']}" # C shared object
15
+ )
16
+
17
+ if File::ALT_SEPARATOR
7
18
  STDERR.puts 'Not supported on this platform. Exiting.'
8
19
  exit(-1)
9
20
  end
10
21
 
11
- desc "Clean the build files for the io-extra source"
12
- task :clean do
13
- Dir['*.gem'].each{ |f| File.delete(f) }
14
- Dir['**/*.rbc'].each{ |f| File.delete(f) } # Rubinius
15
- rm_rf('io') if File.exists?('io')
16
-
17
- Dir.chdir('ext') do
18
- sh 'make distclean' if File.exists?('extra.o')
19
- rm_rf('extra/extra.c') if File.exists?('extra.c')
20
- rm_rf('conftest.dSYM') if File.exists?('conftest.dSYM') # OS X
21
- build_file = File.join(Dir.pwd, 'io', 'extra.' + Config::CONFIG['DLEXT'])
22
- File.delete(build_file) if File.exists?(build_file)
23
- end
24
- end
25
-
26
22
  desc "Build the io-extra library (but don't install it)"
27
23
  task :build => [:clean] do
28
24
  Dir.chdir('ext') do
29
25
  ruby 'extconf.rb'
30
26
  sh 'make'
31
- build_file = File.join(Dir.pwd, 'extra.' + Config::CONFIG['DLEXT'])
27
+ build_file = File.join(Dir.pwd, 'extra.' + CONFIG['DLEXT'])
32
28
  Dir.mkdir('io') unless File.exists?('io')
33
29
  FileUtils.cp(build_file, 'io')
34
30
  end
@@ -80,6 +76,13 @@ task :example => [:build] do
80
76
  ruby '-Iext examples/example_io_extra.rb'
81
77
  end
82
78
 
79
+ namespace :example do
80
+ desc "Run the IO.pread example program."
81
+ task :pread do
82
+ ruby '-Iext examples/example_io_extra.rb'
83
+ end
84
+ end
85
+
83
86
  Rake::TestTask.new do |t|
84
87
  task :test => :build
85
88
  t.libs << 'ext'
@@ -0,0 +1,24 @@
1
+ ########################################################################
2
+ # example_pread.rb
3
+ #
4
+ # Example program demonstrating the use of IO.pread.
5
+ ########################################################################
6
+ require 'io/extra'
7
+ require 'tmpdir'
8
+
9
+ # Create a temporary file with a little data in it.
10
+ file = File.join(Dir.tmpdir, 'pread_test.txt')
11
+ File.open(file, 'w'){ |fh| 100.times{ |n| fh.puts "Hello: #{n}" } }
12
+
13
+ # Read from the file using pread.
14
+ begin
15
+ fh = File.open(file)
16
+
17
+ puts "Handle position before read: #{fh.pos}"
18
+ puts IO.pread(fh.fileno, 18, 0)
19
+
20
+ puts "Handle position after read: #{fh.pos}"
21
+ puts IO.pread(fh.fileno, 18, 0)
22
+ ensure
23
+ fh.close
24
+ end
data/ext/extconf.rb CHANGED
@@ -16,7 +16,7 @@ have_func('writev')
16
16
  have_func('rb_str_set_len', 'ruby.h')
17
17
  have_func('rb_thread_blocking_region')
18
18
 
19
- case Config::CONFIG['host_os']
19
+ case RbConfig::CONFIG['host_os']
20
20
  when /darwin/i
21
21
  $CPPFLAGS += " -D_MACOS"
22
22
  when /linux/i
data/ext/io/extra.c CHANGED
@@ -324,7 +324,7 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
324
324
  static VALUE s_io_pread(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
325
325
  int fd = NUM2INT(v_fd);
326
326
  size_t nbyte = NUM2ULONG(v_nbyte);
327
- off_t offset = NUM2ULONG(v_offset);
327
+ off_t offset = NUM2OFFT(v_offset);
328
328
  VALUE str = rb_str_new(NULL, nbyte);
329
329
  ssize_t nread = pread(fd, RSTRING_PTR(str), nbyte, offset);
330
330
 
@@ -349,7 +349,7 @@ static VALUE s_io_pread(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
349
349
  static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
350
350
  int fd = NUM2INT(v_fd);
351
351
  size_t nbyte = NUM2ULONG(v_nbyte);
352
- off_t offset = NUM2ULONG(v_offset);
352
+ off_t offset = NUM2OFFT(v_offset);
353
353
  uintptr_t* vector = malloc(nbyte + 1);
354
354
 
355
355
  if(pread(fd, vector, nbyte, offset) == -1)
@@ -378,7 +378,7 @@ static VALUE s_io_pwrite(VALUE klass, VALUE v_fd, VALUE v_buf, VALUE v_offset){
378
378
  NUM2INT(v_fd),
379
379
  RSTRING_PTR(v_buf),
380
380
  RSTRING_LEN(v_buf),
381
- NUM2INT(v_offset)
381
+ NUM2OFFT(v_offset)
382
382
  );
383
383
 
384
384
  if(result == -1)
@@ -544,6 +544,6 @@ void Init_extra(){
544
544
  rb_define_singleton_method(rb_cIO, "writev", s_io_writev, 2);
545
545
  #endif
546
546
 
547
- /* 1.2.3: The version of this library. This a string. */
548
- rb_define_const(rb_cIO, "EXTRA_VERSION", rb_str_new2("1.2.3"));
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"));
549
549
  }
data/io-extra.gemspec CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |spec|
5
- if Config::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw/i
5
+ if RbConfig::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw/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.3'
11
+ spec.version = '1.2.4'
12
12
  spec.author = 'Daniel J. Berger'
13
13
  spec.license = 'Artistic 2.0'
14
14
  spec.email = 'djberg96@gmail.com'
@@ -18,19 +18,19 @@ class TC_IO_Extra < Test::Unit::TestCase
18
18
  @fh = File.open(@file, 'w+')
19
19
  @fh.puts "The quick brown fox jumped over the lazy dog's back"
20
20
  end
21
-
21
+
22
22
  def test_version
23
- assert_equal('1.2.3', IO::EXTRA_VERSION)
23
+ assert_equal('1.2.4', IO::EXTRA_VERSION)
24
24
  end
25
25
 
26
26
  def test_direct_constant
27
- omit_unless(Config::CONFIG['host_os'] =~ /linux/i, 'Linux-only')
27
+ omit_unless(RbConfig::CONFIG['host_os'] =~ /linux/i, 'Linux-only')
28
28
  assert_equal(040000, IO::DIRECT)
29
29
  assert_equal(040000, File::DIRECT)
30
30
  end
31
31
 
32
32
  def test_open_direct
33
- omit_unless(Config::CONFIG['host_os'] =~ /linux/i, 'Linux-only')
33
+ omit_unless(RbConfig::CONFIG['host_os'] =~ /linux/i, 'Linux-only')
34
34
  assert_nothing_raised do
35
35
  fh = File.open(@fh.path, IO::RDWR|IO::DIRECT)
36
36
  fh.close
@@ -38,20 +38,20 @@ class TC_IO_Extra < Test::Unit::TestCase
38
38
  end
39
39
 
40
40
  def test_directio
41
- omit_if(Config::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
41
+ omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
42
42
  assert_respond_to(@fh, :directio?)
43
43
  assert_nothing_raised{ @fh.directio? }
44
44
  end
45
45
 
46
46
  def test_directio_set
47
- omit_if(Config::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
47
+ omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
48
48
  assert_respond_to(@fh, :directio=)
49
49
  assert_raises(StandardError){ @fh.directio = 99 }
50
50
  assert_nothing_raised{ @fh.directio = IO::DIRECTIO_ON }
51
51
  end
52
52
 
53
53
  def test_constants
54
- omit_if(Config::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
54
+ omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
55
55
  assert_not_nil(IO::DIRECTIO_ON)
56
56
  assert_not_nil(IO::DIRECTIO_OFF)
57
57
  end
@@ -61,7 +61,7 @@ class TC_IO_Extra < Test::Unit::TestCase
61
61
  end
62
62
 
63
63
  def test_fdwalk
64
- omit_if(Config::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
64
+ omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
65
65
  assert_respond_to(IO, :fdwalk)
66
66
  assert_nothing_raised{ IO.fdwalk(0){ } }
67
67
  end
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: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
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: 2010-10-25 00:00:00 -06:00
18
+ date: 2011-03-22 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,16 +46,17 @@ extra_rdoc_files:
46
46
  - MANIFEST
47
47
  - ext/io/extra.c
48
48
  files:
49
- - CHANGES
49
+ - Rakefile
50
+ - README
50
51
  - doc/io_extra.txt
52
+ - io-extra.gemspec
53
+ - CHANGES
51
54
  - examples/example_io_extra.rb
55
+ - examples/example_pread.rb
56
+ - test/test_io_extra.rb
57
+ - MANIFEST
52
58
  - ext/extconf.rb
53
59
  - ext/io/extra.c
54
- - io-extra.gemspec
55
- - MANIFEST
56
- - Rakefile
57
- - README
58
- - test/test_io_extra.rb
59
60
  has_rdoc: true
60
61
  homepage: http://www.rubyforge.org/projects/shards
61
62
  licenses:
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  requirements: []
89
90
 
90
91
  rubyforge_project: shards
91
- rubygems_version: 1.3.7
92
+ rubygems_version: 1.6.2
92
93
  signing_key:
93
94
  specification_version: 3
94
95
  summary: Adds extra methods to the IO class.