yakg 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/Gemfile.lock +1 -1
  2. data/VERSION +1 -1
  3. data/lib/yakg.rb +2 -1
  4. data/vendor/gems/installit.sh +9 -5
  5. data/vendor/gems/ruby/1.8/gems/ffi-1.8.1/lib/ffi_c.bundle +0 -0
  6. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/CHANGELOG +12 -0
  7. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/LICENSE +8 -0
  8. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/README.md +40 -0
  9. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/array.rb +123 -0
  10. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/base.rb +197 -0
  11. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/boolean.rb +25 -0
  12. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/data.rb +42 -0
  13. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/date.rb +32 -0
  14. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/dictionary.rb +114 -0
  15. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/extensions.rb +158 -0
  16. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/null.rb +11 -0
  17. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/number.rb +98 -0
  18. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/string.rb +91 -0
  19. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/version.rb +4 -0
  20. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation.rb +13 -0
  21. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/array_spec.rb +92 -0
  22. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/boolean_spec.rb +24 -0
  23. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/data_spec.rb +30 -0
  24. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/date_spec.rb +25 -0
  25. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/dictionary_spec.rb +81 -0
  26. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/extensions_spec.rb +127 -0
  27. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/null_spec.rb +7 -0
  28. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/number_spec.rb +52 -0
  29. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/spec_helper.rb +10 -0
  30. data/vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/spec/string_spec.rb +48 -0
  31. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/.require_paths +2 -0
  32. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/COPYING +674 -0
  33. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/COPYING.LESSER +165 -0
  34. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/History.txt +1 -0
  35. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/LICENSE +14 -0
  36. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/README.md +109 -0
  37. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/Rakefile +219 -0
  38. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/ffi.gemspec +22 -0
  39. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/gen/Rakefile +30 -0
  40. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/gen/log +1 -0
  41. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/autopointer.rb +184 -0
  42. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/buffer.rb +4 -0
  43. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/callback.rb +4 -0
  44. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/enum.rb +162 -0
  45. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/errno.rb +33 -0
  46. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/ffi.iml +11 -0
  47. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/ffi.rb +33 -0
  48. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/io.rb +52 -0
  49. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/library.rb +489 -0
  50. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/managedstruct.rb +55 -0
  51. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/memorypointer.rb +1 -0
  52. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/arm-linux/types.conf +104 -0
  53. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  54. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-darwin/types.conf +100 -0
  55. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  56. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-linux/types.conf +103 -0
  57. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  58. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-openbsd/types.conf +126 -0
  59. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-solaris/types.conf +122 -0
  60. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i386-windows/types.conf +105 -0
  61. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/i486-gnu/types.conf +107 -0
  62. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/ia64-linux/types.conf +104 -0
  63. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/mips-linux/types.conf +102 -0
  64. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  65. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  66. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  67. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  68. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/s390-linux/types.conf +102 -0
  69. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/s390x-linux/types.conf +102 -0
  70. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/sparc-linux/types.conf +102 -0
  71. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  72. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  73. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
  74. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  75. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  76. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  77. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-openbsd/types.conf +126 -0
  78. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  79. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform/x86_64-windows/types.conf +27 -0
  80. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/platform.rb +139 -0
  81. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/pointer.rb +122 -0
  82. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/struct.rb +356 -0
  83. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/struct_layout_builder.rb +211 -0
  84. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/tools/const_generator.rb +229 -0
  85. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/tools/generator.rb +60 -0
  86. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/tools/generator_task.rb +36 -0
  87. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/tools/struct_generator.rb +194 -0
  88. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/tools/types_generator.rb +135 -0
  89. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/types.rb +177 -0
  90. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/union.rb +32 -0
  91. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/variadic.rb +65 -0
  92. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi/version.rb +4 -0
  93. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi.rb +28 -0
  94. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/lib/ffi_c.bundle +0 -0
  95. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/Benchmark.c +52 -0
  96. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/BoolTest.c +31 -0
  97. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/BufferTest.c +31 -0
  98. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/ClosureTest.c +190 -0
  99. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/EnumTest.c +34 -0
  100. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/FunctionTest.c +58 -0
  101. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/GNUmakefile +149 -0
  102. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/GlobalVariable.c +62 -0
  103. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/LastErrorTest.c +21 -0
  104. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/NumberTest.c +132 -0
  105. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/PointerTest.c +63 -0
  106. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/ReferenceTest.c +23 -0
  107. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/StringTest.c +34 -0
  108. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/StructTest.c +240 -0
  109. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/UnionTest.c +43 -0
  110. data/vendor/gems/ruby/1.9.1/gems/ffi-1.8.1/libtest/VariadicTest.c +62 -0
  111. data/vendor/gems/ruby/1.9.1/specifications/corefoundation-0.2.0.gemspec +44 -0
  112. data/vendor/gems/ruby/1.9.1/specifications/ffi-1.8.1.gemspec +43 -0
  113. metadata +172 -60
