gir_ffi 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +13 -0
  3. data/Rakefile +0 -1
  4. data/TODO.md +4 -0
  5. data/gir_ffi.gemspec +41 -0
  6. data/lib/ffi-glib/main_loop.rb +1 -3
  7. data/lib/ffi-glib/variant.rb +1 -1
  8. data/lib/ffi-gobject/ruby_closure.rb +1 -1
  9. data/lib/ffi-gobject_introspection/i_constant_info.rb +15 -11
  10. data/lib/gir_ffi/builders/user_defined_builder.rb +2 -1
  11. data/lib/gir_ffi/builders/with_layout.rb +1 -1
  12. data/lib/gir_ffi/class_base.rb +2 -2
  13. data/lib/gir_ffi/enum_base.rb +1 -1
  14. data/lib/gir_ffi/in_out_pointer.rb +1 -1
  15. data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
  16. data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -1
  17. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +2 -1
  18. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -1
  19. data/lib/gir_ffi/method_stubber.rb +1 -1
  20. data/lib/gir_ffi/version.rb +1 -1
  21. data/tasks/test.rake +1 -1
  22. data/test/ffi-glib/iconv_test.rb +1 -1
  23. data/test/ffi-glib/main_loop_test.rb +27 -0
  24. data/test/ffi-gobject_introspection/i_constant_info_test.rb +19 -5
  25. data/test/gir_ffi/class_base_test.rb +4 -4
  26. data/test/gir_ffi/method_stubber_test.rb +4 -4
  27. data/test/lib/autogen.sh +1 -0
  28. data/test/lib/configure.ac +1 -0
  29. metadata +7 -109
  30. data/examples/demo_ffi_inherited_layout.rb +0 -21
  31. data/examples/demo_ffi_nested_struct.rb +0 -17
  32. data/examples/demo_ffi_safe_inherited_layout.rb +0 -43
  33. data/examples/hard_coded.rb +0 -167
  34. data/examples/leak_test.rb +0 -11
  35. data/examples/print_class.rb +0 -61
  36. data/tasks/valgrind.rake +0 -3
  37. data/test/integration/idle_loop_test.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 784da223496ff93dd574411f1058071f336aa18e
4
- data.tar.gz: ffbc7a82e2b710669a74055bf436a8c26d2ed956
3
+ metadata.gz: d42de354fa7299aa1335fbc7853d71c290e40672
4
+ data.tar.gz: 5ac34874e3b063d78efae9e6d866d1c53250a139
5
5
  SHA512:
6
- metadata.gz: b9a5bbd317a59c9cad7840e318e9a03e12413a130e259677216fc7fe6ad9ab5592017bdff9904ec15da9aa65a8f5dbf72b3d74f33f477c3c698309bce3ff4649
7
- data.tar.gz: 1c7ec6f5c809e141c6f5338c742a1a3042cdbc18645dfc3631f838fe090b36fa12822b60eddf875d58707f78e2ad9e5e16c28a9ef7843e41f16a7902a4e882a3
6
+ metadata.gz: 24484386533238755050906dc1d1dbbf31e4d8baf49fb739a9c42cb85176a561f3b280e83eaa06ff249cbb3f77c8b08867f532f0db926618e8be67ad8bb96f19
7
+ data.tar.gz: 35251a7d050dbf35c96ebb59c6c06588d190551a68629df365267c1723cb85a1d813e1e0bfff1b7850ef7661fecaed0453d6f4bf813968c8b3081e65e1c08538
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.7 / 2014-10-21
4
+
5
+ * Handle introspecting boolean constants
6
+ * Provide config.h for versions of the test libs that need it
7
+ * Include gemspec in the gem
8
+ * Avoid needless casting from string to symbol by making #setup_and_call take a
9
+ string
10
+ * Avoid argument list unpacking by making #setup_and_call take an array of
11
+ arguments rather than a variable number of arguments
12
+ * Remove old example files
13
+ * Let rubygems know about required Ruby version
14
+ * Various clean-ups
15
+
3
16
  ## 0.7.6 / 2014-08-22
4
17
 
5
18
  * Work around respond_to? behavior in JRuby 1.6.13
data/Rakefile CHANGED
@@ -10,6 +10,5 @@ end
10
10
  MyGemHelper.install_tasks
11
11
 
12
12
  load 'tasks/test.rake'
13
- load 'tasks/valgrind.rake'
14
13
 
15
14
  task :default => 'test:all'
data/TODO.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TODO
2
2
 
3
+ MAKE CONSTRUCTOR_WRAP CHECK TYPES?
4
+
3
5
  ## Memory managment
4
6
 
5
7
  GirFFI does not attempt to free any memory at the moment, or lower the
@@ -8,6 +10,8 @@ reference count of any objects it gets from GObject. This task therefore involve
8
10
  - Free non-GObject pointers as needed (at garbage-collection time)
9
11
  - Lower reference count of GObjects (at garbage-collection time)
10
12
 
