gir_ffi 0.18.0 → 0.19.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +81 -53
  3. data/README.md +1 -1
  4. data/TODO.md +40 -32
  5. data/lib/ffi-glib/array.rb +1 -1
  6. data/lib/ffi-glib/destroy_notify.rb +8 -0
  7. data/lib/ffi-glib/list_methods.rb +1 -0
  8. data/lib/ffi-glib/ptr_array.rb +1 -1
  9. data/lib/ffi-gobject/object.rb +6 -1
  10. data/lib/ffi-gobject/ruby_closure.rb +2 -2
  11. data/lib/ffi-gobject/value.rb +5 -5
  12. data/lib/ffi-gobject.rb +16 -5
  13. data/lib/ffi-gobject_introspection/gobject_type_init.rb +1 -0
  14. data/lib/ffi-gobject_introspection/lib.rb +1 -0
  15. data/lib/ffi-gobject_introspection/strv.rb +5 -4
  16. data/lib/gir_ffi/array_element_convertor.rb +3 -1
  17. data/lib/gir_ffi/boolean.rb +5 -3
  18. data/lib/gir_ffi/boxed_base.rb +2 -0
  19. data/lib/gir_ffi/builders/argument_builder.rb +2 -4
  20. data/lib/gir_ffi/builders/argument_builder_collection.rb +3 -3
  21. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +3 -0
  22. data/lib/gir_ffi/builders/field_builder.rb +9 -7
  23. data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -1
  24. data/lib/gir_ffi/builders/method_template.rb +1 -1
  25. data/lib/gir_ffi/builders/module_builder.rb +2 -2
  26. data/lib/gir_ffi/builders/object_builder.rb +8 -0
  27. data/lib/gir_ffi/builders/property_builder.rb +5 -1
  28. data/lib/gir_ffi/builders/registered_type_builder.rb +12 -8
  29. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +1 -1
  30. data/lib/gir_ffi/callback_base.rb +0 -1
  31. data/lib/gir_ffi/enum_base.rb +4 -4
  32. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -3
  33. data/lib/gir_ffi/in_pointer.rb +10 -4
  34. data/lib/gir_ffi/info_ext/i_signal_info.rb +1 -1
  35. data/lib/gir_ffi/info_ext/i_type_info.rb +1 -1
  36. data/lib/gir_ffi/lib_c.rb +1 -0
  37. data/lib/gir_ffi/method_stubber.rb +1 -1
  38. data/lib/gir_ffi/object_base.rb +4 -4
  39. data/lib/gir_ffi/object_store.rb +2 -2
  40. data/lib/gir_ffi/sized_array.rb +2 -1
  41. data/lib/gir_ffi/struct_like_base.rb +2 -2
  42. data/lib/gir_ffi/unintrospectable_signal_info.rb +1 -1
  43. data/lib/gir_ffi/user_defined_property_info.rb +4 -0
  44. data/lib/gir_ffi/version.rb +1 -1
  45. data/lib/gir_ffi/zero_terminated.rb +6 -32
  46. metadata +8 -202
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a0a971b16d81d55e25b0944aaaf1ae8c28e8546a416b699902e7f254e5ae79d
4
- data.tar.gz: 5ef09a4c0f0e2f3fbf9afc7c0de7878fa9e44e65a4808a5f0489119139dcc8b7
3
+ metadata.gz: 6c0e4b67ec7da9640bab9e8ad5b6af3a21ca34f7f3bb28bc471418952e361325
4
+ data.tar.gz: 6f86337879c11b41bb57ced5b367dee0785739afc4761203e34140b9fbb8b561
5
5
  SHA512:
6
- metadata.gz: 35c6e4c0d8f99d790685fc7c4f3a7ad1dcd602696b204c52dc837cc361c7843e0b57887f06e3aca96c55d75e651dac26add7c677d01ddbe3ae275e91615c84fd
7
- data.tar.gz: a516176df5475cdc56995c20c84f50bc906e9c3c299c577d3354d9059db07b1deb412a1902c9ca1bc07f43849524a5b93c3659fc6489e172b5b8f24f03aba4c2
6
+ metadata.gz: 931112391d502613f9c1ec82db244ab0dcf26c56a8a45aca3b9b272f6840a07757c1f6b47bbeebb3f2c57902ac2b30edca379ac991f2744cee2587fd69e07a2f
7
+ data.tar.gz: 34624b92c7c209aa9a8dd8e6a95e6a378831f39ac0b7af8ac728e9a9cfbf1cd3dc032021d5ae75da797691436123ef382648de5d5df859417c8b55c055d41d83
data/Changelog.md CHANGED
@@ -1,9 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.0 / 2026-05-02
4
+
5
+ * Allow specifying signals as symbols ([#382] by [mvz])
6
+ * Support Ruby 3.2 through 4.0, dropping support for Ruby 3.1
7
+ ([#383] and [#390] by [mvz])
8
+ * Handle uninitialized Boxed out parameter ([#396] by [mvz])
9
+ * Handle fixed size arrays of GStrv ([#403] by [mvz])
10
+ * Return nil when wrapping a null pointer with GStrv ([#404] by [mvz])
11
+ * Handle zero-terminated arrays of GStrv ([#405] by [mvz])
12
+ * Read elements of GStrv as UTF8 strings ([#406] by [mvz])
13
+ * Handle null GValue return values and out parameters ([#407] by [mvz])
14
+ * Support vfuncs returning a value of type flags ([#412] by [mvz])
15
+ * Block reading of write-only properties ([#413] by [mvz])
16
+ * Ensure class structs are initialized ([#415] by [mvz])
17
+
18
+ [#382]: https://github.com/mvz/gir_ffi/pull/382
19
+ [#383]: https://github.com/mvz/gir_ffi/pull/383
20
+ [#390]: https://github.com/mvz/gir_ffi/pull/390
21
+ [#396]: https://github.com/mvz/gir_ffi/pull/396
22
+ [#403]: https://github.com/mvz/gir_ffi/pull/403
23
+ [#404]: https://github.com/mvz/gir_ffi/pull/404
24
+ [#405]: https://github.com/mvz/gir_ffi/pull/405
25
+ [#406]: https://github.com/mvz/gir_ffi/pull/406
26
+ [#407]: https://github.com/mvz/gir_ffi/pull/407
27
+ [#412]: https://github.com/mvz/gir_ffi/pull/412
28
+ [#413]: https://github.com/mvz/gir_ffi/pull/413
29
+ [#415]: https://github.com/mvz/gir_ffi/pull/415
30
+
3
31
  ## 0.18.0 / 2025-02-07
4
32
 
5
33
  * Update contribution guidelines ([#360] by [mvz])
6
- * Support Ruby 3.1 through 3.4, dripping support for Ruby 3.0 ([#366] by [mvz])
34
+ * Support Ruby 3.1 through 3.4, dropping support for Ruby 3.0 ([#366] by [mvz])
7
35
  * Load gobject-2.0 library in a way that does not require the dev package
8
36
  ([#367] by [mvz])
9
37
  * Update tests for compatibility with GObjectIntrospection 1.81.2 ([#378] by [mvz])
@@ -201,16 +229,16 @@
201
229
  ## 0.10.1 / 2016-03-28
202
230
 
203
231
  * Restore JRuby compatibility.
204
- - Introduce #owned to flag unions and structs for release at garbage collection time.
205
- In JRuby's implementation, FFI::Pointer does not implement #autorelease=
206
- and #autorelease?, so this different technique is used to free pointers
207
- allocated by GLib. It is in fact doubtful that setting autorelease had any
208
- actual effect even on CRuby.
209
- - Immediately free string pointers whose ownership is transfered. Again, the
210
- #autorelease technique doesn't work on JRuby.
211
- - Fix handling of callee-allocated out parameters in vfuncs. The `put_pointer`
212
- method was wrongly called, and JRuby is more picky about what types that
213
- method expects, exposing the bug.
232
+ * Introduce `#owned` to flag unions and structs for release at garbage
233
+ collection time. In JRuby's implementation, FFI::Pointer does not
234
+ implement `#autorelease=` and `#autorelease?`, so this different technique
235
+ is used to free pointers allocated by GLib. It is in fact doubtful that
236
+ setting autorelease had any actual effect even on CRuby.
237
+ * Immediately free string pointers whose ownership is transfered. Again, the
238
+ #autorelease technique doesn't work on JRuby.
239
+ * Fix handling of callee-allocated out parameters in vfuncs. The `put_pointer`
240
+ method was wrongly called, and JRuby is more picky about what types that
241
+ method expects, exposing the bug.
214
242
 
215
243
  ## 0.10.0 / 2016-03-23
216
244
 
@@ -283,16 +311,16 @@
283
311
  ## 0.8.6 / 2015-12-09
284
312
 
285
313
  * Change handling of initializers in subclasses
286
- * Subclasses with their own GType revert to the default GObject constructor
287
- * Subclasses cannot use their parent classes' non-default contructors
314
+ * Subclasses with their own GType revert to the default GObject constructor
315
+ * Subclasses cannot use their parent classes' non-default contructors
288
316
  * Find signals in ancestor classes of unintrospectable types
289
317
 
290
318
  ## 0.8.5 / 2015-12-04
291
319
 
292
320
  * Improve GObject::Value
293
- * Make `#wrap_ruby_value` work for object classes
294
- * Use non-deprecated methods for getting and setting char values
295
- * Make `set_value` and `get_value` work for interface types
321
+ * Make `#wrap_ruby_value` work for object classes
322
+ * Use non-deprecated methods for getting and setting char values
323
+ * Make `set_value` and `get_value` work for interface types
296
324
 
297
325
  ## 0.8.4 / 2015-12-03
298
326
 
@@ -312,14 +340,14 @@
312
340
 
313
341
  * Use inherited constructor for boxed types
314
342
  * Make `InOutPointer` work correctly for boxed types
315
- * Make `.for` work with boxed types
316
- * Make `#set_value` work with boxed types
343
+ * Make `.for` work with boxed types
344
+ * Make `#set_value` work with boxed types
317
345
  * Make GObject::Value support nil type:
318
- * Make `.wrap_ruby_value(nil)` work
319
- * Make `#set_value` and `#get_value` work when the type is `TYPE_INVALID`
320
- * Make `.for_gtype` work with `TYPE_INVALID` and `TYPE_NONE`
321
- * Make `.from(nil)` return a `GObject::Value` instead of nil
322
- * Make `#set_ruby_value` private
346
+ * Make `.wrap_ruby_value(nil)` work
347
+ * Make `#set_value` and `#get_value` work when the type is `TYPE_INVALID`
348
+ * Make `.for_gtype` work with `TYPE_INVALID` and `TYPE_NONE`
349
+ * Make `.from(nil)` return a `GObject::Value` instead of nil
350
+ * Make `#set_ruby_value` private
323
351
  * Make `GObject::Object.signal_emit` work with gobject-introspection 1.46
324
352
  * Replace or remove all custom `.new` methods
325
353
  * Make `setup_method` and `setup_instance_method` handle symbol arguments
@@ -386,8 +414,8 @@
386
414
  * Provide constant `TYPE_BYTE_ARRAY`
387
415
  * Don't recurse looking for signals and properties
388
416
  * Clean up generated code:
389
- * Avoid use of an ignored dummy argument
390
- * Clean up trailing whitespace
417
+ * Avoid use of an ignored dummy argument
418
+ * Clean up trailing whitespace
391
419
  * Drop support for Ruby 1.9.2
392
420
  * Allow data argument for `GObject::Object#signal_connect`
393
421
  * Let Ruby threads run during GLib's main loop
@@ -432,25 +460,25 @@
432
460
  ## 0.7.0 / 2014-01-11
433
461
 
434
462
  * Type handling:
435
- * Handle c arrays with separate length argument for signals
436
- * Handle GHashTable values of type `:gint8` and `:guint32`
437
- * Handle signals with int64, Strv, uint64 arguments
438
- * Handle arrays of integers cast as pointers
439
- * Handle fields of callback type
440
- * Handle nested GHashTable
463
+ * Handle c arrays with separate length argument for signals
464
+ * Handle GHashTable values of type `:gint8` and `:guint32`
465
+ * Handle signals with int64, Strv, uint64 arguments
466
+ * Handle arrays of integers cast as pointers
467
+ * Handle fields of callback type
468
+ * Handle nested GHashTable
441
469
  * Argument handling:
442
- * Refactor argument builder system
443
- * Improve handling of user data arguments
444
- * Handle signal and callback arguments with direction :out
445
- * Handle aliases of container types by making the element type optional
446
- * Handle signal and callback return values that need conversion
470
+ * Refactor argument builder system
471
+ * Improve handling of user data arguments
472
+ * Handle signal and callback arguments with direction :out
473
+ * Handle aliases of container types by making the element type optional
474
+ * Handle signal and callback return values that need conversion
447
475
  * User defined types:
448
- * Pass explicit receiver to initialization block for UserDefinedTypeInfo
449
- * Allow user defined types that are anonymous Ruby classes
450
- * Register defined properties in a subclass
451
- * Support setting virtual function implementations in a subclass
452
- * Support adding an interface to a subclass
453
- * Support implementing an interface's virtual functions in a subclass
476
+ * Pass explicit receiver to initialization block for UserDefinedTypeInfo
477
+ * Allow user defined types that are anonymous Ruby classes
478
+ * Register defined properties in a subclass
479
+ * Support setting virtual function implementations in a subclass
480
+ * Support adding an interface to a subclass
481
+ * Support implementing an interface's virtual functions in a subclass
454
482
  * Use FFI's DataConvertor system to handle enums and callbacks
455
483
  * Stop using deprecated GValueArray to construct argument array for `signal_emit`
456
484
  * Make `ITypeInfo#g_type` return correct value for c arrays
@@ -601,13 +629,13 @@
601
629
 
602
630
  * Add support for properties, with `#get_property` and `#set_property`.
603
631
  * Add support for fields.
604
- - Create field accessor methods.
605
- - Get rid of `#[]` and `#[]=`.
632
+ * Create field accessor methods.
633
+ * Get rid of `#[]` and `#[]=`.
606
634
  * Explicitely load `libgirepository` with ABI version 1.
607
635
  * Improve implementation of GLib container classes (GList etc.):
608
- - Real constructors.
609
- - `#append` and friends are instance methods now.
610
- - Conversion methods to cast Ruby containers to GLib containers.
636
+ * Real constructors.
637
+ * `#append` and friends are instance methods now.
638
+ * Conversion methods to cast Ruby containers to GLib containers.
611
639
  * Start implementing pretty printing.
612
640
  * Various refactorings.
613
641
 
@@ -620,10 +648,10 @@
620
648
  ## 0.0.14 / 2011-10-28
621
649
 
622
650
  * Support GObject Introspection version 1.30:
623
- - Add support for layouts with fixed-length arrays.
624
- - Handle type names starting with underscores.
625
- - Call `g_signal_emitv` directly to avoid conflict in introspection info
626
- with earlier versions of GObject Introspection.
651
+ * Add support for layouts with fixed-length arrays.
652
+ * Handle type names starting with underscores.
653
+ * Call `g_signal_emitv` directly to avoid conflict in introspection info
654
+ with earlier versions of GObject Introspection.
627
655
 
628
656
  ## 0.0.13 / 2011-09-09
629
657
 
@@ -675,8 +703,8 @@
675
703
  ## 0.0.7 / 2011-04-01
676
704
 
677
705
  * Support gobject-introspection 0.10, drop support for earlier versions.
678
- - Use Regress, not Everything, for testing.
679
- - Deal with functions that are no longer introspectable.
706
+ * Use Regress, not Everything, for testing.
707
+ * Deal with functions that are no longer introspectable.
680
708
  * Correctly handle constructors that declare their return type different
681
709
  from their class.
682
710
  * Implement `RubyClosure`, a `GObject::Closure` for handling ruby callbacks.
data/README.md CHANGED
@@ -57,7 +57,7 @@ gem install gir_ffi
57
57
 
58
58
  ## Requirements
59
59
 
60
- GirFFI is supported on CRuby 2.7, 3.0 and 3.1.
60
+ GirFFI is supported on CRuby 3.2 through 4.0.
61
61
 
62
62
  You will also need gobject-introspection installed with some
63
63
  introspection data.
data/TODO.md CHANGED
@@ -3,12 +3,14 @@
3
3
  ## Memory managment
4
4
 
5
5
  GirFFI does not ~~attempt to free any memory at the moment, or~~ lower the
6
- reference count of any objects it gets from GObject. This task therefore involves two parts:
6
+ reference count of any objects it gets from GObject. This task therefore
7
+ involves two parts:
7
8
 
8
9
  - Free non-GObject pointers as needed (at garbage-collection time)
9
10
  - [Done!] Lower reference count of GObjects (at garbage-collection time)
10
11
 
11
- **Use memory_profiler to check memory use (https://github.com/SamSaffron/memory_profiler)**
12
+ **Use [memory_profiler](https://github.com/SamSaffron/memory_profiler) to check
13
+ memory use**
12
14
 
13
15
  ## Refactorings
14
16
 
@@ -28,33 +30,35 @@ These in the order they occured to me, and may therefore be fixed in any order.
28
30
 
29
31
  Derived classes are now registered like so:
30
32
 
31
- class Derived < Base
32
- install_property GObject.param_spec_int("foo", "foo bar",
33
- "The Foo Bar Property",
34
- 10, 20, 15, 3)
33
+ ```ruby
34
+ class Derived < Base
35
+ install_property GObject.param_spec_int("foo", "foo bar",
36
+ "The Foo Bar Property",
37
+ 10, 20, 15, 3)
35
38
 
36
- # assume Base defines a virtual function called 'some_vfunc'
37
- install_vfunc_implementation :some_vfunc, proc {|obj|
38
- # implementation goes here
39
- }
39
+ # assume Base defines a virtual function called 'some_vfunc'
40
+ install_vfunc_implementation :some_vfunc, proc {|obj|
41
+ # implementation goes here
42
+ }
40
43
 
41
- def other_vfunc
42
- # implementation
43
- end
44
+ def other_vfunc
45
+ # implementation
46
+ end
44
47
 
45
- # assume Base defines a virtual function called 'other_vfunc'
46
- install_vfunc_implementation :other_vfunc
47
- end
48
+ # assume Base defines a virtual function called 'other_vfunc'
49
+ install_vfunc_implementation :other_vfunc
50
+ end
48
51
 
49
- GirFFI.define_type Derived
52
+ GirFFI.define_type Derived
53
+ ```
50
54
 
51
55
  Potential improvements:
52
56
 
53
- * Allow `define_type` to be called in the class definition
54
- * Perhaps auto-register types, like Gtk# does
55
- * Perhaps automagically find vfunc implementations, like PyGObject and
57
+ - Allow `define_type` to be called in the class definition
58
+ - Perhaps auto-register types, like Gtk# does
59
+ - Perhaps automagically find vfunc implementations, like PyGObject and
56
60
  Ruby-GNOME do
57
- * What about properties?
61
+ - What about properties?
58
62
 
59
63
  NOTE: When adding an interface module to a derived class, its prerequisites
60
64
  should be checked.
@@ -65,7 +69,7 @@ GirFFI should make sure that if it gets a pointer to a GObject for which a Ruby
65
69
  object already exists, the existing object is returned. This involves the use
66
70
  of WeakRef, no doubt.
67
71
 
68
- ## Handle fundamental objects that are not GObject.
72
+ ## Handle fundamental objects that are not GObject
69
73
 
70
74
  This is a big one. See commit 1e9822c7817062a9b853269b9418fd78782090b5 in
71
75
  gobject-introspection, and TestFundamentalObject in Regress.
@@ -73,12 +77,16 @@ gobject-introspection, and TestFundamentalObject in Regress.
73
77
  The tests for TestFundamentalObject accidentally pass, but there may be
74
78
  hidden issues.
75
79
 
76
- ## Check binding of GObject:
80
+ ## Check binding of GObject
77
81
 
78
- (11:37:03 PM) walters: the basic story is that GObject should be manually bound
79
- (11:47:02 PM) ebassi: the really necessary bits are: GObject/GInitiallyUnowned memory management; properties accessors; GSignal connection API
80
- (11:47:15 PM) ebassi: the rest is "nice to have"
81
- (11:47:37 PM) ebassi: oh, and probably GBinding - but that's just because I wrote it ;-)
82
+ ```
83
+ (11:37:03 PM) walters: the basic story is that GObject should be manually bound
84
+ (11:47:02 PM) ebassi: the really necessary bits are: GObject/GInitiallyUnowned
85
+ memory management; properties accessors; GSignal connection API
86
+ (11:47:15 PM) ebassi: the rest is "nice to have"
87
+ (11:47:37 PM) ebassi: oh, and probably GBinding - but that's just because I
88
+ wrote it ;-)
89
+ ```
82
90
 
83
91
  ## Use FFI::DataConverter to automatically convert GObject types
84
92
 
@@ -96,20 +104,20 @@ to be put in place for that.
96
104
 
97
105
  ## Handle ownership-transfer correctly
98
106
 
99
- For how to handle objects, see https://bugzilla.gnome.org/show_bug.cgi?id=657202#c1
107
+ For how to handle objects, see [this comment on Gnome bug 657202](https://bugzilla.gnome.org/show_bug.cgi?id=657202#c1).
100
108
 
101
109
  ## Miscellaneous
102
110
 
103
- * Move GObjectIntrospection to GIRepository, and allow generating its own
111
+ - Move GObjectIntrospection to GIRepository, and allow generating its own
104
112
  members.
105
- * Do something useful with the versioning info in the GIR
113
+ - Do something useful with the versioning info in the GIR
106
114
 
107
115
  ## External dependencies
108
116
 
109
117
  Things that I think GirFFI cannot fix:
110
118
 
111
- * gobject-introspection should correctly mark private fields as not readable.
112
- * gobject-introspection should ignore functions that are only defined but not
119
+ - gobject-introspection should correctly mark private fields as not readable.
120
+ - gobject-introspection should ignore functions that are only defined but not
113
121
  implemented, or implement those cases in GIMarshallingTests.
114
122
 
115
123
  ## See Also
@@ -22,7 +22,7 @@ module GLib
22
22
 
23
23
  # @api private
24
24
  def self.from_enumerable(elmtype, arr)
25
- new(elmtype).tap { |it| it.append_vals arr }
25
+ new(elmtype).tap { _1.append_vals arr }
26
26
  end
27
27
 
28
28
  # @api private
@@ -7,6 +7,14 @@ module GLib
7
7
  # It should not be necessary to create objects of this class from Ruby
8
8
  # directly.
9
9
  class DestroyNotify
10
+ # Return the default DestroyNotify object used when calling functions that
11
+ # take a DestroyNotify argument.
12
+ #
13
+ # GirFFI uses a singleton object here to ensure it will always exist when
14
+ # called from the C side.
15
+ #
16
+ # This assumes ClosureToPointerConvertor creates code store the callbacak
17
+ # to be destroyed using ArgHelper.store.
10
18
  def self.default
11
19
  @default ||= from proc { |user_data|
12
20
  callback = GirFFI::ArgHelper::OBJECT_STORE.fetch(user_data)
@@ -6,6 +6,7 @@ module GLib
6
6
  # Common methods for List and SList.
7
7
  module ListMethods
8
8
  include Enumerable
9
+
9
10
  attr_reader :element_type
10
11
 
11
12
  def self.included(base)
@@ -27,7 +27,7 @@ module GLib
27
27
  end
28
28
 
29
29
  def self.from_enumerable(type, arr)
30
- new(type).tap { |it| it.add_array arr }
30
+ new(type).tap { _1.add_array arr }
31
31
  end
32
32
 
33
33
  def self.add(array, data)
@@ -124,7 +124,12 @@ module GObject
124
124
  # Overrides for GObject, GObject's generic base class.
125
125
  module Overrides
126
126
  def get_property(property_name)
127
- gvalue = gvalue_for_property property_name
127
+ spec = property_param_spec(property_name)
128
+ unless spec.flags[:readable]
129
+ raise ArgumentError, "Property #{property_name} is not readable"
130
+ end
131
+
132
+ gvalue = GObject::Value.for_gtype spec.value_type
128
133
  super property_name, gvalue
129
134
  value = gvalue.get_value
130
135
 
@@ -41,8 +41,8 @@ module GObject
41
41
 
42
42
  # @api private
43
43
  # TODO: Re-structure so invoke_block can become a private method
44
- def invoke_block(*args)
45
- block.call(*args)
44
+ def invoke_block(*)
45
+ block.call(*)
46
46
  end
47
47
 
48
48
  private
@@ -48,16 +48,16 @@ module GObject
48
48
  end
49
49
 
50
50
  def self.for_gtype(gtype)
51
- new.tap do |it|
52
- it.init gtype
51
+ new.tap do |val|
52
+ val.init gtype
53
53
  end
54
54
  end
55
55
 
56
56
  # TODO: Combine with wrap_ruby_value
57
57
  def self.wrap_instance(instance)
58
- new.tap do |it|
59
- it.init GObject.type_from_instance instance
60
- it.set_instance instance
58
+ new.tap do |val|
59
+ val.init GObject.type_from_instance instance
60
+ val.set_instance instance
61
61
  end
62
62
  end
63
63
 
data/lib/ffi-gobject.rb CHANGED
@@ -36,11 +36,12 @@ module GObject
36
36
  end
37
37
 
38
38
  def self.signal_emit(object, detailed_signal, *args)
39
- signal, detail = detailed_signal.split("::")
40
- signal_id = signal_lookup_from_instance signal, object
39
+ _, signal_name, detail = process_detailed_signal detailed_signal
40
+
41
+ signal_id = signal_lookup_from_instance signal_name, object
41
42
  detail_quark = GLib.quark_from_string(detail)
42
43
 
43
- sig_info = object.class.find_signal signal
44
+ sig_info = object.class.find_signal signal_name
44
45
  argument_gvalues = sig_info.arguments_to_gvalues object, args
45
46
  return_gvalue = sig_info.gvalue_for_return_value
46
47
 
@@ -50,9 +51,9 @@ module GObject
50
51
  def self.signal_connect(object, detailed_signal, data = nil, after = false, &block)
51
52
  block or raise ArgumentError, "Block needed"
52
53
 
53
- signal_name, = detailed_signal.split("::")
54
- sig_info = object.class.find_signal signal_name
54
+ detailed_signal, signal_name, = process_detailed_signal detailed_signal
55
55
 
56
+ sig_info = object.class.find_signal signal_name
56
57
  closure = sig_info.wrap_in_closure do |*args|
57
58
  yield(*args << data)
58
59
  end
@@ -64,6 +65,16 @@ module GObject
64
65
  signal_connect(object, detailed_signal, data, true, &)
65
66
  end
66
67
 
68
+ class << self
69
+ private
70
+
71
+ def process_detailed_signal(detailed_signal)
72
+ detailed_signal = detailed_signal.to_s.tr("_", "-") if detailed_signal.is_a?(Symbol)
73
+ signal_name, detail = detailed_signal.split("::")
74
+ return detailed_signal, signal_name, detail
75
+ end
76
+ end
77
+
67
78
  load_class :Callback
68
79
  load_class :ClosureNotify
69
80
  load_class :ConnectFlags
@@ -12,6 +12,7 @@ module GObjectIntrospection
12
12
  # Module for attaching g_type_init from the gobject library.
13
13
  module Lib
14
14
  extend FFI::Library
15
+
15
16
  ffi_lib "gobject-2.0.so.0"
16
17
  attach_function :g_type_init, [], :void
17
18
  end
@@ -8,6 +8,7 @@ module GObjectIntrospection
8
8
  module Lib
9
9
  extend FFI::Library
10
10
  extend FFI::BitMasks
11
+
11
12
  ffi_lib "girepository-1.0.so.1"
12
13
 
13
14
  # IRepository
@@ -4,8 +4,9 @@ require "ffi"
4
4
 
5
5
  module GObjectIntrospection
6
6
  # Represents a null-terminated array of strings.
7
- # GLib uses this
8
- # construction, but does not provide any actual functions for this class.
7
+ # GLib uses this construction, but does not provide any actual functions for
8
+ # this class.
9
+ # In a sense, this is a specialization of GirFFI::ZeroTerminated.
9
10
  class Strv
10
11
  include Enumerable
11
12
 
@@ -23,12 +24,12 @@ module GObjectIntrospection
23
24
  offset = 0
24
25
  while (ptr = fetch_ptr offset)
25
26
  offset += POINTER_SIZE
26
- yield ptr.read_string
27
+ yield ptr.read_string.force_encoding(Encoding::UTF_8)
27
28
  end
28
29
  end
29
30
 
30
31
  def self.wrap(ptr)
31
- new ptr
32
+ new ptr unless ptr.null?
32
33
  end
33
34
 
34
35
  private
@@ -17,7 +17,9 @@ module GirFFI
17
17
  when :utf8, :filename
18
18
  bare_value.to_utf8
19
19
  when Array
20
- value_type[1].wrap bare_value
20
+ element_type = value_type[1]
21
+ element_type = GLib::Strv if element_type == :strv
22
+ element_type.wrap bare_value
21
23
  when Module
22
24
  value_type.wrap bare_value
23
25
  else
@@ -6,17 +6,19 @@ module GirFFI
6
6
  # Class representing a boolean (natively, an int).
7
7
  class Boolean
8
8
  extend FFI::DataConverter
9
+
9
10
  native_type FFI::Type::INT
10
11
 
11
- FROM_NATIVE = { 0 => false, 1 => true }.freeze
12
- TO_NATIVE = FROM_NATIVE.invert
12
+ NATIVE_TRUE = 1
13
+ NATIVE_FALSE = 0
14
+ FROM_NATIVE = { NATIVE_FALSE => false, NATIVE_TRUE => true }.freeze
13
15
 
14
16
  def self.from_native(value, _context)
15
17
  FROM_NATIVE.fetch(value)
16
18
  end
17
19
 
18
20
  def self.to_native(value, _context)
19
- TO_NATIVE.fetch(value ? true : false)
21
+ value ? NATIVE_TRUE : NATIVE_FALSE
20
22
  end
21
23
 
22
24
  def self.size
@@ -10,6 +10,8 @@ module GirFFI
10
10
  end
11
11
 
12
12
  def self.copy(val)
13
+ return if val.to_ptr.null?
14
+
13
15
  ptr = GObject.boxed_copy(gtype, val)
14
16
  wrap(ptr)
15
17
  end
@@ -114,7 +114,7 @@ module GirFFI
114
114
 
115
115
  def outgoing_convertor(base)
116
116
  FullCToRubyConvertor.new(type_info, base, length_argument_name,
117
- ownership_transfer: arginfo.ownership_transfer)
117
+ ownership_transfer: ownership_transfer)
118
118
  end
119
119
 
120
120
  def sub_type_spec
@@ -203,13 +203,11 @@ module GirFFI
203
203
  arginfo.caller_allocates?
204
204
  end
205
205
 
206
- DESTROY_NOTIFIER = "GLib::DestroyNotify.default"
207
-
208
206
  def ingoing_convertor
209
207
  if skipped_in?
210
208
  NullConvertor.new("0")
211
209
  elsif destroy_notifier?
212
- NullConvertor.new(DESTROY_NOTIFIER)
210
+ NullConvertor.new("GLib::DestroyNotify.default")
213
211
  elsif user_data?
214
212
  ClosureToPointerConvertor.new(callback_argument_name)
215
213
  elsif needs_ruby_to_c_conversion?
@@ -150,9 +150,9 @@ module GirFFI
150
150
 
151
151
  def base_argument_names(arguments)
152
152
  required_found = false
153
- arguments.reverse.filter_map do |it|
154
- name = it.method_argument_name
155
- if it.allow_none? && !required_found
153
+ arguments.reverse.filter_map do |arg|
154
+ name = arg.method_argument_name
155
+ if arg.allow_none? && !required_found
156
156
  "#{name} = nil"
157
157
  else
158
158
  required_found = true
@@ -4,6 +4,9 @@ module GirFFI
4
4
  module Builders
5
5
  # Builder that generates code to convert closure arguments ('user data')
6
6
  # from Ruby to C. Used by argument builders.
7
+ #
8
+ # GirFFI uses this to store a key to the storage of the related callback so
9
+ # it can be cleaned by the default DestroyNotify object.
7
10
  class ClosureToPointerConvertor
8
11
  def initialize(argument_name)
9
12
  @argument_name = argument_name