gir_ffi 0.7.9 → 0.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9da5e936faa40d8974a094267b9da5c302fd08c
4
- data.tar.gz: 441e768cda62450ab418c941703e9cff26e28c0a
3
+ metadata.gz: c78011dfb34b7799b25df253c661de0b9bce5115
4
+ data.tar.gz: d83510e42c93f89563af82eb7e4d4316def805f5
5
5
  SHA512:
6
- metadata.gz: 09115a044eee555798d204123d566e10c7fb291f679fb2bfa6d18123716a618de6dcbcd5a23e49fc890b8d2c221046df21f34ac52e92d9939a1cd723fbdac3af
7
- data.tar.gz: 6cb2722920829fe0e81ca48ee8fd8e19d5fade1f34d461608c6d8cb43b5421917074b8173a0010e0a07e796ea57d0369799c3db39f81b6b8571a8beea5d5a8a4
6
+ metadata.gz: bd02e60de28ecdeff0b15eed790feed6c2e744df44bd473b10914573acced71c6c6613e55cf7f5bfbd62e21501fa6322274bc341be2a1de943ea574fdee82409
7
+ data.tar.gz: de8a61b783c0f46e9b83acb5157a3305bb66abda3e201f930021acf78786ea12b9d743e3c6783015df5b7663c5bb4c0c7ff430ff57cb64c6b5bed3b9fcc9c0ff
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.10 / 2015-09-16
4
+
5
+ * Allow ffi-gobject and ffi-glib to be required directly
6
+ * Improve documentation
7
+ * Remove arbitrary refcount check from finalizer (by John Cupitt)
8
+
3
9
  ## 0.7.9 / 2015-05-05
4
10
 
5
11
  * Unset GValues in finalizer
@@ -89,8 +95,6 @@
89
95
  * Handle method setup for methods with unsafe names (i.e., g_iconv())
90
96
  * Add override for GLib::IConv.open
91
97
 
92
- # Changelog
93
-
94
98
  ## 0.7.0 / 2014-01-11
95
99
 
96
100
  * Type handling:
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # The gem's dependencies are specified in gir_ffi.gemspec
4
+ gemspec
5
+
6
+ if ENV['CI']
7
+ gem 'coveralls', type: :development, platform: :mri
8
+ else
9
+ gem 'simplecov', '~> 0.10.0', type: :development, platform: :mri
10
+ gem 'pry', '~> 0.10.0', type: :development
11
+ end
data/README.md CHANGED
@@ -8,11 +8,12 @@ Ruby bindings for GNOME using the GObject Introspection Repository.
8
8
 
9
9
  ## Status
10
10
 
