gir_ffi 0.17.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +93 -52
  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/bytes.rb +2 -2
  7. data/lib/ffi-glib/destroy_notify.rb +8 -0
  8. data/lib/ffi-glib/list_methods.rb +1 -0
  9. data/lib/ffi-glib/ptr_array.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +10 -5
  11. data/lib/ffi-gobject/ruby_closure.rb +2 -2
  12. data/lib/ffi-gobject/value.rb +5 -5
  13. data/lib/ffi-gobject.rb +18 -7
  14. data/lib/ffi-gobject_introspection/gobject_type_init.rb +2 -1
  15. data/lib/ffi-gobject_introspection/lib.rb +1 -0
  16. data/lib/ffi-gobject_introspection/strv.rb +5 -4
  17. data/lib/gir_ffi/array_element_convertor.rb +3 -1
  18. data/lib/gir_ffi/boolean.rb +5 -3
  19. data/lib/gir_ffi/boxed_base.rb +2 -0
  20. data/lib/gir_ffi/builders/argument_builder.rb +4 -6
  21. data/lib/gir_ffi/builders/argument_builder_collection.rb +4 -3
  22. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +3 -0
  23. data/lib/gir_ffi/builders/field_builder.rb +9 -7
  24. data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -1
  25. data/lib/gir_ffi/builders/method_template.rb +2 -2
  26. data/lib/gir_ffi/builders/module_builder.rb +2 -2
  27. data/lib/gir_ffi/builders/object_builder.rb +8 -0
  28. data/lib/gir_ffi/builders/property_builder.rb +5 -1
  29. data/lib/gir_ffi/builders/registered_type_builder.rb +12 -8
  30. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +1 -1
  31. data/lib/gir_ffi/callback_base.rb +0 -1
  32. data/lib/gir_ffi/class_base.rb +4 -4
  33. data/lib/gir_ffi/enum_base.rb +4 -4
  34. data/lib/gir_ffi/enum_like_base.rb +2 -2
  35. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -3
  36. data/lib/gir_ffi/in_pointer.rb +10 -4
  37. data/lib/gir_ffi/info_ext/i_signal_info.rb +3 -3
  38. data/lib/gir_ffi/info_ext/i_type_info.rb +1 -1
  39. data/lib/gir_ffi/interface_base.rb +2 -2
  40. data/lib/gir_ffi/lib_c.rb +1 -0
  41. data/lib/gir_ffi/method_stubber.rb +1 -1
  42. data/lib/gir_ffi/object_base.rb +4 -4
  43. data/lib/gir_ffi/object_store.rb +2 -2
  44. data/lib/gir_ffi/sized_array.rb +2 -1
  45. data/lib/gir_ffi/struct_like_base.rb +2 -2
  46. data/lib/gir_ffi/unintrospectable_signal_info.rb +3 -3
  47. data/lib/gir_ffi/user_defined_property_info.rb +4 -0
  48. data/lib/gir_ffi/version.rb +1 -1
  49. data/lib/gir_ffi/zero_terminated.rb +6 -32
  50. data/lib/gir_ffi-base/gobject/lib.rb +1 -1
  51. metadata +8 -185
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d9166ab1e26f13ddc3aa9c5695fb67d4530491f56c01d1e78ad7648f5ea8583
4
- data.tar.gz: 5a2e96556fcd892f0cd143c51a21df6c18475950a166c90a994b38a33777281e
3
+ metadata.gz: 6c0e4b67ec7da9640bab9e8ad5b6af3a21ca34f7f3bb28bc471418952e361325
4
+ data.tar.gz: 6f86337879c11b41bb57ced5b367dee0785739afc4761203e34140b9fbb8b561
5
5
  SHA512:
