ffi_dry 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ === 0.1.12 / 2010-11-8
2
+ * Added ffi/dry/errno for handling errno errors from FFI-bound functions
3
+
1
4
  === 0.1.11 / 2010-6-2
2
5
  * Added attach_optional_function to FFI::Library for dealing with functions
3
6
  that are not always present.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.1.12
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ffi_dry}
8
- s.version = "0.1.11"
8
+ s.version = "0.1.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eric Monti"]
12
- s.date = %q{2010-06-02}
12
+ s.date = %q{2010-11-08}
13
13
  s.description = %q{Provides some useful modules, classes, and methods for FFI bindings as well as a DSL-like syntax for FFI::Struct layouts}
14
14
  s.email = %q{emonti@matasano.com}
15
15
  s.extra_rdoc_files = [
@@ -26,10 +26,12 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "ffi_dry.gemspec",
28
28
  "lib/ffi/dry.rb",
29
+ "lib/ffi/dry/errno.rb",
29
30
  "lib/ffi_dry.rb",
30
31
  "samples/afmap.rb",
31
32
  "samples/basic.rb",
32
33
  "samples/describer.rb",
34
+ "spec/errno_spec.rb",
33
35
  "spec/ffi_dry_spec.rb",
34
36
  "spec/spec_helper.rb"
35
37
  ]
@@ -39,7 +41,8 @@ Gem::Specification.new do |s|
39
41
  s.rubygems_version = %q{1.3.6}
40
42
  s.summary = %q{Syntactic sugar and helper utilities for FFI}
41
43
  s.test_files = [
42
- "spec/ffi_dry_spec.rb",
44
+ "spec/errno_spec.rb",
45
+ "spec/ffi_dry_spec.rb",
43
46
  "spec/spec_helper.rb"
44
47
  ]
45
48
 
@@ -0,0 +1,37 @@
1
+ require 'ffi'
2
+
3
+ module FFI
4
+ module DRY
5
+ # This module lets us handle FFI-generated system call errors
6
+ # through ruby as exceptions using the Errno and SystemCallError
7
+ # exception classes.
8
+ #
9
+ # This module is not automatically included in the runtime when you
10
+ # include 'ffi/dry'. You must explicitely say
11
+ #
12
+ # require 'ffi/dry/errno'
13
+ #
14
+ module ErrnoHelper
15
+ extend FFI::Library
16
+ libs = ffi_lib FFI::Library::LIBC
17
+
18
+ attach_function :strerror, [:int], :string
19
+
20
+ # Returns a ruby exception derived from the current value of errno.
21
+ # As per the intro(2) manpage, this should only ever be called after an
22
+ # error has been deteted from a function that sets the errno variable.
23
+ def errno_exception(arg=nil)
24
+ err = self.errno
25
+ return SystemCallError.new(arg, err)
26
+ end
27
+
28
+ # An alias for FFI.errno
29
+ def errno
30
+ FFI.errno
31
+ end
32
+
33
+ end
34
+
35
+ extend ErrnoHelper
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ require 'ffi/dry/errno'
2
+
3
+ module TestLib
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ attach_function :fopen, [:string, :string], :pointer
7
+ end
8
+
9
+
10
+ describe FFI::DRY::ErrnoHelper do
11
+ it "should supply errno errors as exceptions" do
12
+ filename = "/veryboguspath/bogus filename#{rand(0xffff)}"
13
+ TestLib.fopen(filename, 'r').should be_null
14
+
15
+ exc1 = FFI::DRY.errno_exception
16
+ exc1.should be_kind_of(Errno::ENOENT)
17
+ end
18
+
19
+ it "should take an optional argument for additional error info" do
20
+ filename = "/veryboguspath/bogus filename#{rand(0xffff)}"
21
+ TestLib.fopen(filename, 'r').should be_null
22
+
23
+ exc2 = FFI::DRY.errno_exception(filename)
24
+ exc2.should be_kind_of(Errno::ENOENT)
25
+
26
+ exc2.message.index(filename).should_not be_nil
27
+ end
28
+
29
+
30
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 11
9
- version: 0.1.11
8
+ - 12
9
+ version: 0.1.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eric Monti
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-02 00:00:00 -05:00
17
+ date: 2010-11-08 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,10 +50,12 @@ files:
50
50
  - VERSION
51
51
  - ffi_dry.gemspec
52
52
  - lib/ffi/dry.rb
53
+ - lib/ffi/dry/errno.rb
53
54
  - lib/ffi_dry.rb
54
55
  - samples/afmap.rb
55
56
  - samples/basic.rb
56
57
  - samples/describer.rb
58
+ - spec/errno_spec.rb
57
59
  - spec/ffi_dry_spec.rb
58
60
  - spec/spec_helper.rb
59
61
  has_rdoc: true
@@ -87,5 +89,6 @@ signing_key:
87
89
  specification_version: 3
88
90
  summary: Syntactic sugar and helper utilities for FFI
89
91
  test_files:
92
+ - spec/errno_spec.rb
90
93
  - spec/ffi_dry_spec.rb
91
94
  - spec/spec_helper.rb