13
+ **Use memory_profiler to check memory use (https://github.com/SamSaffron/memory_profiler)**
14
+
11
15
  ## Refactorings
12
16
 
13
17
  These in the order they occured to me, and may therefore be fixed in any order.
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'lib/gir_ffi/version.rb')
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "gir_ffi"
6
+ s.version = GirFFI::VERSION
7
+
8
+ s.summary = "FFI-based GObject binding using the GObject Introspection Repository"
9
+ s.required_ruby_version = %q{>= 1.9.3}
10
+
11
+ s.authors = ["Matijs van Zuijlen"]
12
+ s.email = ["matijs@matijs.net"]
13
+ s.homepage = "http://www.github.com/mvz/ruby-gir-ffi"
14
+
15
+ s.license = 'LGPL-2.1'
16
+
17
+ s.description = <<-DESC
18
+ GirFFI creates bindings for GObject-based libraries at runtime based on introspection
19
+ data provided by the GObject Introspection Repository (GIR) system. Bindings are created
20
+ at runtime and use FFI to interface with the C libraries. In cases where the GIR does not
21
+ provide enough or correct information to create sane bindings, overrides may be created.
22
+ DESC
23
+
24
+ s.files = Dir[ '{lib,test,tasks,examples}/**/*',
25
+ "*.md",
26
+ "*.gemspec",
27
+ "Rakefile",
28
+ "COPYING.LIB" ] & `git ls-files -z`.split("\0")
29
+
30
+ s.rdoc_options = ["--main", "README.md"]
31
+ s.extra_rdoc_files = ["DESIGN.md", "Changelog.md", "README.md", "TODO.md"]
32
+
33
+ s.add_runtime_dependency('ffi', ["~> 1.8"])
34
+ s.add_runtime_dependency('indentation', ["~> 0.1.1"])
35
+
36
+ s.add_development_dependency('minitest', ["~> 5.2"])
37
+ s.add_development_dependency('rr', ["~> 1.1.2"])
38
+ s.add_development_dependency('rake', ["~> 10.1"])
39
+
40
+ s.require_paths = ["lib"]
41
+ end
@@ -5,7 +5,7 @@ GLib.load_class :MainLoop
5
5
  module GLib
6
6
  # Overrides for GMainLoop, GLib's event loop
7
7
  class MainLoop
8
- # Class encepsulationg logic for running an idle handler to make Ruby code
8
+ # Class encapsulationg logic for running an idle handler to make Ruby code
9
9
  # run during GLib's event loop.
10
10
  class ThreadEnabler
11
11
  include Singleton
@@ -33,8 +33,6 @@ module GLib
33
33
  end
34
34
  end
35
35
 
36
- setup_instance_method "run_with_thread_enabler"
37
-
38
36
  def run_with_thread_enabler
39
37
  case RUBY_ENGINE
40
38
  when 'jruby'
@@ -10,7 +10,7 @@ module GLib
10
10
  end
11
11
 
12
12
  def self.constructor_wrap ptr
13
- super.tap { |variant| variant.ref }
13
+ super.tap(&:ref)
14
14
  end
15
15
 
16
16
  alias_method :get_string_without_override, :get_string
@@ -42,7 +42,7 @@ module GObject
42
42
  rclosure = wrap(closure.to_ptr)
43
43
  param_values ||= []
44
44
 
45
- args = param_values.map { |value| value.get_value }
45
+ args = param_values.map(&:get_value)
46
46
 
47
47
  result = rclosure.invoke_block(*args)
48
48
 
@@ -2,21 +2,25 @@ module GObjectIntrospection
2
2
  # Wraps a GIConstantInfo struct; represents a constant.
3
3
  class IConstantInfo < IBaseInfo
4
4
  TYPE_TAG_TO_UNION_MEMBER = {
5
- gint8: :v_int8,
6
- gint16: :v_int16,
7
- gint32: :v_int32,
8
- gint64: :v_int64,
9
- guint8: :v_uint8,
10
- guint16: :v_uint16,
11
- guint32: :v_uint32,
12
- guint64: :v_uint64,
13
- gdouble: :v_double,
14
- utf8: :v_string
5
+ gboolean: :v_boolean,
6
+ gint8: :v_int8,
7
+ gint16: :v_int16,
8
+ gint32: :v_int32,
9
+ gint64: :v_int64,
10
+ guint8: :v_uint8,
11
+ guint16: :v_uint16,
12
+ guint32: :v_uint32,
13
+ guint64: :v_uint64,
14
+ gdouble: :v_double,
15
+ utf8: :v_string
15
16
  }
16
17
 
17
18
  def value
18
- if type_tag == :utf8
19
+ case type_tag
20
+ when :utf8
19
21
  raw_value.force_encoding("utf-8")
22
+ when :gboolean
23
+ raw_value != 0
20
24
  else
21
25
  raw_value
22
26
  end
@@ -117,7 +117,8 @@ module GirFFI
117
117
  end
118
118
 
119
119
  def setup_vfuncs object_class_ptr
120
- super_class_struct = superclass.gir_ffi_builder.object_class_struct::Struct.new(object_class_ptr)
120
+ super_class_struct =
121
+ superclass.gir_ffi_builder.object_class_struct::Struct.new(object_class_ptr)
121
122
 
122
123
  info.vfunc_implementations.each do |impl|
123
124
  setup_vfunc super_class_struct, impl
