gir_ffi 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/ffi-glib/ptr_array.rb +1 -1
- data/lib/ffi-gobject_introspection/i_function_info.rb +4 -0
- data/lib/gir_ffi/builder/function.rb +7 -7
- data/lib/gir_ffi/builder/type/callback.rb +4 -1
- data/lib/gir_ffi/builder/type/struct_based.rb +3 -1
- data/lib/gir_ffi/builder/type/with_methods.rb +16 -5
- data/lib/gir_ffi/version.rb +1 -1
- data/test/ffi-gobject_introspection/i_function_info_test.rb +23 -0
- data/test/integration/pretty_print_test.rb +25 -5
- data/test/unit/callback_builder_test.rb +14 -0
- data/test/unit/function_builder_test.rb +5 -4
- data/test/unit/struct_builder_test.rb +33 -5
- metadata +14 -12
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.2.2 / 2011-12-07
|
2
|
+
|
3
|
+
* Fix issue #19: Check if a GLib::PtrArray.add method was generated
|
4
|
+
before attempting to remove it.
|
5
|
+
* Fix two issues with pretty printing that made output for GLib have syntax
|
6
|
+
errors.
|
7
|
+
|
1
8
|
== 0.2.1 / 2011-11-20
|
2
9
|
|
3
10
|
* Fix handling of output parameters that are arrays of pointers to
|
data/lib/ffi-glib/ptr_array.rb
CHANGED
@@ -43,13 +43,13 @@ module GirFFI::Builder
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def filled_out_template
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
lines = pre
|
47
|
+
lines << "#{capture}::#{@libmodule}.#{@info.symbol} #{callargs.join(', ')}"
|
48
|
+
lines << post
|
49
|
+
|
50
|
+
code = "def #{@info.safe_name} #{inargs.join(', ')}\n"
|
51
|
+
code << lines.join("\n").indent
|
52
|
+
code << "\nend\n"
|
53
53
|
end
|
54
54
|
|
55
55
|
def inargs
|
@@ -14,8 +14,11 @@ module GirFFI
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def pretty_print
|
17
|
+
args = argument_types.map do |arg|
|
18
|
+
arg.is_a?(FFI::Enum) ? arg.tag : arg.inspect
|
19
|
+
end
|
17
20
|
return "#{@classname} = Lib.callback #{callback_sym.inspect}, " +
|
18
|
-
"#{
|
21
|
+
"[#{args.join(', ')}], #{return_type.inspect}"
|
19
22
|
end
|
20
23
|
|
21
24
|
def callback_sym
|
@@ -6,11 +6,8 @@ module GirFFI
|
|
6
6
|
# :object, :interface.
|
7
7
|
module WithMethods
|
8
8
|
def setup_method method
|
9
|
-
klass = build_class
|
10
|
-
meta = (class << klass; self; end)
|
11
|
-
|
12
9
|
go = method_introspection_data method
|
13
|
-
attach_and_define_method method, go,
|
10
|
+
attach_and_define_method method, go, meta_class
|
14
11
|
end
|
15
12
|
|
16
13
|
def setup_instance_method method
|
@@ -20,6 +17,11 @@ module GirFFI
|
|
20
17
|
|
21
18
|
private
|
22
19
|
|
20
|
+
def meta_class
|
21
|
+
klass = build_class
|
22
|
+
return (class << klass; self; end)
|
23
|
+
end
|
24
|
+
|
23
25
|
def method_introspection_data method
|
24
26
|
info.find_method method
|
25
27
|
end
|
@@ -29,8 +31,12 @@ module GirFFI
|
|
29
31
|
return !data.nil? && data.method? ? data : nil
|
30
32
|
end
|
31
33
|
|
34
|
+
def function_definition_builder go
|
35
|
+
Builder::Function.new(go, lib)
|
36
|
+
end
|
37
|
+
|
32
38
|
def function_definition go
|
33
|
-
|
39
|
+
function_definition_builder(go).generate
|
34
40
|
end
|
35
41
|
|
36
42
|
def attach_and_define_method method, go, modul
|
@@ -55,6 +61,11 @@ module GirFFI
|
|
55
61
|
"
|
56
62
|
end
|
57
63
|
|
64
|
+
def pretty_print_methods
|
65
|
+
info.get_methods.map do |minfo|
|
66
|
+
function_definition_builder(minfo).pretty_print.indent + "\n"
|
67
|
+
end.join
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
60
71
|
end
|
data/lib/gir_ffi/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe GObjectIntrospection::IFunctionInfo do
|
4
|
+
describe "#safe_name" do
|
5
|
+
it "keeps lower case names lower case" do
|
6
|
+
stub(ptr = Object.new).null? { false }
|
7
|
+
info = GObjectIntrospection::IFunctionInfo.wrap ptr
|
8
|
+
stub(info).name { "foo" }
|
9
|
+
|
10
|
+
assert_equal "foo", info.safe_name
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a non-empty string if name is empty" do
|
14
|
+
stub(ptr = Object.new).null? { false }
|
15
|
+
info = GObjectIntrospection::IFunctionInfo.wrap ptr
|
16
|
+
stub(info).name { "" }
|
17
|
+
|
18
|
+
assert_equal "_", info.safe_name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -1,11 +1,31 @@
|
|
1
1
|
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
GirFFI.setup :Regress
|
6
|
+
|
7
|
+
describe "Pretty-printing" do
|
8
|
+
def assert_syntax_ok str
|
9
|
+
tmp = Tempfile.new "gir_ffi"
|
10
|
+
tmp.write str
|
11
|
+
tmp.flush
|
12
|
+
is_ok = `ruby -c #{tmp.path} 2>&1`
|
13
|
+
assert_equal "Syntax OK\n", is_ok
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "for the Regress module" do
|
17
|
+
it "runs without throwing an exception" do
|
18
|
+
Regress._builder.pretty_print
|
19
|
+
end
|
20
|
+
|
21
|
+
it "results in valid Ruby" do
|
22
|
+
assert_syntax_ok Regress._builder.pretty_print
|
23
|
+
end
|
6
24
|
end
|
7
25
|
|
8
|
-
|
9
|
-
|
26
|
+
describe "for the GLib module" do
|
27
|
+
it "results in valid Ruby" do
|
28
|
+
assert_syntax_ok GLib._builder.pretty_print
|
29
|
+
end
|
10
30
|
end
|
11
31
|
end
|
@@ -13,6 +13,20 @@ describe GirFFI::Builder::Type::Callback do
|
|
13
13
|
assert_equal "TheCallback = Lib.callback :TheCallback, [:baz, :qux], :ret_type",
|
14
14
|
builder.pretty_print
|
15
15
|
end
|
16
|
+
|
17
|
+
it "renders enum argument types by their tags" do
|
18
|
+
stub(enum = FFI::Enum.new([])).tag { :EnumTag }
|
19
|
+
|
20
|
+
mock(info = Object.new).safe_name { "TheCallback" }
|
21
|
+
stub(info).namespace { "Foo" }
|
22
|
+
mock(GirFFI::Builder).ffi_function_return_type(info) { :ret_type }
|
23
|
+
mock(GirFFI::Builder).ffi_function_argument_types(info) { [ enum ] }
|
24
|
+
|
25
|
+
builder = GirFFI::Builder::Type::Callback.new(info)
|
26
|
+
|
27
|
+
assert_equal "TheCallback = Lib.callback :TheCallback, [EnumTag], :ret_type",
|
28
|
+
builder.pretty_print
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
18
32
|
|
@@ -16,15 +16,16 @@ describe GirFFI::Builder::Function do
|
|
16
16
|
fbuilder = GirFFI::Builder::Function.new go, Lib
|
17
17
|
code = fbuilder.generate
|
18
18
|
|
19
|
-
expected =
|
20
|
-
|
19
|
+
expected = <<-CODE
|
20
|
+
def test_array_fixed_out_objects
|
21
21
|
_v1 = GirFFI::InOutPointer.for_array [:pointer, ::Regress::TestObj]
|
22
22
|
::Lib.regress_test_array_fixed_out_objects _v1
|
23
23
|
_v2 = _v1.to_sized_array_value 2
|
24
24
|
return _v2
|
25
|
-
end
|
25
|
+
end
|
26
|
+
CODE
|
26
27
|
|
27
|
-
assert_equal
|
28
|
+
assert_equal expected.reset_indentation, code
|
28
29
|
end
|
29
30
|
|
30
31
|
end
|
@@ -2,13 +2,41 @@ require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Type::Struct do
|
4
4
|
describe "#pretty_print" do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe "for a struct with no methods" do
|
6
|
+
it "returns a class block" do
|
7
|
+
mock(info = Object.new).safe_name { "Bar" }
|
8
|
+
stub(info).namespace { "Foo" }
|
9
|
+
stub(info).get_methods { [] }
|
8
10
|
|
9
|
-
|
11
|
+
builder = GirFFI::Builder::Type::Struct.new(info)
|
10
12
|
|
11
|
-
|
13
|
+
assert_equal "class Bar\nend", builder.pretty_print
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "for a struct with a method" do
|
18
|
+
it "returns a class block with the pretty printed method inside" do
|
19
|
+
# FIXME: Loads of mocks. Make info objects create their own builders.
|
20
|
+
|
21
|
+
# Function info and its builder
|
22
|
+
stub(func_info = Object.new).info_type { :function }
|
23
|
+
mock(func_builder = Object.new).pretty_print { "def foo\n function_body\nend" }
|
24
|
+
mock(GirFFI::Builder::Function).new(func_info, :bla) { func_builder }
|
25
|
+
|
26
|
+
# Struct info
|
27
|
+
mock(info = Object.new).safe_name { "Bar" }
|
28
|
+
stub(info).namespace { "Foo" }
|
29
|
+
mock(info).get_methods { [func_info] }
|
30
|
+
|
31
|
+
# Struct builder
|
32
|
+
builder = GirFFI::Builder::Type::Struct.new(info)
|
33
|
+
stub(builder).lib { :bla }
|
34
|
+
|
35
|
+
res = builder.pretty_print
|
36
|
+
expected = "class Bar\n def foo\n function_body\n end\nend"
|
37
|
+
|
38
|
+
assert_equal expected, res
|
39
|
+
end
|
12
40
|
end
|
13
41
|
end
|
14
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gir_ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &11478020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11478020
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: indentation
|
27
|
-
requirement: &
|
27
|
+
requirement: &11477500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.0.6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11477500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &11477020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.0.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11477020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rr
|
49
|
-
requirement: &
|
49
|
+
requirement: &11476540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11476540
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &11476060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.9.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11476060
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- matijs@matijs.net
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- test/ffi-gobject_introspection/i_object_info_test.rb
|
171
171
|
- test/ffi-gobject_introspection/i_base_info_test.rb
|
172
172
|
- test/ffi-gobject_introspection/lib_test.rb
|
173
|
+
- test/ffi-gobject_introspection/i_function_info_test.rb
|
173
174
|
- test/ffi-gobject_introspection/i_constant_info_test.rb
|
174
175
|
- test/test_helper.rb
|
175
176
|
- test/girffi_test.rb
|
@@ -273,6 +274,7 @@ test_files:
|
|
273
274
|
- test/ffi-gobject/value_test.rb
|
274
275
|
- test/ffi-gobject_introspection/i_base_info_test.rb
|
275
276
|
- test/ffi-gobject_introspection/i_constant_info_test.rb
|
277
|
+
- test/ffi-gobject_introspection/i_function_info_test.rb
|
276
278
|
- test/ffi-gobject_introspection/i_object_info_test.rb
|
277
279
|
- test/ffi-gobject_introspection/i_repository_test.rb
|
278
280
|
- test/ffi-gobject_introspection/lib_test.rb
|