6
- metadata.gz: f9252568631fc6355af2ee913e73fd363ccf04714c9702d93c6fc26119180046f4345232c66d47a93dcc872024f6a855a1d268b3eff23b49f18fd136d9ef5ef4
7
- data.tar.gz: e289ed1d545a09f5bb2d67a91101fd6cd7510a1a69e721f07f85fd82a352f4922316a3cf92b67a57216e8e203ec5f3232d60e7634e4c9509e6a65819f42a0dcb
6
+ metadata.gz: 931112391d502613f9c1ec82db244ab0dcf26c56a8a45aca3b9b272f6840a07757c1f6b47bbeebb3f2c57902ac2b30edca379ac991f2744cee2587fd69e07a2f
7
+ data.tar.gz: 34624b92c7c209aa9a8dd8e6a95e6a378831f39ac0b7af8ac728e9a9cfbf1cd3dc032021d5ae75da797691436123ef382648de5d5df859417c8b55c055d41d83
data/Changelog.md CHANGED
@@ -1,5 +1,46 @@
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
+
31
+ ## 0.18.0 / 2025-02-07
32
+
33
+ * Update contribution guidelines ([#360] by [mvz])
34
+ * Support Ruby 3.1 through 3.4, dropping support for Ruby 3.0 ([#366] by [mvz])
35
+ * Load gobject-2.0 library in a way that does not require the dev package
36
+ ([#367] by [mvz])
37
+ * Update tests for compatibility with GObjectIntrospection 1.81.2 ([#378] by [mvz])
38
+
39
+ [#360]: https://github.com/mvz/gir_ffi/pull/360
40
+ [#366]: https://github.com/mvz/gir_ffi/pull/366
41
+ [#367]: https://github.com/mvz/gir_ffi/pull/367
42
+ [#378]: https://github.com/mvz/gir_ffi/pull/378
43
+
3
44
  ## 0.17.0 / 2023-12-31
4
45
 
5
46
  * Support Ruby 3.0 and up, dropping support for Ruby 2.7 ([#356] by [mvz])
@@ -188,16 +229,16 @@
188
229
  ## 0.10.1 / 2016-03-28
189
230
 
190
231
  * Restore JRuby compatibility.
191
- - Introduce #owned to flag unions and structs for release at garbage collection time.
192
- In JRuby's implementation, FFI::Pointer does not implement #autorelease=
193
- and #autorelease?, so this different technique is used to free pointers
194
- allocated by GLib. It is in fact doubtful that setting autorelease had any
195
- actual effect even on CRuby.
196
- - Immediately free string pointers whose ownership is transfered. Again, the
197
- #autorelease technique doesn't work on JRuby.
198
- - Fix handling of callee-allocated out parameters in vfuncs. The `put_pointer`
199
- method was wrongly called, and JRuby is more picky about what types that
200
- 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.
201
242
 
202
243
  ## 0.10.0 / 2016-03-23
203
244
 
@@ -270,16 +311,16 @@
270
311
  ## 0.8.6 / 2015-12-09
271
312
 
272
313
  * Change handling of initializers in subclasses
273
- * Subclasses with their own GType revert to the default GObject constructor
274
- * 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
275
316
  * Find signals in ancestor classes of unintrospectable types
276
317
 
277
318
  ## 0.8.5 / 2015-12-04
278
319
 
279
320
  * Improve GObject::Value
280
- * Make `#wrap_ruby_value` work for object classes
281
- * Use non-deprecated methods for getting and setting char values
282
- * 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
283
324
 
284
325
  ## 0.8.4 / 2015-12-03
285
326
 
@@ -299,14 +340,14 @@
299
340
 
300
341
  * Use inherited constructor for boxed types
301
342
  * Make `InOutPointer` work correctly for boxed types
302
- * Make `.for` work with boxed types
303
- * Make `#set_value` work with boxed types
343
+ * Make `.for` work with boxed types
344
+ * Make `#set_value` work with boxed types
304
345
  * Make GObject::Value support nil type:
305
- * Make `.wrap_ruby_value(nil)` work
306
- * Make `#set_value` and `#get_value` work when the type is `TYPE_INVALID`
307
- * Make `.for_gtype` work with `TYPE_INVALID` and `TYPE_NONE`
308
- * Make `.from(nil)` return a `GObject::Value` instead of nil
309
- * 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
310
351
  * Make `GObject::Object.signal_emit` work with gobject-introspection 1.46
311
352
  * Replace or remove all custom `.new` methods
312
353
  * Make `setup_method` and `setup_instance_method` handle symbol arguments
@@ -373,8 +414,8 @@
373
414
  * Provide constant `TYPE_BYTE_ARRAY`
374
415
  * Don't recurse looking for signals and properties
375
416
  * Clean up generated code:
376
- * Avoid use of an ignored dummy argument
377
- * Clean up trailing whitespace
417
+ * Avoid use of an ignored dummy argument
418
+ * Clean up trailing whitespace
378
419
  * Drop support for Ruby 1.9.2
379
420
  * Allow data argument for `GObject::Object#signal_connect`
380
421
  * Let Ruby threads run during GLib's main loop
@@ -419,25 +460,25 @@
419
460
  ## 0.7.0 / 2014-01-11
420
461
 
421
462
  * Type handling:
422
- * Handle c arrays with separate length argument for signals
423
- * Handle GHashTable values of type `:gint8` and `:guint32`
424
- * Handle signals with int64, Strv, uint64 arguments
425
- * Handle arrays of integers cast as pointers
426
- * Handle fields of callback type
427
- * 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
428
469
  * Argument handling:
429
- * Refactor argument builder system
430
- * Improve handling of user data arguments
431
- * Handle signal and callback arguments with direction :out
432
- * Handle aliases of container types by making the element type optional
433
- * 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
434
475
  * User defined types:
435
- * Pass explicit receiver to initialization block for UserDefinedTypeInfo
436
- * Allow user defined types that are anonymous Ruby classes
437
- * Register defined properties in a subclass
438
- * Support setting virtual function implementations in a subclass
439
- * Support adding an interface to a subclass
440
- * 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
441
482
  * Use FFI's DataConvertor system to handle enums and callbacks
442
483
  * Stop using deprecated GValueArray to construct argument array for `signal_emit`
443
484
  * Make `ITypeInfo#g_type` return correct value for c arrays
@@ -588,13 +629,13 @@
588
629
 
589
630
  * Add support for properties, with `#get_property` and `#set_property`.
590
631
  * Add support for fields.
591
- - Create field accessor methods.
592
- - Get rid of `#[]` and `#[]=`.
632
+ * Create field accessor methods.
633
+ * Get rid of `#[]` and `#[]=`.
593
634
  * Explicitely load `libgirepository` with ABI version 1.
594
635
  * Improve implementation of GLib container classes (GList etc.):
595
- - Real constructors.
596
- - `#append` and friends are instance methods now.
597
- - 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.
598
639
  * Start implementing pretty printing.
599
640
  * Various refactorings.
600
641
 
@@ -607,10 +648,10 @@
607
648
  ## 0.0.14 / 2011-10-28
608
649
 
609
650
  * Support GObject Introspection version 1.30:
610
- - Add support for layouts with fixed-length arrays.
611
- - Handle type names starting with underscores.
612
- - Call `g_signal_emitv` directly to avoid conflict in introspection info
613
- 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.
614
655
 
615
656
  ## 0.0.13 / 2011-09-09
616
657
 
@@ -662,8 +703,8 @@
662
703
  ## 0.0.7 / 2011-04-01
663
704
 
664
705
  * Support gobject-introspection 0.10, drop support for earlier versions.
665
- - Use Regress, not Everything, for testing.
666
- - Deal with functions that are no longer introspectable.
706
+ * Use Regress, not Everything, for testing.
707
+ * Deal with functions that are no longer introspectable.
667
708
  * Correctly handle constructors that declare their return type different
668
709
  from their class.
669
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,8 +7,8 @@ module GLib
7
7
  class Bytes
8
8
  include Enumerable
9
9
 
10
- def each(&block)
11
- data.each(&block)
10
+ def each(&)
11
+ data.each(&)
12
12
  end
13
13
 
14
14
  def self.from(obj)
@@ -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)
@@ -71,12 +71,12 @@ module GObject
71
71
  end
72
72
  end
73
73
 
74
- def signal_connect(event, data = nil, &block)
75
- GObject.signal_connect(self, event, data, &block)
74
+ def signal_connect(event, data = nil, &)
75
+ GObject.signal_connect(self, event, data, &)
76
76
  end
77
77
 
78
- def signal_connect_after(event, data = nil, &block)
79
- GObject.signal_connect_after(self, event, data, &block)
78
+ def signal_connect_after(event, data = nil, &)
79
+ GObject.signal_connect_after(self, event, data, &)
80
80
  end
81
81
 
82
82
  setup_instance_method! "get_property"
@@ -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
@@ -60,8 +61,18 @@ module GObject
60
61
  signal_connect_closure object, detailed_signal, closure, after
61
62
  end
62
63
 
63
- def self.signal_connect_after(object, detailed_signal, data = nil, &block)
64
- signal_connect object, detailed_signal, data, true, &block
64
+ def self.signal_connect_after(object, detailed_signal, data = nil, &)
65
+ signal_connect(object, detailed_signal, data, true, &)
66
+ end
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
65
76
  end
66
77
 
67
78
  load_class :Callback
@@ -12,7 +12,8 @@ module GObjectIntrospection
12
12
  # Module for attaching g_type_init from the gobject library.
13
13
  module Lib
14
14
  extend FFI::Library
15
- ffi_lib "gobject-2.0"
15
+
16
+ ffi_lib "gobject-2.0.so.0"
16
17
  attach_function :g_type_init, [], :void
17
18
  end
18
19
  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