11
- [![Gem Version](https://badge.fury.io/rb/gir_ffi.png)](http://badge.fury.io/rb/gir_ffi)
12
- [![Dependency Status](https://gemnasium.com/mvz/gir_ffi.png)](https://gemnasium.com/mvz/gir_ffi)
13
- [![Build Status](https://travis-ci.org/mvz/gir_ffi.png?branch=master)](https://travis-ci.org/mvz/gir_ffi)
14
- [![Code Climate](https://codeclimate.com/github/mvz/gir_ffi.png)](https://codeclimate.com/github/mvz/gir_ffi)
15
- [![Coverage Status](https://coveralls.io/repos/mvz/gir_ffi/badge.png)](https://coveralls.io/r/mvz/gir_ffi)
11
+ [![Gem Version](https://badge.fury.io/rb/gir_ffi.svg)](http://badge.fury.io/rb/gir_ffi)
12
+ [![Dependency Status](https://gemnasium.com/mvz/gir_ffi.svg)](https://gemnasium.com/mvz/gir_ffi)
13
+ [![Build Status](https://travis-ci.org/mvz/gir_ffi.svg?branch=master)](https://travis-ci.org/mvz/gir_ffi)
14
+ [![Code Climate](https://codeclimate.com/github/mvz/gir_ffi/badges/gpa.svg)](https://codeclimate.com/github/mvz/gir_ffi)
15
+ [![Coverage Status](https://coveralls.io/repos/mvz/gir_ffi/badge.svg?branch=master&service=github)](https://coveralls.io/github/mvz/gir_ffi?branch=master)
16
+ [![Documentation Status](https://inch-ci.org/github/mvz/gir_ffi.svg?branch=master)](https://inch-ci.org/github/mvz/gir_ffi/branch/master)
16
17
 
17
18
  ## Features
18
19
 
@@ -1,5 +1,4 @@
1
- # NOTE: Do not require this file directly. Require 'gir_ffi' instead.
2
- #
1
+ require 'gir_ffi/core'
3
2
 
4
3
  GirFFI.setup :GLib
5
4
 
@@ -20,6 +20,18 @@ module GLib
20
20
  wrap type, ptr
21
21
  end
22
22
 
23
+ # @api private
24
+ def self.from_enumerable elmtype, it
25
+ new(elmtype).tap { |arr| arr.append_vals it }
26
+ end
27
+
28
+ # @api private
29
+ def self.calculated_element_size type
30
+ ffi_type = GirFFI::TypeMap.type_specification_to_ffi_type(type)
31
+ FFI.type_size(ffi_type)
32
+ end
33
+
34
+ # @override
23
35
  def append_vals ary
24
36
  bytes = GirFFI::InPointer.from_array element_type, ary
25
37
  Lib.g_array_append_vals(self, bytes, ary.length)
@@ -36,10 +48,6 @@ module GLib
36
48
  @struct[:len]
37
49
  end
38
50
 
39
- def data_ptr
40
- @struct[:data]
41
- end
42
-
43
51
  def get_element_size
44
52
  Lib.g_array_get_element_size self
45
53
  end
@@ -50,6 +58,7 @@ module GLib
50
58
  to_a == other.to_a
51
59
  end
52
60
 
61
+ # @api private
53
62
  def reset_typespec typespec = nil
54
63
  if typespec
55
64
  @element_type = typespec
@@ -60,15 +69,10 @@ module GLib
60
69
  self
61
70
  end
62
71
 
63
- def self.from_enumerable elmtype, it
64
- new(elmtype).tap { |arr| arr.append_vals it }
65
- end
66
-
67
72
  private
68
73
 
69
- def self.calculated_element_size type
70
- ffi_type = GirFFI::TypeMap.type_specification_to_ffi_type(type)
71
- FFI.type_size(ffi_type)
74
+ def data_ptr
75
+ @struct[:data]
72
76
  end
73
77
 
74
78
  def calculated_element_size
@@ -7,12 +7,13 @@ module GLib
7
7
 
8
8
  remove_method :get_data if method_defined? :get_data
9
9
 
10
- # Override for GBytes#get_data, needed due to mis-identification of the
11
- # element-type of the resulting sized array.
10
+ # @override
12
11
  def get_data
13
12
  length_ptr = GirFFI::InOutPointer.for :gsize
14
13
  data_ptr = Lib.g_bytes_get_data self, length_ptr
15
14
  length = length_ptr.to_value
15
+ # NOTE: Needed due to mis-identification of the element-type of the
16
+ # resulting sized array for the default binding.
16
17
  GirFFI::SizedArray.wrap(:guint8, length, data_ptr)
17
18
  end
18
19
 
@@ -11,26 +11,6 @@ module GLib
11
11
  attr_reader :key_type
12
12
  attr_reader :value_type
13
13
 
14
- def each
15
- prc = proc {|keyptr, valptr, _userdata|
16
- key = GirFFI::ArgHelper.cast_from_pointer key_type, keyptr
17
- val = GirFFI::ArgHelper.cast_from_pointer value_type, valptr
18
- yield key, val
19
- }
20
- callback = GLib::HFunc.from prc
21
- ::GLib::Lib.g_hash_table_foreach to_ptr, callback, nil
22
- end
23
-
24
- def to_hash
25
- Hash[to_a]
26
- end
27
-
28
- def insert key, value
29
- keyptr = GirFFI::InPointer.from key_type, key
30
- valptr = GirFFI::InPointer.from value_type, value
31
- ::GLib::Lib.g_hash_table_insert to_ptr, keyptr, valptr
32
- end
33
-
34
14
  class << self; remove_method :new; end
35
15
 
36
16
  def self.new keytype, valtype
@@ -38,11 +18,7 @@ module GLib
38
18
  hash_function_for(keytype), equality_function_for(keytype))
39
19
  end
40
20
 
41
- def reset_typespec typespec
42
- @key_type, @value_type = *typespec
43
- self
44
- end
45
-
21
+ # @api private
46
22
  def self.from_enumerable typespec, hash
47
23
  ghash = new(*typespec)
48
24
  hash.each do |key, val|
@@ -51,6 +27,7 @@ module GLib
51
27
  ghash
52
28
  end
53
29
 
30
+ # @api private
54
31
  def self.hash_function_for keytype
55
32
  case keytype
56
33
  when :utf8
@@ -60,6 +37,7 @@ module GLib
60
37
  end
61
38
  end
62
39
 
40
+ # @api private
63
41
  def self.equality_function_for keytype
64
42
  case keytype
65
43
  when :utf8
@@ -69,9 +47,37 @@ module GLib
69
47
  end
70
48
  end
71
49
 
50
+ # @api private
72
51
  def self.find_support_function name
73
52
  lib = ::GLib::Lib.ffi_libraries.first
74
53
  lib.find_function(name)
75
54
  end
55
+
56
+ def each
57
+ prc = proc {|keyptr, valptr, _userdata|
58
+ key = GirFFI::ArgHelper.cast_from_pointer key_type, keyptr
59
+ val = GirFFI::ArgHelper.cast_from_pointer value_type, valptr
60
+ yield key, val
61
+ }
62
+ callback = GLib::HFunc.from prc
63
+ ::GLib::Lib.g_hash_table_foreach to_ptr, callback, nil
64
+ end
65
+
66
+ def to_hash
67
+ Hash[to_a]
68
+ end
69
+
70
+ # @override
71
+ def insert key, value
72
+ keyptr = GirFFI::InPointer.from key_type, key
73
+ valptr = GirFFI::InPointer.from value_type, value
74
+ ::GLib::Lib.g_hash_table_insert to_ptr, keyptr, valptr
75
+ end
76
+
77
+ # @api private
78
+ def reset_typespec typespec
79
+ @key_type, @value_type = *typespec
80
+ self
81
+ end
76
82
  end
77
83
  end
@@ -1,5 +1,4 @@
1
- # NOTE: Do not require this file directly. Require 'gir_ffi' instead.
2
- #
1
+ require 'gir_ffi/core'
3
2
 
4
3
  GirFFI.setup :GObject
5
4
 
@@ -2,7 +2,12 @@ GObject.load_class :Closure
2
2
 
3
3
  module GObject
4
4
  # Overrides for GClosure, GObject's base class for closure objects.
5
+ #
6
+ # To create Closure objects wrapping Ruby code, use {RubyClosure}.
5
7
  class Closure
8
+ # @override
9
+ #
10
+ # @param [Proc] marshal The marshaller to use for this closure object
6
11
  def set_marshal marshal
7
12
  callback = GObject::ClosureMarshal.from marshal
8
13
  Lib.g_closure_set_marshal self, callback
@@ -14,7 +14,7 @@ module GObject
14
14
  def self.make_finalizer ptr, name
15
15
  proc {
16
16
  rc = GObject::Object::Struct.new(ptr)[:ref_count]
17
- if rc == 0 || rc > 100
17
+ if rc == 0
18
18
  warn "not unreffing #{name}:#{ptr} (#{rc})"
19
19
  else
20
20
  GObject::Lib.g_object_unref ptr
@@ -1,32 +1,20 @@
1
1
  require 'ffi-gobject/closure'
2
2
 
3
3
  module GObject
4
- # This class encapsulates Ruby
5
- # blocks as GObject Closures.
4
+ # Encapsulates Ruby blocks as GObject Closures.
6
5
  class RubyClosure < Closure
6
+ # @api private
7
7
  BLOCK_STORE = {}
8
8
 
9
- # Extend the standard GClosure layout with a field block_id to store
9
+ # Extend the standard +GObject::Closure+ layout with a field block_id to store
10
10
  # the object_id of the associated block.
11
+ #
12
+ # @api private
11
13
  class Struct < FFI::Struct
12
14
  layout :parent, Closure::Struct, 0,
13
15
  :block_id, :int64
14
16
  end
15
17
 
16
- def block
17
- BLOCK_STORE[@struct[:block_id]]
18
- end
19
-
20
- def block= block
21
- id = block.object_id
22
- BLOCK_STORE[id] = block
23
- @struct[:block_id] = id
24
- end
25
-
26
- def invoke_block *args
27
- block.call(*args)
28
- end
29
-
30
18
  def self.new &block
31
19
  raise ArgumentError unless block_given?
32
20
 
@@ -37,6 +25,7 @@ module GObject
37
25
  closure
38
26
  end
39
27
 
28
+ # @api private
40
29
  def self.marshaller closure, return_value, param_values, _invocation_hint, _marshal_data
41
30
  # TODO: Improve by registering RubyClosure as a GObject type
42
31
  rclosure = wrap(closure.to_ptr)
@@ -48,5 +37,24 @@ module GObject
48
37
 
49
38
  return_value.set_ruby_value(result) if return_value
50
39
  end
40
+
41
+ # @api private
42
+ # TODO: Re-structure so block= and invoke_block can become private methods
43
+ def block= block
44
+ id = block.object_id
45
+ BLOCK_STORE[id] = block
46
+ @struct[:block_id] = id
47
+ end
48
+
49
+ # @api private
50
+ def invoke_block *args
51
+ block.call(*args)
52
+ end
53
+
54
+ private
55
+
56
+ def block
57
+ BLOCK_STORE[@struct[:block_id]]
58
+ end
51
59
  end
52
60
  end
@@ -1,37 +1,4 @@
1
- require 'ffi'
2
-
3
- require 'gir_ffi-base'
4
-
5
- require 'ffi-gobject_introspection'
6
-
7
- require 'gir_ffi/ffi_ext'
8
- require 'gir_ffi/class_base'
9
- require 'gir_ffi/type_map'
10
- require 'gir_ffi/info_ext'
11
- require 'gir_ffi/in_pointer'
12
- require 'gir_ffi/in_out_pointer'
13
- require 'gir_ffi/sized_array'
14
- require 'gir_ffi/zero_terminated'
15
- require 'gir_ffi/arg_helper'
16
- require 'gir_ffi/user_defined_type_info'
17
- require 'gir_ffi/builder'
18
- require 'gir_ffi/version'
19
-
20
- # Main module containing classes and modules needed for generating GLib and
21
- # GObject bindings.
22
- module GirFFI
23
- def self.setup module_name, version = nil
24
- module_name = module_name.to_s
25
- GirFFI::Builder.build_module module_name, version
26
- end
27
-
28
- def self.define_type klass, &block
29
- info = UserDefinedTypeInfo.new(klass, &block)
30
- Builders::UserDefinedBuilder.new(info).build_class
31
-
32
- klass.gtype
33
- end
34
- end
1
+ require 'gir_ffi/core'
35
2
 
36
3
  require 'ffi-glib'
37
4
  require 'ffi-gobject'
@@ -0,0 +1,34 @@
1
+ require 'ffi'
2
+
3
+ require 'gir_ffi-base'
4
+
5
+ require 'ffi-gobject_introspection'
6
+
7
+ require 'gir_ffi/ffi_ext'
8
+ require 'gir_ffi/class_base'
9
+ require 'gir_ffi/type_map'
10
+ require 'gir_ffi/info_ext'
11
+ require 'gir_ffi/in_pointer'
12
+ require 'gir_ffi/in_out_pointer'
13
+ require 'gir_ffi/sized_array'
14
+ require 'gir_ffi/zero_terminated'
15
+ require 'gir_ffi/arg_helper'
16
+ require 'gir_ffi/user_defined_type_info'
17
+ require 'gir_ffi/builder'
18
+ require 'gir_ffi/version'
19
+
20
+ # Main module containing classes and modules needed for generating GLib and
21
+ # GObject bindings.
22
+ module GirFFI
23
+ def self.setup module_name, version = nil
24
+ module_name = module_name.to_s
25
+ GirFFI::Builder.build_module module_name, version
26
+ end
27
+
28
+ def self.define_type klass, &block
29
+ info = UserDefinedTypeInfo.new(klass, &block)
30
+ Builders::UserDefinedBuilder.new(info).build_class
31
+
32
+ klass.gtype
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
1
  # Current GirFFI version
2
2
  module GirFFI
3
- VERSION = '0.7.9'
3
+ VERSION = '0.7.10'
4
4
  end
@@ -70,12 +70,14 @@ describe GLib::Array do
70
70
  describe '.from' do
71
71
  it 'creates a GArray from an array of :gint32' do
72
72
  arr = GLib::Array.from :gint32, [3, 2, 1]
73
- arr.data_ptr.read_array_of_int32(3).must_equal [3, 2, 1]
73
+ arr.must_be_instance_of GLib::Array
74
+ arr.to_a.must_equal [3, 2, 1]
74
75
  end
75
76
 
76
77
  it 'creates a GArray from an array of :gboolean' do
77
78
  arr = GLib::Array.from :gboolean, [true, false, true]
78
- arr.data_ptr.read_array_of_int(3).must_equal [1, 0, 1]
79
+ arr.must_be_instance_of GLib::Array
80
+ arr.to_a.must_equal [true, false, true]
79
81
  end
80
82
 
81
83
  it 'return its argument if given a GArray' do
@@ -16,7 +16,7 @@ describe GObject::RubyClosure do
16
16
  a = 0
17
17
  c = GObject::RubyClosure.new { a = 2 }
18
18
  c2 = GObject::RubyClosure.wrap(c.to_ptr)
19
- c2.block.call
19
+ c2.invoke_block
20
20
  assert_equal 2, a
21
21
  end
22
22
 
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.9
4
+ version: 0.7.10
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: 2015-05-05 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 5.5.1
47
+ version: '5.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 5.5.1
54
+ version: '5.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest-rspec_mocks
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.0
61
+ version: 0.3.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.0
68
+ version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -98,11 +98,11 @@ files:
98
98
  - COPYING.LIB
99
99
  - Changelog.md
100
100
  - DESIGN.md
101
+ - Gemfile
101
102
  - README.md
102
103
  - Rakefile
103
104
  - TODO.md
104
105
  - examples/main_loop.rb
105
- - gir_ffi.gemspec
106
106
  - lib/ffi-glib.rb
107
107
  - lib/ffi-glib/array.rb
108
108
  - lib/ffi-glib/array_methods.rb
@@ -202,6 +202,7 @@ files:
202
202
  - lib/gir_ffi/builders/with_layout.rb
203
203
  - lib/gir_ffi/callback_base.rb
204
204
  - lib/gir_ffi/class_base.rb
205
+ - lib/gir_ffi/core.rb
205
206
  - lib/gir_ffi/enum_base.rb
206
207
  - lib/gir_ffi/error_argument_info.rb
207
208
  - lib/gir_ffi/error_type_info.rb
@@ -370,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
371
  version: '0'
371
372
  requirements: []
372
373
  rubyforge_project:
373
- rubygems_version: 2.4.5
374
+ rubygems_version: 2.4.5.1
374
375
  signing_key:
375
376
  specification_version: 4
376
377
  summary: FFI-based GObject binding using the GObject Introspection Repository
@@ -1,41 +0,0 @@
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.5.1"])
37
- s.add_development_dependency('minitest-rspec_mocks', ["~> 0.2.0"])
38
- s.add_development_dependency('rake', ["~> 10.1"])
39
-
40
- s.require_paths = ["lib"]
41
- end