@@ -31,7 +31,7 @@ module GirFFI
31
31
  end
32
32
 
33
33
  def base_layout_specification
34
- fields.map { |finfo| finfo.layout_specification }.flatten(1)
34
+ fields.map(&:layout_specification).flatten(1)
35
35
  end
36
36
 
37
37
  def setup_field_accessors
@@ -11,7 +11,7 @@ module GirFFI
11
11
  attr_reader :struct
12
12
  def_delegators :@struct, :to_ptr
13
13
 
14
- def setup_and_call method, *arguments, &block
14
+ def setup_and_call method, arguments, &block
15
15
  method_name = self.class.try_in_ancestors(:setup_instance_method, method.to_s)
16
16
 
17
17
  unless method_name
@@ -27,7 +27,7 @@ module GirFFI
27
27
  other.class == self.class && to_ptr.address == other.to_ptr.address
28
28
  end
29
29
 
30
- def self.setup_and_call method, *arguments, &block
30
+ def self.setup_and_call method, arguments, &block
31
31
  method_name = try_in_ancestors(:setup_method, method.to_s)
32
32
 
33
33
  unless method_name
@@ -38,7 +38,7 @@ module GirFFI
38
38
  from_native pointer.get_int32(0), nil
39
39
  end
40
40
 
41
- def setup_and_call method, *arguments, &block
41
+ def setup_and_call method, arguments, &block
42
42
  result = setup_method method.to_s
43
43
 
44
44
  unless result
@@ -56,7 +56,7 @@ module GirFFI
56
56
  end
57
57
 
58
58
  def self.for type
59
- new(type).tap { |ptr| ptr.clear }
59
+ new(type).tap(&:clear)
60
60
  end
61
61
 
62
62
  def self.from type, value
@@ -3,7 +3,7 @@ module GirFFI
3
3
  # Extensions for GObjectIntrospection::ICallableInfo needed by GirFFI
4
4
  module ICallableInfo
5
5
  def argument_ffi_types
6
- args.map { |arg| arg.to_ffitype }
6
+ args.map(&:to_ffitype)
7
7
  end
8
8
  end
9
9
  end
@@ -7,7 +7,7 @@ module GirFFI
7
7
  end
8
8
 
9
9
  def argument_ffi_types
10
- args.map { |arg| arg.to_callback_ffitype }
10
+ args.map(&:to_callback_ffitype)
11
11
  end
12
12
 
13
13
  def return_ffi_type
@@ -20,4 +20,5 @@ module GirFFI
20
20
  end
21
21
  end
22
22
 
23
- GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::IRegisteredTypeInfo
23
+ GObjectIntrospection::IRegisteredTypeInfo.send :include,
24
+ GirFFI::InfoExt::IRegisteredTypeInfo
@@ -4,7 +4,7 @@ module GirFFI
4
4
  # TODO: Merge implementation with ICallbackInfo and ISignalInfo extensions.
5
5
  module IVFuncInfo
6
6
  def argument_ffi_types
7
- args.map { |arg| arg.to_callback_ffitype }.tap do |types|
7
+ args.map(&:to_callback_ffitype).tap do |types|
8
8
  types << :pointer if throws?
9
9
  end
10
10
  end
@@ -9,7 +9,7 @@ module GirFFI
9
9
  def method_stub
10
10
  <<-STUB.reset_indentation
11
11
  def #{@info.method? ? '' : 'self.'}#{@info.safe_name} *args, &block
12
- setup_and_call #{@info.name.to_sym.inspect}, *args, &block
12
+ setup_and_call "#{@info.name}", args, &block
13
13
  end
14
14
  STUB
15
15
  end
@@ -1,4 +1,4 @@
1
1
  # Current GirFFI version
2
2
  module GirFFI
3
- VERSION = "0.7.6"
3
+ VERSION = "0.7.7"
4
4
  end
@@ -189,6 +189,6 @@ file "test/lib/Makefile" => "test/lib/configure" do
189
189
  sh %{cd test/lib && ./configure --enable-maintainer-mode}
190
190
  end
191
191
 
192
- file "test/lib/configure" do
192
+ file "test/lib/configure" => ["test/lib/autogen.sh", "test/lib/configure.ac"] do
193
193
  sh %{cd test/lib && NOCONFIGURE=1 ./autogen.sh}
194
194
  end
@@ -12,7 +12,7 @@ describe GLib::IConv do
12
12
 
13
13
  describe "#setup_and_call" do
14
14
  it "works for the method called ''" do
15
- instance.setup_and_call :'', nil, nil, nil, nil
15
+ instance.setup_and_call :'', [nil, nil, nil, nil]
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,27 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GLib::MainLoop do
4
+ describe "#run" do
5
+ it "allows other threads to run" do
6
+ main_loop = GLib::MainLoop.new nil, false
7
+
8
+ a = []
9
+ GLib.timeout_add(GLib::PRIORITY_DEFAULT, 100,
10
+ proc { main_loop.quit },
11
+ nil, nil)
12
+
13
+ slow_thread = Thread.new do
14
+ sleep 0.001
15
+ a << "During run"
16
+ end
17
+
18
+ a << "Before run"
19
+ main_loop.run
20
+ a << "After run"
21
+
22
+ slow_thread.join
23
+
24
+ a.last.must_equal "After run"
25
+ end
26
+ end
27
+ end
@@ -2,16 +2,30 @@ require 'introspection_test_helper'
2
2
 
