ffi 1.2.0.pre2 → 1.2.0.pre3

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);
@@ -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,78 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
- version: !ruby/object:Gem::Version
4
- hash: -1049754034
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0.pre3
5
5
  prerelease: 6
6
- segments:
7
- - 1
8
- - 2
9
- - 0
10
- - pre
11
- - 2
12
- version: 1.2.0.pre2
13
6
  platform: ruby
14
- authors:
7
+ authors:
15
8
  - Wayne Meissner
16
9
  autorequire:
17
10
  bindir: bin
18
11
  cert_chain: []
19
-
20
- date: 2012-11-01 00:00:00 +11:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
24
15
  name: rake
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
27
17
  none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 3
32
- segments:
33
- - 0
34
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
35
22
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rake-compiler
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
41
25
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 0
48
- - 6
49
- - 0
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake-compiler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
50
37
  version: 0.6.0
51
38
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
39
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
65
54
  type: :development
66
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
67
62
  description: Ruby FFI library
68
63
  email: wmeissner@gmail.com
69
64
  executables: []
70
-
71
- extensions:
65
+ extensions:
72
66
  - ext/ffi_c/extconf.rb
73
67
  extra_rdoc_files: []
74
-
75
- files:
68
+ files:
76
69
  - History.txt
77
70
  - LICENSE
78
71
  - COPYING
@@ -507,45 +500,31 @@ files:
507
500
  - libtest/StructTest.c
508
501
  - libtest/UnionTest.c
509
502
  - libtest/VariadicTest.c
510
- has_rdoc: true
511
503
  homepage: http://wiki.github.com/ffi/ffi
512
- licenses:
504
+ licenses:
513
505
  - LGPL-3
514
506
  post_install_message:
515
507
  rdoc_options: []
516
-
517
- require_paths:
508
+ require_paths:
518
509
  - lib
519
510
  - lib/ffi
520
511
  - ext/ffi_c
521
- required_ruby_version: !ruby/object:Gem::Requirement
512
+ required_ruby_version: !ruby/object:Gem::Requirement
522
513
  none: false
523
- requirements:
524
- - - ">="
525
- - !ruby/object:Gem::Version
526
- hash: 57
527
- segments:
528
- - 1
529
- - 8
530
- - 7
514
+ requirements:
515
+ - - ! '>='
516
+ - !ruby/object:Gem::Version
531
517
  version: 1.8.7
532
- required_rubygems_version: !ruby/object:Gem::Requirement
518
+ required_rubygems_version: !ruby/object:Gem::Requirement
533
519
  none: false
534
- requirements:
535
- - - ">"
536
- - !ruby/object:Gem::Version
537
- hash: 25
538
- segments:
539
- - 1
540
- - 3
541
- - 1
520
+ requirements:
521
+ - - ! '>'
522
+ - !ruby/object:Gem::Version
542
523
  version: 1.3.1
543
524
  requirements: []
544
-
545
525
  rubyforge_project:
546
- rubygems_version: 1.6.2
526
+ rubygems_version: 1.8.24
547
527
  signing_key:
548
528
  specification_version: 3
549
529
  summary: Ruby FFI
550
530
  test_files: []
551
-