ffi 1.2.0.pre2-x86-mingw32 → 1.2.0.pre3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

data/Rakefile CHANGED
@@ -167,6 +167,32 @@ task 'gem:win32' do
167
167
  end
168
168
 
169
169
 
170
+ namespace 'java' do
171
+
172
+ java_gem_spec = Gem::Specification.new do |s|
173
+ s.name = gem_spec.name
174
+ s.version = gem_spec.version
175
+ s.author = gem_spec.author
176
+ s.email = gem_spec.email
177
+ s.homepage = gem_spec.homepage
178
+ s.summary = gem_spec.summary
179
+ s.description = gem_spec.description
180
+ s.files = %w(History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile)
181
+ s.has_rdoc = false
182
+ s.license = gem_spec.license
183
+ s.platform = 'java'
184
+ end
185
+
186
+ Gem::PackageTask.new(java_gem_spec) do |pkg|
187
+ pkg.need_zip = true
188
+ pkg.need_tar = true
189
+ pkg.package_dir = 'pkg'
190
+ end
191
+ end
192
+
193
+ task 'gem:java' => 'java:gem'
194
+
195
+
170
196
  if USE_RAKE_COMPILER
171
197
  Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
172
198
  ext.name = 'ffi_c' # indicate the name of the extension.
@@ -493,7 +493,7 @@ inline_array_size(VALUE self)
493
493
  static int
494
494
  inline_array_offset(InlineArray* array, int index)
495
495
  {
496
- if (index < 0 || index >= array->length) {
496
+ if (index < 0 || (index >= array->length && array->length > 0)) {
497
497
  rb_raise(rb_eIndexError, "index %d out of bounds", index);
498
498
  }
499
499
 
@@ -388,7 +388,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
388
388
  }
389
389
 
390
390
  ftype = field->type->ffiType;
391
- if (ftype->size == 0) {
391
+ if (ftype->size == 0 && i < ((int) layout->fieldCount - 1)) {
392
392
  rb_raise(rb_eTypeError, "type of field %d has zero size", i);
393
393
  }
394
394
 
@@ -396,7 +396,8 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
396
396
  field->referenceIndex = layout->referenceFieldCount++;
397
397
  }
398
398
 
399
- layout->ffiTypes[i] = ftype;
399
+
400
+ layout->ffiTypes[i] = ftype->size > 0 ? ftype : NULL;
400
401
  st_insert(layout->fieldSymbolTable, rbName, rbField);
401
402
  rb_hash_aset(layout->rbFieldMap, rbName, rbField);
402
403
  rb_ary_push(layout->rbFields, rbField);
Binary file
Binary file
@@ -7,7 +7,6 @@
7
7
  </content>
8
8
  <orderEntry type="inheritedJdk" />
9
9
  <orderEntry type="sourceFolder" forTests="false" />
10
- <orderEntry type="library" scope="PROVIDED" name="rake (v0.8.7, RVM: ruby-1.8.7-p357) [gem]" level="application" />
11
10
  </component>
12
11
  </module>
13
12
 
@@ -171,6 +171,43 @@ describe "Reading/Writing binary strings" do
171
171
  str = "hello\0world"
172
172
  buf = FFI::Buffer.new 1024
173
173
  lambda { buf.put_bytes(0, str, -1, 12); }.should raise_error
174
+ end
175
+
176
+ it "Buffer#write_bytes" do
177
+ str = "hello\0world"
178
+ buf = FFI::Buffer.new 1024
179
+ buf.write_bytes(str)
180
+ s2 = buf.get_bytes(0, 11)
181
+ s2.should eq str
182
+ end
183
+ it "Buffer#write_bytes with index and length" do
184
+ str = "hello\0world"
185
+ buf = FFI::Buffer.new 1024
186
+ buf.write_bytes(str, 5, 6)
187
+ s2 = buf.get_bytes(0, 6)
188
+ s2.should eq str[5..-1]
189
+ end
190
+ it "Buffer#write_bytes with only index" do
191
+ str = "hello\0world"
192
+ buf = FFI::Buffer.new 1024
193
+ buf.write_bytes(str, 5)
194
+ s2 = buf.get_bytes(0, 6)
195
+ s2.should eq str[5..-1]
196
+ end
197
+ it "Buffer#write_bytes with index > str.length" do
198
+ str = "hello\0world"
199
+ buf = FFI::Buffer.new 1024
200
+ lambda { buf.write_bytes(str, 12) }.should raise_error
201
+ end
202
+ it "Buffer#put_bytes with length > str.length" do
203
+ str = "hello\0world"
204
+ buf = FFI::Buffer.new 1024
205
+ lambda { buf.put_bytes(0, str, 0, 12) }.should raise_error
206
+ end
207
+ it "Buffer#write_bytes with negative index" do
208
+ str = "hello\0world"
209
+ buf = FFI::Buffer.new 1024
210
+ lambda { buf.write_bytes(str, -1, 12) }.should raise_error
174
211
  end
175
212
  end
176
213
  describe "Reading/Writing ascii strings" do
@@ -717,3 +717,43 @@ describe "Struct allocation" do
717
717
  end
718
718
 
719
719
  end
720
+
721
+ describe "variable-length arrays" do
722
+ it "zero length array should be accepted as last field" do
723
+ lambda {
724
+ Class.new(FFI::Struct) do
725
+ layout :count, :int, :data, [ :char, 0 ]
726
+ end
727
+ }.should_not raise_error
728
+ end
729
+
730
+ it "zero length array before last element should raise error" do
731
+ lambda {
732
+ Class.new(FFI::Struct) do
733
+ layout :data, [ :char, 0 ], :count, :int
734
+ end
735
+ }.should raise_error
736
+ end
737
+
738
+ it "can access elements of array" do
739
+ struct_class = Class.new(FFI::Struct) do
740
+ layout :count, :int, :data, [ :long, 0 ]
741
+ end
742
+ s = struct_class.new(FFI::MemoryPointer.new(1024))
743
+ s[:data][0] = 0xdeadbeef
744
+ s[:data][1] = 0xfee1dead
745
+ s[:data][0].should eq 0xdeadbeef
746
+ s[:data][1].should eq 0xfee1dead
747
+ end
748
+
749
+ it "non-variable length array is bounds checked" do
750
+ struct_class = Class.new(FFI::Struct) do
751
+ layout :count, :int, :data, [ :long, 1 ]
752
+ end
753
+ s = struct_class.new(FFI::MemoryPointer.new(1024))
754
+ s[:data][0] = 0xdeadbeef
755
+ lambda { s[:data][1] = 0xfee1dead }.should raise_error
756
+ s[:data][0].should eq 0xdeadbeef
757
+ lambda { s[:data][1].should eq 0xfee1dead }.should raise_error
758
+ end
759
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1308335528
4
+ hash: -810651450
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
9
  - 0
10
10
  - pre
11
- - 2
12
- version: 1.2.0.pre2
11
+ - 3
12
+ version: 1.2.0.pre3
13
13
  platform: x86-mingw32
14
14
  authors:
15
15
  - Wayne Meissner
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-11-07 00:00:00 Z
20
+ date: 2012-11-11 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  prerelease: false