3
3
  describe GObjectIntrospection::IConstantInfo do
4
4
  describe "for GLib::USEC_PER_SEC, a constant of type :gint32" do
5
- before do
6
- @info = get_introspection_data 'GLib', 'USEC_PER_SEC'
7
- end
5
+ let(:constant_info) { get_introspection_data 'GLib', 'USEC_PER_SEC' }
8
6
 
9
7
  it "returns :gint32 as its type" do
10
- assert_equal :gint32, @info.constant_type.tag
8
+ assert_equal :gint32, constant_info.constant_type.tag
11
9
  end
12
10
 
13
11
  it "returns 1_000_000 as its value" do
14
- assert_equal 1_000_000, @info.value
12
+ assert_equal 1_000_000, constant_info.value
13
+ end
14
+ end
15
+
16
+ describe "for GLib::SOURCE_CONTINUE, a constant of type :gboolean" do
17
+ let(:constant_info) { get_introspection_data 'GLib', 'SOURCE_CONTINUE' }
18
+
19
+ before do
20
+ skip unless constant_info
21
+ end
22
+
23
+ it "returns :gboolean as its type" do
24
+ assert_equal :gboolean, constant_info.constant_type.tag
25
+ end
26
+
27
+ it "returns true as its value" do
28
+ assert_equal true, constant_info.value
15
29
  end
16
30
  end
17
31
  end
@@ -82,7 +82,7 @@ describe GirFFI::ClassBase do
82
82
  end
83
83
  sub_klass.const_set :GIR_FFI_BUILDER, sub_builder
84
84
 
85
- sub_klass.setup_and_call :foo
85
+ sub_klass.setup_and_call :foo, []
86
86
  end
87
87
 
88
88
  it "calls the method given by the result of .setup_method" do
@@ -95,7 +95,7 @@ describe GirFFI::ClassBase do
95
95
  end
96
96
  klass.const_set :GIR_FFI_BUILDER, builder
97
97
 
98
- result = klass.setup_and_call :foo
98
+ result = klass.setup_and_call :foo, []
99
99
  result.must_equal "correct-result"
100
100
  end
101
101
  end
@@ -116,7 +116,7 @@ describe GirFFI::ClassBase do
116
116
 
117
117
  obj = sub_klass.new
118
118
 
119
- obj.setup_and_call :foo
119
+ obj.setup_and_call :foo, []
120
120
  end
121
121
 
122
122
  it "calls the method given by the result of .setup_instance_method" do
@@ -131,7 +131,7 @@ describe GirFFI::ClassBase do
131
131
 
132
132
  obj = klass.new
133
133
 
134
- result = obj.setup_and_call :foo
134
+ result = obj.setup_and_call :foo, []
135
135
  result.must_equal "correct-result"
136
136
  end
137
137
  end
@@ -12,7 +12,7 @@ describe GirFFI::MethodStubber do
12
12
  it "creates a method stub" do
13
13
  result.must_equal <<-STUB.reset_indentation
14
14
  def instance_method *args, &block
15
- setup_and_call :instance_method, *args, &block
15
+ setup_and_call "instance_method", args, &block
16
16
  end
17
17
  STUB
18
18
  end
@@ -25,7 +25,7 @@ describe GirFFI::MethodStubber do
25
25
  it "creates a class method stub" do
26
26
  result.must_equal <<-STUB.reset_indentation
27
27
  def self.static_method *args, &block
28
- setup_and_call :static_method, *args, &block
28
+ setup_and_call "static_method", args, &block
29
29
  end
30
30
  STUB
31
31
  end
@@ -38,7 +38,7 @@ describe GirFFI::MethodStubber do
38
38
  it "creates a module method stub" do
39
39
  result.must_equal <<-STUB.reset_indentation
40
40
  def self.test_int *args, &block
41
- setup_and_call :test_int, *args, &block
41
+ setup_and_call "test_int", args, &block
42
42
  end
43
43
  STUB
44
44
  end
@@ -50,7 +50,7 @@ describe GirFFI::MethodStubber do
50
50
  it "creates a method stub with a safe name that sets up the unsafe method" do
51
51
  result.must_equal <<-STUB.reset_indentation
52
52
  def _ *args, &block
53
- setup_and_call :"", *args, &block
53
+ setup_and_call "", args, &block
54
54
  end
55
55
  STUB
56
56
  end
@@ -74,6 +74,7 @@ libtoolize --force || exit $?
74
74
  $ACLOCAL -I m4 || exit $?
75
75
 
76
76
  autoconf || exit $?
77
+ autoheader || exit $?
77
78
 
78
79
  $AUTOMAKE --add-missing || exit $?
79
80
 
@@ -6,6 +6,7 @@ AC_INIT(dummy_test_lib, 0.0.1)
6
6
  AC_CONFIG_MACRO_DIR([m4])
7
7
  AM_INIT_AUTOMAKE([1.7 foreign])
8
8
  AM_MAINTAINER_MODE