@@ -0,0 +1,184 @@
1
+ #
2
+ # Copyright (C) 2008-2010 Wayne Meissner
3
+ # Copyright (C) 2008 Mike Dalessio
4
+ #
5
+ # All rights reserved.
6
+ #
7
+ # This file is part of ruby-ffi.
8
+ #
9
+ # This code is free software: you can redistribute it and/or modify it under
10
+ # the terms of the GNU Lesser General Public License version 3 only, as
11
+ # published by the Free Software Foundation.
12
+ #
13
+ # This code is distributed in the hope that it will be useful, but WITHOUT
14
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16
+ # version 3 for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public License
19
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+ module FFI
23
+ class AutoPointer < Pointer
24
+ extend DataConverter
25
+
26
+ # @overload initialize(pointer, method)
27
+ # @param [Pointer] pointer
28
+ # @param [Method] method
29
+ # @return [self]
30
+ # The passed Method will be invoked at GC time.
31
+ # @overload initialize(pointer, proc)
32
+ # @param [Pointer] pointer
33
+ # @return [self]
34
+ # The passed Proc will be invoked at GC time (SEE WARNING BELOW!)
35
+ # @note WARNING: passing a proc _may_ cause your pointer to never be GC'd, unless you're
36
+ # careful to avoid trapping a reference to the pointer in the proc. See the test
37
+ # specs for examples.
38
+ # @overload initialize(pointer) { |p| ... }
39
+ # @param [Pointer] pointer
40
+ # @yieldparam [Pointer] p +pointer+ passed to the block
41
+ # @return [self]
42
+ # The passed block will be invoked at GC time.
43
+ # @note WARNING: passing a block will cause your pointer to never be GC'd. This is bad.
44
+ # @overload initialize(pointer)
45
+ # @param [Pointer] pointer
46
+ # @return [self]
47
+ # The pointer's release() class method will be invoked at GC time.
48
+ #
49
+ # @note The safest, and therefore preferred, calling
50
+ # idiom is to pass a Method as the second parameter. Example usage:
51
+ #
52
+ # class PointerHelper
53
+ # def self.release(pointer)
54
+ # ...
55
+ # end
56
+ # end
57
+ #
58
+ # p = AutoPointer.new(other_pointer, PointerHelper.method(:release))
59
+ #
60
+ # The above code will cause PointerHelper#release to be invoked at GC time.
61
+ #
62
+ # @note
63
+ # The last calling idiom (only one parameter) is generally only
64
+ # going to be useful if you subclass {AutoPointer}, and override
65
+ # #release, which by default does nothing.
66
+ def initialize(ptr, proc=nil, &block)
67
+ super(ptr.type_size, ptr)
68
+ raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \
69
+ || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
70
+
71
+ @releaser = if proc
72
+ raise RuntimeError.new("proc must be callable") unless proc.respond_to?(:call)
73
+ CallableReleaser.new(ptr, proc)
74
+
75
+ else
76
+ raise RuntimeError.new("no release method defined") unless self.class.respond_to?(:release)
77
+ DefaultReleaser.new(ptr, self.class)
78
+ end
79
+
80
+ ObjectSpace.define_finalizer(self, @releaser)
81
+ self
82
+ end
83
+
84
+ # @return [nil]
85
+ # Free the pointer.
86
+ def free
87
+ @releaser.free
88
+ end
89
+
90
+ # @param [Boolean] autorelease
91
+ # @return [Boolean] +autorelease+
92
+ # Set +autorelease+ property. See {Pointer Autorelease section at Pointer}.
93
+ def autorelease=(autorelease)
94
+ @releaser.autorelease=(autorelease)
95
+ end
96
+
97
+ # @return [Boolean] +autorelease+
98
+ # Get +autorelease+ property. See {Pointer Autorelease section at Pointer}.
99
+ def autorelease?
100
+ @releaser.autorelease
101
+ end
102
+
103
+ # @abstract Base class for {AutoPointer}'s releasers.
104
+ #
105
+ # All subclasses of Releaser should define a +#release(ptr)+ method.
106
+ # A releaser is an object in charge of release an {AutoPointer}.
107
+ class Releaser
108
+ attr_accessor :autorelease
109
+
110
+ # @param [Pointer] ptr
111
+ # @param [#call] proc
112
+ # @return [nil]
113
+ # A new instance of Releaser.
114
+ def initialize(ptr, proc)
115
+ @ptr = ptr
116
+ @proc = proc
117
+ @autorelease = true
118
+ end
119
+
120
+ # @return [nil]
121
+ # Free pointer.
122
+ def free
123
+ if @ptr
124
+ release(@ptr)
125
+ @autorelease = false
126
+ @ptr = nil
127
+ @proc = nil
128
+ end
129
+ end
130
+
131
+ # @param args
132
+ # Release pointer if +autorelease+ is set.
133
+ def call(*args)
134
+ release(@ptr) if @autorelease && @ptr
135
+ end
136
+
137
+ end
138
+
139
+ # DefaultReleaser is a {Releaser} used when an {AutoPointer} is defined without Proc
140
+ # or Method. In this case, the pointer to release must be of a class derived from
141
+ # AutoPointer with a +#release+ class method.
142
+ class DefaultReleaser < Releaser
143
+ # @param [Pointer] ptr
144
+ # @return [nil]
145
+ # Release +ptr+ by using his #release class method.
146
+ def release(ptr)
147
+ @proc.release(ptr)
148
+ end
149
+ end
150
+
151
+ # CallableReleaser is a {Releaser} used when an {AutoPointer} is defined with a
152
+ # Proc or a Method.
153
+ class CallableReleaser < Releaser
154
+ # @param [Pointer] ptr
155
+ # @return [nil]
156
+ # Release +ptr+ by using Proc or Method defined at +ptr+ {AutoPointer#initialize initialization}.
157
+ def release(ptr)
158
+ @proc.call(ptr)
159
+ end
160
+ end
161
+
162
+ # Return native type of AutoPointer.
163
+ #
164
+ # Override {DataConverter#native_type}.
165
+ # @return [Type::POINTER]
166
+ # @raise {RuntimeError} if class does not implement a +#release+ method
167
+ def self.native_type
168
+ raise RuntimeError.new("no release method defined for #{self.inspect}") unless self.respond_to?(:release)
169
+ Type::POINTER
170
+ end
171
+
172
+ # Create a new AutoPointer.
173
+ #
174
+ # Override {DataConverter#from_native}.
175
+ # @overload self.from_native(ptr, ctx)
176
+ # @param [Pointer] ptr
177
+ # @param ctx not used. Please set +nil+.
178
+ # @return [AutoPointer]
179
+ def self.from_native(val, ctx)
180
+ self.new(val)
181
+ end
182
+ end
183
+
184
+ end
@@ -0,0 +1,4 @@
1
+ #
2
+ # All the code from this file is now implemented in C. This file remains
3
+ # to satisfy any leftover require 'ffi/buffer' in user code
4
+ #
@@ -0,0 +1,4 @@
1
+ #
2
+ # All the code from this file is now implemented in C. This file remains
3
+ # to satisfy any leftover require 'ffi/callback' in user code
4
+ #
@@ -0,0 +1,162 @@
1
+ #
2
+ # Copyright (C) 2009, 2010 Wayne Meissner
3
+ # Copyright (C) 2009 Luc Heinrich
4
+ #
5
+ # All rights reserved.
6
+ #
7
+ # This file is part of ruby-ffi.
8
+ #
9
+ # This code is free software: you can redistribute it and/or modify it under
10
+ # the terms of the GNU Lesser General Public License version 3 only, as
11
+ # published by the Free Software Foundation.
12
+ #
13
+ # This code is distributed in the hope that it will be useful, but WITHOUT
14
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16
+ # version 3 for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public License
19
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+ module FFI
23
+
24
+ # An instance of this class permits to manage {Enum}s. In fact, Enums is a collection of {Enum}s.
25
+ class Enums
26
+
27
+ # @return [nil]
28
+ def initialize
29
+ @all_enums = Array.new
30
+ @tagged_enums = Hash.new
31
+ @symbol_map = Hash.new
32
+ end
33
+
34
+ # @param [Enum] enum
35
+ # Add an {Enum} to the collection.
36
+ def <<(enum)
37
+ @all_enums << enum
38
+ @tagged_enums[enum.tag] = enum unless enum.tag.nil?
39
+ @symbol_map.merge!(enum.symbol_map)
40
+ end
41
+
42
+ # @param query enum tag or part of an enum name
43
+ # @return [Enum]
44
+ # Find a {Enum} in collection.
45
+ def find(query)
46
+ if @tagged_enums.has_key?(query)
47
+ @tagged_enums[query]
48
+ else
49
+ @all_enums.detect { |enum| enum.symbols.include?(query) }
50
+ end
51
+ end
52
+
53
+ # @param symbol a symbol to find in merge symbol maps of all enums.
54
+ # @return a symbol
55
+ def __map_symbol(symbol)
56
+ @symbol_map[symbol]
57
+ end
58
+
59
+ end
60
+
61
+ # Represents a C enum.
62
+ #
63
+ # For a C enum:
64
+ # enum fruits {
65
+ # apple,
66
+ # banana,
67
+ # orange,
68
+ # pineapple
69
+ # };
70
+ # are defined this vocabulary:
71
+ # * a _symbol_ is a word from the enumeration (ie. _apple_, by example);
72
+ # * a _value_ is the value of a symbol in the enumeration (by example, apple has value _0_ and banana _1_).
73
+ class Enum
74
+ include DataConverter
75
+
76
+ attr_reader :tag
77
+
78
+ # @param [nil, Enumerable] info
79
+ # @param tag enum tag
80
+ def initialize(info, tag=nil)
81
+ @tag = tag
82
+ @kv_map = Hash.new
83
+ unless info.nil?
84
+ last_cst = nil
85
+ value = 0
86
+ info.each do |i|
87
+ case i
88
+ when Symbol
89
+ raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i)
90
+ @kv_map[i] = value
91
+ last_cst = i
92
+ value += 1
93
+ when Integer
94
+ @kv_map[last_cst] = i
95
+ value = i+1
96
+ end
97
+ end
98
+ end
99
+ @vk_map = @kv_map.invert
100
+ end
101
+
102
+ # @return [Array] enum symbol names
103
+ def symbols
104
+ @kv_map.keys
105
+ end
106
+
107
+ # Get a symbol or a value from the enum.
108
+ # @overload [](query)
109
+ # Get enum value from symbol.
110
+ # @param [Symbol] query
111
+ # @return [Integer]
112
+ # @overload [](query)
113
+ # Get enum symbol from value.
114
+ # @param [Integer] query
115
+ # @return [Symbol]
116
+ def [](query)
117
+ case query
118
+ when Symbol
119
+ @kv_map[query]
120
+ when Integer
121
+ @vk_map[query]
122
+ end
123
+ end
124
+ alias find []
125
+
126
+ # Get the symbol map.
127
+ # @return [Hash]
128
+ def symbol_map
129
+ @kv_map
130
+ end
131
+
132
+ alias to_h symbol_map
133
+ alias to_hash symbol_map
134
+
135
+ # Get native type of Enum
136
+ # @return [Type::INT]
137
+ def native_type
138
+ Type::INT
139
+ end
140
+
141
+ # @param [Symbol, Integer, #to_int] val
142
+ # @param ctx unused
143
+ # @return [Integer] value of a enum symbol
144
+ def to_native(val, ctx)
145
+ @kv_map[val] || if val.is_a?(Integer)
146
+ val
147
+ elsif val.respond_to?(:to_int)
148
+ val.to_int
149
+ else
150
+ raise ArgumentError, "invalid enum value, #{val.inspect}"
151
+ end
152
+ end
153
+
154
+ # @param val
155
+ # @return symbol name if it exists for +val+.
156
+ def from_native(val, ctx)
157
+ @vk_map[val] || val
158
+ end
159
+
160
+ end
161
+
162
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2008-2010 Wayne Meissner
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # This file is part of ruby-ffi.
7
+ #
8
+ # This code is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Lesser General Public License version 3 only, as
10
+ # published by the Free Software Foundation.
11
+ #
12
+ # This code is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ # version 3 for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module FFI
22
+ # @return (see FFI::LastError.error)
23
+ # @see FFI::LastError.error
24
+ def self.errno
25
+ FFI::LastError.error
26
+ end
27
+ # @param error (see FFI::LastError.error=)
28
+ # @return (see FFI::LastError.error=)
29
+ # @see FFI::LastError.error=
30
+ def self.errno=(error)
31
+ FFI::LastError.error = error
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="jdk" jdkName="RVM: jruby-1.6.8" jdkType="JRUBY_SDK" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.0.0, RVM: jruby-1.6.8) [gem]" level="application" />
9
+ </component>
10
+ </module>
11
+
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2008-2010 JRuby project
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # This file is part of ruby-ffi.
7
+ #
8
+ # This code is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Lesser General Public License version 3 only, as
10
+ # published by the Free Software Foundation.
11
+ #
12
+ # This code is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ # version 3 for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'ffi/platform'
21
+ require 'ffi/types'
22
+ require 'ffi/library'
23
+ require 'ffi/errno'
24
+ require 'ffi/pointer'
25
+ require 'ffi/memorypointer'
26
+ require 'ffi/struct'
27
+ require 'ffi/union'
28
+ require 'ffi/managedstruct'
29
+ require 'ffi/callback'
30
+ require 'ffi/io'
31
+ require 'ffi/autopointer'
32
+ require 'ffi/variadic'
33
+ require 'ffi/enum'
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright (C) 2008, 2009 Wayne Meissner
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # This file is part of ruby-ffi.
7
+ #
8
+ # This code is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Lesser General Public License version 3 only, as
10
+ # published by the Free Software Foundation.
11
+ #
12
+ # This code is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ # version 3 for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module FFI
22
+
23
+ # This module implements a couple of class methods to play with IO.
24
+ module IO
25
+ # @param [Integer] fd file decriptor
26
+ # @param [String] mode mode string
27
+ # @return [::IO]
28
+ # Synonym for IO::for_fd.
29
+ def self.for_fd(fd, mode = "r")
30
+ ::IO.for_fd(fd, mode)
31
+ end
32
+
33
+ # @param [#read] io io to read from
34
+ # @param [AbstractMemory] buf destination for data read from +io+
35
+ # @param [nil, Numeric] len maximul number of bytes to read from +io+. If +nil+,
36
+ # read until end of file.
37
+ # @return [Numeric] length really read, in bytes
38
+ #
39
+ # A version of IO#read that reads data from an IO and put then into a native buffer.
40
+ #
41
+ # This will be optimized at some future time to eliminate the double copy.
42
+ #
43
+ def self.native_read(io, buf, len)
44
+ tmp = io.read(len)
45
+ return -1 unless tmp
46
+ buf.put_bytes(0, tmp)
47
+ tmp.length
48
+ end
49
+
50
+ end
51
+ end
52
+