ffi 1.6.0 → 1.7.0.dev
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.
- checksums.yaml +4 -4
- data/ext/ffi_c/MethodHandle.c +1 -1
- data/ext/ffi_c/Pointer.c +11 -0
- data/ext/ffi_c/{Ffi_c.iml → cruby-ext.iml} +0 -0
- data/ffi.gemspec +1 -1
- data/lib/ffi/autopointer.rb +1 -1
- data/lib/ffi/ffi.iml +11 -0
- data/spec/ffi/pointer_spec.rb +49 -0
- data/spec/ffi/{Ffi.iml → spec.iml} +2 -2
- data/spec/ffi/struct_by_ref_spec.rb +43 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e0e169711bac631dcc3627cd32335671f3e931
|
4
|
+
data.tar.gz: 204499b27f918bb2a373c565c01f3ebb65f77e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6503891a4924031002825708c8b02d04451defa6e958953c038e1e483d7491d2e12db7309d3fd83b75e2d239cc88cc17d101328714da11b4dd77d7a2117526bd
|
7
|
+
data.tar.gz: 9f8bdcf6cdd408fa7690b5c881e801818ed10f8805b38d711f490c3adafca9408a9a957cbe46fe2a70606bdbf718321be857e4db4a667728dc9c61b399c43841
|
data/ext/ffi_c/MethodHandle.c
CHANGED
@@ -77,7 +77,7 @@ typedef int bool;
|
|
77
77
|
static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
|
78
78
|
static long trampoline_size(void);
|
79
79
|
|
80
|
-
#if defined(__x86_64__) && defined(
|
80
|
+
#if defined(__x86_64__) && (defined(__linux__) || defined(__APPLE__))
|
81
81
|
# define CUSTOM_TRAMPOLINE 1
|
82
82
|
#endif
|
83
83
|
|
data/ext/ffi_c/Pointer.c
CHANGED
@@ -396,6 +396,16 @@ ptr_free(VALUE self)
|
|
396
396
|
return self;
|
397
397
|
}
|
398
398
|
|
399
|
+
static VALUE
|
400
|
+
ptr_type_size(VALUE self)
|
401
|
+
{
|
402
|
+
Pointer* ptr;
|
403
|
+
|
404
|
+
Data_Get_Struct(self, Pointer, ptr);
|
405
|
+
|
406
|
+
return INT2NUM(ptr->memory.typeSize);
|
407
|
+
}
|
408
|
+
|
399
409
|
/*
|
400
410
|
* call-seq: ptr.autorelease = autorelease
|
401
411
|
* @param [Boolean] autorelease
|
@@ -481,6 +491,7 @@ rbffi_Pointer_Init(VALUE moduleFFI)
|
|
481
491
|
rb_define_method(rbffi_PointerClass, "autorelease=", ptr_autorelease, 1);
|
482
492
|
rb_define_method(rbffi_PointerClass, "autorelease?", ptr_autorelease_p, 0);
|
483
493
|
rb_define_method(rbffi_PointerClass, "free", ptr_free, 0);
|
494
|
+
rb_define_method(rbffi_PointerClass, "type_size", ptr_type_size, 0);
|
484
495
|
|
485
496
|
rbffi_NullPointerSingleton = rb_class_new_instance(1, &rbNullAddress, rbffi_PointerClass);
|
486
497
|
/*
|
File without changes
|
data/ffi.gemspec
CHANGED
data/lib/ffi/autopointer.rb
CHANGED
@@ -64,7 +64,7 @@ module FFI
|
|
64
64
|
# going to be useful if you subclass {AutoPointer}, and override
|
65
65
|
# #release, which by default does nothing.
|
66
66
|
def initialize(ptr, proc=nil, &block)
|
67
|
-
super(ptr)
|
67
|
+
super(ptr.type_size, ptr)
|
68
68
|
raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \
|
69
69
|
|| ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
|
70
70
|
|
data/lib/ffi/ffi.iml
ADDED
@@ -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
|
+
|
data/spec/ffi/pointer_spec.rb
CHANGED
@@ -99,6 +99,36 @@ describe "Pointer" do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
it "Pointer.size returns sizeof pointer on platform" do
|
103
|
+
FFI::Pointer.size.should == (FFI::Platform::ADDRESS_SIZE / 8)
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#slice" do
|
107
|
+
before(:each) do
|
108
|
+
@mptr = FFI::MemoryPointer.new(:char, 12)
|
109
|
+
@mptr.put_uint(0, 0x12345678)
|
110
|
+
@mptr.put_uint(4, 0xdeadbeef)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "contents of sliced pointer matches original pointer at offset" do
|
114
|
+
@mptr.slice(4, 4).get_uint(0).should == 0xdeadbeef
|
115
|
+
end
|
116
|
+
|
117
|
+
it "modifying sliced pointer is reflected in original pointer" do
|
118
|
+
@mptr.slice(4, 4).put_uint(0, 0xfee1dead)
|
119
|
+
@mptr.get_uint(4).should == 0xfee1dead
|
120
|
+
end
|
121
|
+
|
122
|
+
it "access beyond bounds should raise IndexError" do
|
123
|
+
lambda { @mptr.slice(4, 4).get_int(4) }.should raise_error(IndexError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#type_size" do
|
128
|
+
it "should be same as FFI.type_size(type)" do
|
129
|
+
FFI::MemoryPointer.new(:int, 1).type_size.should == FFI.type_size(:int)
|
130
|
+
end
|
131
|
+
end
|
102
132
|
end
|
103
133
|
|
104
134
|
describe "AutoPointer" do
|
@@ -212,5 +242,24 @@ describe "AutoPointer" do
|
|
212
242
|
end
|
213
243
|
end
|
214
244
|
|
245
|
+
describe "#type_size" do
|
246
|
+
ptr_class = Class.new(FFI::AutoPointer) do
|
247
|
+
def self.release(ptr); end
|
248
|
+
end
|
249
|
+
|
250
|
+
it "type_size of AutoPointer should match wrapped Pointer" do
|
251
|
+
aptr = ptr_class.new(FFI::Pointer.new(:int, 0xdeadbeef))
|
252
|
+
aptr.type_size.should == FFI.type_size(:int)
|
253
|
+
end
|
254
|
+
|
255
|
+
it "[] offset should match wrapped Pointer" do
|
256
|
+
mptr = FFI::MemoryPointer.new(:int, 1024)
|
257
|
+
aptr = ptr_class.new(FFI::Pointer.new(:int, mptr))
|
258
|
+
aptr[0].write_uint(0xfee1dead)
|
259
|
+
aptr[1].write_uint(0xcafebabe)
|
260
|
+
mptr[0].read_uint.should == 0xfee1dead
|
261
|
+
mptr[1].read_uint.should == 0xcafebabe
|
262
|
+
end
|
263
|
+
end
|
215
264
|
end
|
216
265
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<module type="RUBY_MODULE" version="4">
|
3
3
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
4
|
<exclude-output />
|
5
|
-
<content url="file://$MODULE_DIR
|
6
|
-
<sourceFolder url="file://$MODULE_DIR
|
5
|
+
<content url="file://$MODULE_DIR$/..">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$/.." isTestSource="true" />
|
7
7
|
</content>
|
8
8
|
<orderEntry type="inheritedJdk" />
|
9
9
|
<orderEntry type="sourceFolder" forTests="false" />
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of ruby-ffi.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
7
|
+
|
8
|
+
describe FFI::Struct, ' by_ref' do
|
9
|
+
before :all do
|
10
|
+
@struct_class = struct_class = Class.new(FFI::Struct) do
|
11
|
+
layout :a, :pointer
|
12
|
+
end
|
13
|
+
|
14
|
+
@api = Module.new do
|
15
|
+
extend FFI::Library
|
16
|
+
ffi_lib TestLibrary::PATH
|
17
|
+
fn = FFI::Type::POINTER.size == FFI::Type::LONG.size ? :ret_ulong : ret_uint64_t
|
18
|
+
attach_function :struct_test, fn, [ struct_class.by_ref ], :pointer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept instances of exact struct class" do
|
23
|
+
s = @struct_class.new
|
24
|
+
@api.struct_test(s).should == s.pointer
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should accept nil" do
|
28
|
+
@api.struct_test(nil).should == nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should reject other types" do
|
32
|
+
lambda { @api.struct_test('test').should == nil }.should raise_error(TypeError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should reject instances of other struct classes" do
|
36
|
+
other_class = Class.new(FFI::Struct) do
|
37
|
+
layout :a, :pointer
|
38
|
+
end
|
39
|
+
|
40
|
+
lambda { @api.struct_test(other_class.new) }.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0.dev
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Meissner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -76,12 +76,12 @@ files:
|
|
76
76
|
- ext/ffi_c/ClosurePool.c
|
77
77
|
- ext/ffi_c/ClosurePool.h
|
78
78
|
- ext/ffi_c/compat.h
|
79
|
+
- ext/ffi_c/cruby-ext.iml
|
79
80
|
- ext/ffi_c/DataConverter.c
|
80
81
|
- ext/ffi_c/DynamicLibrary.c
|
81
82
|
- ext/ffi_c/DynamicLibrary.h
|
82
83
|
- ext/ffi_c/extconf.rb
|
83
84
|
- ext/ffi_c/ffi.c
|
84
|
-
- ext/ffi_c/Ffi_c.iml
|
85
85
|
- ext/ffi_c/Function.c
|
86
86
|
- ext/ffi_c/Function.h
|
87
87
|
- ext/ffi_c/FunctionInfo.c
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- lib/ffi/callback.rb
|
401
401
|
- lib/ffi/enum.rb
|
402
402
|
- lib/ffi/errno.rb
|
403
|
+
- lib/ffi/ffi.iml
|
403
404
|
- lib/ffi/ffi.rb
|
404
405
|
- lib/ffi/io.rb
|
405
406
|
- lib/ffi/library.rb
|
@@ -455,7 +456,6 @@ files:
|
|
455
456
|
- spec/ffi/dup_spec.rb
|
456
457
|
- spec/ffi/enum_spec.rb
|
457
458
|
- spec/ffi/errno_spec.rb
|
458
|
-
- spec/ffi/Ffi.iml
|
459
459
|
- spec/ffi/ffi_spec.rb
|
460
460
|
- spec/ffi/function_spec.rb
|
461
461
|
- spec/ffi/library_spec.rb
|
@@ -467,9 +467,11 @@ files:
|
|
467
467
|
- spec/ffi/rbx/memory_pointer_spec.rb
|
468
468
|
- spec/ffi/rbx/spec_helper.rb
|
469
469
|
- spec/ffi/rbx/struct_spec.rb
|
470
|
+
- spec/ffi/spec.iml
|
470
471
|
- spec/ffi/spec_helper.rb
|
471
472
|
- spec/ffi/string_spec.rb
|
472
473
|
- spec/ffi/strptr_spec.rb
|
474
|
+
- spec/ffi/struct_by_ref_spec.rb
|
473
475
|
- spec/ffi/struct_callback_spec.rb
|
474
476
|
- spec/ffi/struct_initialize_spec.rb
|
475
477
|
- spec/ffi/struct_packed_spec.rb
|
@@ -512,9 +514,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
512
514
|
version: 1.8.7
|
513
515
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
514
516
|
requirements:
|
515
|
-
- - '
|
517
|
+
- - '>'
|
516
518
|
- !ruby/object:Gem::Version
|
517
|
-
version:
|
519
|
+
version: 1.3.1
|
518
520
|
requirements: []
|
519
521
|
rubyforge_project:
|
520
522
|
rubygems_version: 2.0.0
|