9
+ AM_CONFIG_HEADER([config.h])
9
10
 
10
11
  m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],)
11
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-22 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -101,13 +101,8 @@ files:
101
101
  - README.md
102
102
  - Rakefile
103
103
  - TODO.md
104
- - examples/demo_ffi_inherited_layout.rb
105
- - examples/demo_ffi_nested_struct.rb
106
- - examples/demo_ffi_safe_inherited_layout.rb
107
- - examples/hard_coded.rb
108
- - examples/leak_test.rb
109
104
  - examples/main_loop.rb
110
- - examples/print_class.rb
105
+ - gir_ffi.gemspec
111
106
  - lib/ffi-glib.rb
112
107
  - lib/ffi-glib/array.rb
113
108
  - lib/ffi-glib/array_methods.rb
@@ -251,7 +246,6 @@ files:
251
246
  - lib/gir_ffi/vfunc_implementation.rb
252
247
  - lib/gir_ffi/zero_terminated.rb
253
248
  - tasks/test.rake
254
- - tasks/valgrind.rake
255
249
  - test/base_test_helper.rb
256
250
  - test/ffi-glib/array_test.rb
257
251
  - test/ffi-glib/byte_array_test.rb
@@ -259,6 +253,7 @@ files:
259
253
  - test/ffi-glib/hash_table_test.rb
260
254
  - test/ffi-glib/iconv_test.rb
261
255
  - test/ffi-glib/list_test.rb
256
+ - test/ffi-glib/main_loop_test.rb
262
257
  - test/ffi-glib/ptr_array_test.rb
263
258
  - test/ffi-glib/ruby_closure_test.rb
264
259
  - test/ffi-glib/s_list_test.rb
@@ -340,7 +335,6 @@ files:
340
335
  - test/integration/generated_pango_test.rb
341
336
  - test/integration/generated_regress_test.rb
342
337
  - test/integration/generated_secret_test.rb
343
- - test/integration/idle_loop_test.rb
344
338
  - test/integration/method_lookup_test.rb
345
339
  - test/introspection_test_helper.rb
346
340
  - test/lib/Makefile.am
@@ -362,7 +356,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
362
356
  requirements:
363
357
  - - ">="
364
358
  - !ruby/object:Gem::Version
365
- version: '0'
359
+ version: 1.9.3
366
360
  required_rubygems_version: !ruby/object:Gem::Requirement
367
361
  requirements:
368
362
  - - ">="
@@ -370,104 +364,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
364
  version: '0'
371
365
  requirements: []
372
366
  rubyforge_project:
373
- rubygems_version: 2.2.2
367
+ rubygems_version: 2.4.1
374
368
  signing_key:
375
369
  specification_version: 4
376
370
  summary: FFI-based GObject binding using the GObject Introspection Repository
377
- test_files:
378
- - test/base_test_helper.rb
379
- - test/ffi-glib/array_test.rb
380
- - test/ffi-glib/byte_array_test.rb
381
- - test/ffi-glib/bytes_test.rb
382
- - test/ffi-glib/hash_table_test.rb
383
- - test/ffi-glib/iconv_test.rb
384
- - test/ffi-glib/list_test.rb
385
- - test/ffi-glib/ptr_array_test.rb
386
- - test/ffi-glib/ruby_closure_test.rb
387
- - test/ffi-glib/s_list_test.rb
388
- - test/ffi-glib/strv_test.rb
389
- - test/ffi-glib/variant_test.rb
390
- - test/ffi-gobject/gobject_test.rb
391
- - test/ffi-gobject/object_class_test.rb
392
- - test/ffi-gobject/object_test.rb
393
- - test/ffi-gobject/value_test.rb
394
- - test/ffi-gobject_introspection/i_base_info_test.rb
395
- - test/ffi-gobject_introspection/i_constant_info_test.rb
396
- - test/ffi-gobject_introspection/i_enum_info_test.rb
397
- - test/ffi-gobject_introspection/i_function_info_test.rb
398
- - test/ffi-gobject_introspection/i_object_info_test.rb
399
- - test/ffi-gobject_introspection/i_registered_type_info_test.rb
400
- - test/ffi-gobject_introspection/i_repository_test.rb
401
- - test/ffi-gobject_introspection/i_type_info_test.rb
402
- - test/ffi-gobject_introspection/lib_test.rb
403
- - test/ffi-gobject_test.rb
404
- - test/gir_ffi-base/glib/boolean_test.rb
405
- - test/gir_ffi-base/glib/strv_test.rb
406
- - test/gir_ffi/arg_helper_test.rb
407
- - test/gir_ffi/builder_test.rb
408
- - test/gir_ffi/builders/argument_builder_test.rb
409
- - test/gir_ffi/builders/base_argument_builder_test.rb
410
- - test/gir_ffi/builders/callback_argument_builder_test.rb
411
- - test/gir_ffi/builders/callback_builder_test.rb
412
- - test/gir_ffi/builders/callback_return_value_builder_test.rb
413
- - test/gir_ffi/builders/constant_builder_test.rb
414
- - test/gir_ffi/builders/enum_builder_test.rb
415
- - test/gir_ffi/builders/field_builder_test.rb
416
- - test/gir_ffi/builders/function_builder_test.rb
417
- - test/gir_ffi/builders/interface_builder_test.rb
418
- - test/gir_ffi/builders/module_builder_test.rb
419
- - test/gir_ffi/builders/object_builder_test.rb
420
- - test/gir_ffi/builders/property_builder_test.rb
421
- - test/gir_ffi/builders/registered_type_builder_test.rb
422
- - test/gir_ffi/builders/return_value_builder_test.rb
423
- - test/gir_ffi/builders/signal_closure_builder_test.rb
424
- - test/gir_ffi/builders/struct_builder_test.rb
425
- - test/gir_ffi/builders/unintrospectable_builder_test.rb
426
- - test/gir_ffi/builders/union_builder_test.rb
427
- - test/gir_ffi/builders/user_defined_builder_test.rb
428
- - test/gir_ffi/builders/vfunc_builder_test.rb
429
- - test/gir_ffi/callback_base_test.rb
430
- - test/gir_ffi/class_base_test.rb
431
- - test/gir_ffi/error_type_info_test.rb
432
- - test/gir_ffi/ffi_ext/pointer_test.rb
433
- - test/gir_ffi/g_type_test.rb
434
- - test/gir_ffi/in_out_pointer_test.rb
435
- - test/gir_ffi/in_pointer_test.rb
436
- - test/gir_ffi/info_ext/i_callable_info_test.rb
437
- - test/gir_ffi/info_ext/i_callback_info_test.rb
438
- - test/gir_ffi/info_ext/i_field_info_test.rb
439
- - test/gir_ffi/info_ext/i_function_info_test.rb
440
- - test/gir_ffi/info_ext/i_signal_info_test.rb
441
- - test/gir_ffi/info_ext/i_type_info_test.rb
442
- - test/gir_ffi/info_ext/safe_constant_name_test.rb
443
- - test/gir_ffi/info_ext/safe_function_name_test.rb
444
- - test/gir_ffi/interface_base_test.rb
445
- - test/gir_ffi/method_stubber_test.rb
446
- - test/gir_ffi/object_base_test.rb
447
- - test/gir_ffi/sized_array_test.rb
448
- - test/gir_ffi/type_map_test.rb
449
- - test/gir_ffi/unintrospectable_type_info_test.rb
450
- - test/gir_ffi/user_defined_property_info_test.rb
451
- - test/gir_ffi/user_defined_type_info_test.rb
452
- - test/gir_ffi/variable_name_generator_test.rb
453
- - test/gir_ffi/version_test.rb
454
- - test/gir_ffi/zero_terminated_test.rb
455
- - test/gir_ffi_test.rb
456
- - test/gir_ffi_test_helper.rb
457
- - test/integration/derived_classes_test.rb
458
- - test/integration/generated_gimarshallingtests_test.rb
459
- - test/integration/generated_gio_test.rb
460
- - test/integration/generated_glib_test.rb
461
- - test/integration/generated_gobject_test.rb
462
- - test/integration/generated_pango_ft2_test.rb
463
- - test/integration/generated_pango_test.rb
464
- - test/integration/generated_regress_test.rb
465
- - test/integration/generated_secret_test.rb
466
- - test/integration/idle_loop_test.rb
467
- - test/integration/method_lookup_test.rb
468
- - test/introspection_test_helper.rb
469
- - test/lib/Makefile.am
470
- - test/lib/autogen.sh
471
- - test/lib/configure.ac
472
- - test/lib/m4/jhflags.m4
473
- - test/minitest/stats_plugin.rb
371
+ test_files: []
@@ -1,21 +0,0 @@
1
- # Demonstration program for FFI functionality.
2
- #
3
- # Show what happens if we call layout again in a subclass. This works in
4
- # JRuby, but not in MRI (gives warnings with ffi 0.6.3, is explicitely
5
- # forbidden later).
6
- #
7
- require 'ffi'
8
-
9
- class Foo < FFI::Struct
10
- layout :a, :int, :b, :int
11
- end
12
-
13
- class Bar < Foo
14
- layout :p, Foo, :c, :int
15
- end
16
-
17
- bar = Bar.new
18
- foo = Foo.new(bar.to_ptr)
19
- foo[:a] = 20
20
- puts "bar[:p][:a] = #{bar[:p][:a]}"
21
-
@@ -1,17 +0,0 @@
1
- # Demonstration program for FFI functionality.
2
- #
3
- # Basic demo of nested struct. Works in MRI, YARV, and JRuby. Does not work
4
- # in Rubinius.
5
- #
6
- require 'ffi'
7
-
8
- module LibTest
9
- class Foo < FFI::Struct
10
- layout :a, :int, :b, :int
11
- end
12
-
13
- class Bar < FFI::Struct
14
- layout :f, Foo, :g, :int
15
- end
16
- end
17
- puts LibTest::Bar.members.inspect
@@ -1,43 +0,0 @@
1
- # Demonstrate safe inheritance with layout.
2
- #
3
- # Uses nested Struct class to separate inheritance from FFI::Struct from
4
- # main inheritance structure. Works with MRI and JRuby, without warnings.
5
-
6
- require 'ffi'
7
- require 'forwardable'
8
-
9
- class Foo
10
- extend Forwardable
11
- def_delegators :@struct, :[], :to_ptr
12
-
13
- class Struct < FFI::Struct
14
- layout :a, :int, :b, :int
15
- end
16
-
17
- def initialize(ptr=nil)
18
- @struct = ptr.nil? ?
19
- self.ffi_structure.new :
20
- self.ffi_structure.new(ptr)
21
- end
22
-
23
- def ffi_structure
24
- self.class.ffi_structure
25
- end
26
-
27
- class << self
28
- def ffi_structure
29
- self.const_get(:Struct)
30
- end
31
- end
32
- end
33
-
34
- class Bar < Foo
35
- class Struct < FFI::Struct
36
- layout :p, Foo.ffi_structure, :c, :int
37
- end
38
- end
39
-
40
- bar = Bar.new
41
- bar[:p][:a] = 20
42
- foo = Foo.new(bar.to_ptr)
43
- puts foo[:a]
@@ -1,167 +0,0 @@
1
- # Hard-code FFI-based Gtk+ test program. Nothing is generated here.
2
- require 'ffi'
3
- module GObject
4
-
5
- module Lib
6
- extend FFI::Library
7
- CALLBACKS = []
8
- ffi_lib "gobject-2.0"
9
- callback :GCallback, [], :void
10
- enum :GConnectFlags, [:AFTER, (1<<0), :SWAPPED, (1<<1)]
11
-
12
- attach_function :g_signal_connect_data, [:pointer, :string, :GCallback,
13
- :pointer, :pointer, :GConnectFlags], :ulong
14
- end
15
-
16
- def self.signal_connect_data gobject, signal, prc, data, destroy_data, connect_flags
17
- Lib::CALLBACKS << prc
18
- Lib.g_signal_connect_data gobject.to_ptr, signal, prc, data, destroy_data, connect_flags
19
- end
20
- end
21
-
22
- module Gtk
23
- module Lib
24
- extend FFI::Library
25
-
26
- ffi_lib "gtk-x11-2.0"
27
- attach_function :gtk_init, [:pointer, :pointer], :void
28
- attach_function :gtk_main, [], :void
29
- attach_function :gtk_main_quit, [], :void
30
-
31
- attach_function :gtk_widget_show, [:pointer], :pointer
32
- attach_function :gtk_widget_destroy, [:pointer], :void
33
- attach_function :gtk_container_add, [:pointer, :pointer], :void
34
-
35
- enum :GtkWindowType, [:GTK_WINDOW_TOPLEVEL, :GTK_WINDOW_POPUP]
36
- attach_function :gtk_window_new, [:GtkWindowType], :pointer
37
- attach_function :gtk_button_new, [], :pointer
38
- attach_function :gtk_button_new_with_label, [:string], :pointer
39
- attach_function :gtk_label_new, [:string], :pointer
40
- end
41
-
42
- def self.init size, ary
43
- argv = self.string_array_to_inoutptr ary
44
- argc = self.int_to_inoutptr(size)
45
-
46
- Lib.gtk_init argc, argv
47
-
48
- outsize = self.outptr_to_int argc
49
- outary = self.outptr_to_string_array argv, ary.nil? ? 0 : ary.size
50
-
51
- return outsize, outary
52
- end
53
-
54
- def self.int_to_inoutptr val
55
- ptr = FFI::MemoryPointer.new(:int)
56
- ptr.write_int val
57
- return ptr
58
- end
59
-
60
- # Note: This implementation would dump core if the garbage collector runs
61
- # before the contents of the pointers is used.
62
- def self.string_array_to_inoutptr ary
63
- ptrs = ary.map {|a| FFI::MemoryPointer.from_string(a)}
64
- block = FFI::MemoryPointer.new(:pointer, ptrs.length)
65
- block.write_array_of_pointer ptrs
66
- argv = FFI::MemoryPointer.new(:pointer)
67
- argv.write_pointer block
68
- argv
69
- end
70
-
71
- def self.outptr_to_int ptr
72
- return ptr.read_int
73
- end
74
-
75
- def self.outptr_to_string_array ptr, size
76
- block = ptr.read_pointer
77
- ptrs = block.read_array_of_pointer(size)
78
- return ptrs.map {|p| p.null? ? nil : p.read_string}
79
- end
80
-
81
- def self.main; Lib.gtk_main; end
82
- def self.main_quit; Lib.gtk_main_quit; end
83
-
84
- class Widget
85
- def show
86
- Lib.gtk_widget_show(@gobj)
87
- end
88
- def destroy
89
- Lib.gtk_widget_destroy(@gobj)
90
- end
91
- def to_ptr
92
- @gobj
93
- end
94
- end
95
-
96
- class Container < Widget
97
- def add widget
98
- Lib.gtk_container_add self.to_ptr, widget.to_ptr
99
- end
100
- end
101
-
102
- class Window < Container
103
- def initialize type
104
- @gobj = Lib.gtk_window_new(type)
105
- end
106
- end
107
-
108
- class Button < Container
109
- class << self
110
- alias :real_new :new
111
- end
112
-
113
- def self.new *args
114
- obj = self.real_new *args
115
- ptr = Lib.gtk_button_new()
116
- obj.instance_variable_set :@gobj, ptr
117
- obj
118
- end
119
-
120
- def self.new_with_label text, *args
121
- obj = self.real_new *args
122
- ptr = Lib.gtk_button_new_with_label(text)
123
- obj.instance_variable_set :@gobj, ptr
124
- obj
125
- end
126
- end
127
-
128
- class MyButton < Button
129
- def initialize sym
130
- puts "Initializing a #{self.class} with symbol #{sym}"
131
- end
132
-
133
- def self.new
134
- super :foo
135
- end
136
-
137
- def self.new_with_label sym
138
- super "Hello world", sym
139
- end
140
- end
141
- end
142
-
143
- (my_len, my_args) = Gtk.init ARGV.length + 1, [$0, *ARGV]
144
- p [my_len, my_args]
145
- win = Gtk::Window.new(:GTK_WINDOW_TOPLEVEL)
146
-
147
- #btn = Gtk::Button.new_with_label('Hello World')
148
- #btn = Gtk::MyButton.new
149
- btn = Gtk::MyButton.new_with_label :foobar2
150
-
151
- win.add btn
152
-
153
- quit_prc = Proc.new { Gtk.main_quit }
154
-
155
- # We can create callbacks with a different signature by using FFI::Function
156
- # directly.
157
- del_prc = FFI::Function.new(:bool, [:pointer, :pointer]) {|a, b|
158
- puts "delete event occured"
159
- true
160
- }
161
- GObject.signal_connect_data(win, "destroy", quit_prc, nil, nil, 0)
162
- GObject.signal_connect_data(win, "delete-event", del_prc, nil, nil, 0)
163
- GObject.signal_connect_data(btn, "clicked", Proc.new { win.destroy }, nil, nil, :SWAPPED)
164
-
165
- btn.show
166
- win.show
167
- Gtk.main
@@ -1,11 +0,0 @@
1
- # Test program to train Valgrind.
2
- require 'ffi'
3
-
4
- module LibC
5
- extend FFI::Library
6
- ffi_lib FFI::Library::LIBC
7
-
8
- attach_function :malloc, [:size_t], :pointer
9
- end
10
-
11
- LibC.malloc 2000
@@ -1,61 +0,0 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'gir_ffi'
3
-
4
- # File activesupport/lib/active_support/inflector/methods.rb, line 48
5
- def underscore(camel_cased_word)
6
- word = camel_cased_word.to_s.dup
7
- word.gsub!(/::/, '/')
8
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
9
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
10
- word.tr!("-", "_")
11
- word.downcase!
12
- word
13
- end
14
-
15
- namespace = 'GObject'
16
- GirFFI.setup namespace
17
- modul = Kernel.const_get(namespace)
18
-
19
- gir = GObjectIntrospection::IRepository.default
20
- gir.require namespace, nil
21
- infos = gir.infos namespace
22
-
23
- main_file = File.open(File.join('.', "#{underscore(namespace)}.rb"), 'w')
24
-
25
- main_file.write "module #{namespace}\n"
26
-
27
- infos.each do |info|
28
- case info.info_type
29
- when :function
30
- fbuilder = GirFFI::Builder::Function.new info, modul::Lib
31
- main_file.write "\n"
32
- main_file.write fbuilder.generate
33
- main_file.write "\n"
34
- when :object
35
- main_file.write "class #{info.name} < #{info.parent.name}\n"
36
- info.get_methods.each do |minfo|
37
- main_file.write "\n"
38
- unless minfo.method?
39
- main_file.write "class << self\n"
40
- end
41
- if minfo.constructor?
42
- main_file.write "# This method is a constructor\n"
43
- end
44
- main_file.write "# @return [#{minfo.return_type.tag}]\n"
45
-
46
- fbuilder = GirFFI::Builder::Function.new minfo, modul::Lib
47
- main_file.write fbuilder.generate
48
- unless minfo.method?
49
- main_file.write "end\n"
50
- end
51
- main_file.write "\n"
52
- end
53
- main_file.write "end\n"
54
- else
55
- puts "#{info.info_type}: #{info.name}\n"
56
- end
57
- end
58
-
59
- main_file.write "end\n"
60
- main_file.close
61
-
@@ -1,3 +0,0 @@
1
- task :valgrind do
2
- `valgrind --suppressions=gir_ffi-ruby1.9.1.supp ruby1.9.1 -Ilib -e "require 'gir_ffi'"`
3
- end
@@ -1,25 +0,0 @@
1
- require 'gir_ffi_test_helper'
2
-
3
- describe "threading" do
4
- it "works while a MainLoop is running" do
5
- main_loop = GLib::MainLoop.new nil, false
6
-
7
- a = []
8
- GLib.timeout_add(GLib::PRIORITY_DEFAULT, 100,
9
- proc { main_loop.quit },
10
- nil, nil)
11
-
12
- slow_thread = Thread.new do
13
- sleep 0.001
14
- a << "During run"
15
- end
16
-
17
- a << "Before run"
18
- main_loop.run
19
- a << "After run"
20
-
21
- slow_thread.join
22
-
23
- a.last.must_equal "After run"
24
- end
25
- end