glib2 3.5.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/ext/glib2/extconf.rb +4 -3
  3. data/ext/glib2/glib2.def +4 -0
  4. data/ext/glib2/rbglib-bytes.c +1 -1
  5. data/ext/glib2/rbglib-gc.c +1 -1
  6. data/ext/glib2/rbglib-variant-type.c +1 -1
  7. data/ext/glib2/rbglib-variant.c +75 -2
  8. data/ext/glib2/rbglib.c +25 -59
  9. data/ext/glib2/rbglib.h +16 -3
  10. data/ext/glib2/rbglib_bookmarkfile.c +3 -2
  11. data/ext/glib2/rbglib_convert.c +2 -2
  12. data/ext/glib2/rbglib_datetime.c +14 -3
  13. data/ext/glib2/rbglib_error.c +2 -2
  14. data/ext/glib2/rbglib_fileutils.c +2 -2
  15. data/ext/glib2/rbglib_gettext.c +1 -1
  16. data/ext/glib2/rbglib_i18n.c +2 -2
  17. data/ext/glib2/rbglib_io_constants.c +1 -1
  18. data/ext/glib2/rbglib_iochannel.c +2 -2
  19. data/ext/glib2/rbglib_iochannel_win32_socket.c +2 -2
  20. data/ext/glib2/rbglib_iochannelerror.c +1 -1
  21. data/ext/glib2/rbglib_keyfile.c +2 -2
  22. data/ext/glib2/rbglib_maincontext.c +6 -6
  23. data/ext/glib2/rbglib_mainloop.c +1 -1
  24. data/ext/glib2/rbglib_matchinfo.c +1 -1
  25. data/ext/glib2/rbglib_messages.c +1 -1
  26. data/ext/glib2/rbglib_pollfd.c +1 -1
  27. data/ext/glib2/rbglib_regex.c +3 -3
  28. data/ext/glib2/rbglib_shell.c +1 -1
  29. data/ext/glib2/rbglib_shellerror.c +1 -1
  30. data/ext/glib2/rbglib_source.c +1 -1
  31. data/ext/glib2/rbglib_spawn.c +1 -1
  32. data/ext/glib2/rbglib_spawnerror.c +1 -1
  33. data/ext/glib2/rbglib_threads.c +1 -1
  34. data/ext/glib2/rbglib_timer.c +1 -1
  35. data/ext/glib2/rbglib_timezone.c +1 -1
  36. data/ext/glib2/rbglib_ucs4.c +1 -1
  37. data/ext/glib2/rbglib_unichar.c +1 -1
  38. data/ext/glib2/rbglib_unicode.c +3 -3
  39. data/ext/glib2/rbglib_utf16.c +1 -1
  40. data/ext/glib2/rbglib_utf8.c +1 -1
  41. data/ext/glib2/rbglib_utils.c +1 -1
  42. data/ext/glib2/rbglib_win32.c +3 -3
  43. data/ext/glib2/rbgobj_binding.c +1 -1
  44. data/ext/glib2/rbgobj_boxed.c +1 -1
  45. data/ext/glib2/rbgobj_closure.c +54 -84
  46. data/ext/glib2/rbgobj_enums.c +1 -1
  47. data/ext/glib2/rbgobj_flags.c +1 -1
  48. data/ext/glib2/rbgobj_object.c +32 -5
  49. data/ext/glib2/rbgobj_param.c +1 -1
  50. data/ext/glib2/rbgobj_signal.c +36 -18
  51. data/ext/glib2/rbgobj_type.c +2 -2
  52. data/ext/glib2/rbgobj_typeinstance.c +1 -1
  53. data/ext/glib2/rbgobj_typeinterface.c +4 -4
  54. data/ext/glib2/rbgobj_typemodule.c +1 -1
  55. data/ext/glib2/rbgobj_typeplugin.c +1 -1
  56. data/ext/glib2/rbgobj_value.c +1 -1
  57. data/ext/glib2/rbgobj_valuetypes.c +14 -4
  58. data/ext/glib2/rbgobject.c +7 -21
  59. data/ext/glib2/rbgobject.h +1 -0
  60. data/ext/glib2/rbgprivate.h +7 -4
  61. data/ext/glib2/rbgutil.c +20 -1
  62. data/ext/glib2/rbgutil.h +3 -0
  63. data/ext/glib2/rbgutil_callback.c +7 -7
  64. data/lib/glib2/date-time.rb +35 -0
  65. data/lib/glib2/variant.rb +25 -0
  66. data/lib/glib2.rb +6 -1
  67. data/lib/mkmf-gnome.rb +2 -2
  68. data/test/test-date-time.rb +14 -2
  69. data/test/test-glib2.rb +21 -9
  70. data/test/test-variant.rb +44 -1
  71. metadata +7 -7
  72. data/ext/glib2/glib-enum-types.c +0 -1233
  73. data/ext/glib2/glib-enum-types.h +0 -154
@@ -217,7 +217,7 @@ rg_s_close_pid(G_GNUC_UNUSED VALUE self, VALUE pid)
217
217
  void
218
218
  Init_glib_spawn(void)
219
219
  {
220
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "Spawn");
220
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "Spawn");
221
221
 
222
222
  id_call = rb_intern("call");
223
223
  id_new = rb_intern("new");
@@ -28,7 +28,7 @@
28
28
  void
29
29
  Init_glib_spawnerror(void)
30
30
  {
31
- VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_SPAWN_ERROR, "SpawnError", mGLib, rb_eIOError);
31
+ VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_SPAWN_ERROR, "SpawnError", rbg_mGLib(), rb_eIOError);
32
32
 
33
33
  rb_define_const(RG_TARGET_NAMESPACE, "FORK", INT2NUM(G_SPAWN_ERROR_FORK));
34
34
  rb_define_const(RG_TARGET_NAMESPACE, "READ", INT2NUM(G_SPAWN_ERROR_READ));
@@ -41,7 +41,7 @@ rg_s_supported_p(G_GNUC_UNUSED VALUE self)
41
41
  void
42
42
  Init_glib_threads(void)
43
43
  {
44
- RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Thread", rb_cObject);
44
+ RG_TARGET_NAMESPACE = rb_define_class_under(rbg_mGLib(), "Thread", rb_cObject);
45
45
 
46
46
  RG_DEF_SMETHOD(init, 0);
47
47
  RG_DEF_SMETHOD_P(supported, 0);
@@ -116,7 +116,7 @@ rg_reset(VALUE self)
116
116
  void
117
117
  Init_glib_timer(void)
118
118
  {
119
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_TIMER, "Timer", mGLib);
119
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_TIMER, "Timer", rbg_mGLib());
120
120
 
121
121
  RG_DEF_METHOD(initialize, 0);
122
122
  RG_DEF_METHOD(start, 0);
@@ -73,7 +73,7 @@ void
73
73
  Init_glib_time_zone(void)
74
74
  {
75
75
  VALUE RG_TARGET_NAMESPACE;
76
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_TIME_ZONE, "TimeZone", mGLib);
76
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_TIME_ZONE, "TimeZone", rbg_mGLib());
77
77
  RG_DEF_METHOD(initialize, -1);
78
78
  RG_DEF_SMETHOD(local, 0);
79
79
  RG_DEF_SMETHOD(utc, 0);
@@ -72,7 +72,7 @@ rg_s_to_utf8(G_GNUC_UNUSED VALUE self, VALUE rb_ucs4)
72
72
  void
73
73
  Init_glib_ucs4(void)
74
74
  {
75
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "UCS4");
75
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "UCS4");
76
76
 
77
77
  RG_DEF_SMETHOD(to_utf16, 1);
78
78
  RG_DEF_SMETHOD(to_utf8, 1);
@@ -185,7 +185,7 @@ rg_s_decompose(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
185
185
  void
186
186
  Init_glib_unichar(void)
187
187
  {
188
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "UniChar");
188
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "UniChar");
189
189
 
190
190
  rbg_define_singleton_method(RG_TARGET_NAMESPACE, "alnum?",
191
191
  rbglib_m_unichar_isalnum, 1);
@@ -52,7 +52,7 @@ rg_s_canonical_ordering(G_GNUC_UNUSED VALUE self, VALUE rb_ucs4)
52
52
  void
53
53
  Init_glib_unicode(void)
54
54
  {
55
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "Unicode");
55
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "Unicode");
56
56
 
57
57
  /* GUnicodeType */
58
58
  G_DEF_CLASS(G_TYPE_UNICODE_TYPE, "Type", RG_TARGET_NAMESPACE);
@@ -65,9 +65,9 @@ Init_glib_unicode(void)
65
65
  G_DEF_CLASS(G_TYPE_UNICODE_SCRIPT, "Script", RG_TARGET_NAMESPACE);
66
66
  G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, G_TYPE_UNICODE_SCRIPT, "G_UNICODE_");
67
67
 
68
- G_DEF_CLASS(G_TYPE_NORMALIZE_MODE, "NormalizeMode", mGLib);
68
+ G_DEF_CLASS(G_TYPE_NORMALIZE_MODE, "NormalizeMode", rbg_mGLib());
69
69
 
70
- rbg_define_singleton_method(mGLib, "charset", rbglib_m_charset, 0);
70
+ rbg_define_singleton_method(rbg_mGLib(), "charset", rbglib_m_charset, 0);
71
71
 
72
72
  RG_DEF_SMETHOD(canonical_ordering, 1);
73
73
  }
@@ -71,7 +71,7 @@ rg_s_to_utf8(G_GNUC_UNUSED VALUE self, VALUE rb_utf16)
71
71
  void
72
72
  Init_glib_utf16(void)
73
73
  {
74
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "UTF16");
74
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "UTF16");
75
75
 
76
76
  RG_DEF_SMETHOD(to_ucs4, 1);
77
77
  RG_DEF_SMETHOD(to_utf8, 1);
@@ -218,7 +218,7 @@ rg_s_to_ucs4(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
218
218
  void
219
219
  Init_glib_utf8(void)
220
220
  {
221
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "UTF8");
221
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "UTF8");
222
222
 
223
223
  /*
224
224
  Not implemented.
@@ -21,7 +21,7 @@
21
21
 
22
22
  #include "rbgprivate.h"
23
23
 
24
- #define RG_TARGET_NAMESPACE mGLib
24
+ #define RG_TARGET_NAMESPACE rbg_mGLib()
25
25
 
26
26
  static VALUE
27
27
  rg_s_application_name(G_GNUC_UNUSED VALUE self)
@@ -90,17 +90,17 @@ Init_glib_win32(void)
90
90
  {
91
91
  #ifdef G_OS_WIN32
92
92
  /* glib/gwin32.h */
93
- VALUE RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "Win32");
93
+ VALUE RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "Win32");
94
94
 
95
95
  RG_DEF_SMETHOD(error_message, 1);
96
96
  RG_DEF_SMETHOD(locale, 0);
97
97
  RG_DEF_SMETHOD(version, 0);
98
98
  /* Deprecated */
99
- rbg_define_singleton_method(mGLib, "win32_locale", rbglib_m_win32_locale_deprecated, 0);
99
+ rbg_define_singleton_method(rbg_mGLib(), "win32_locale", rbglib_m_win32_locale_deprecated, 0);
100
100
 
101
101
  RG_DEF_SMETHOD(locale_filename_from_utf8, 1);
102
102
  /* Deprecated */
103
- rbg_define_singleton_method(mGLib, "win32_locale_filename_from_utf8",
103
+ rbg_define_singleton_method(rbg_mGLib(), "win32_locale_filename_from_utf8",
104
104
  rbglib_m_win32_locale_filename_from_utf8_deprecated, 1);
105
105
 
106
106
  RG_DEF_SMETHOD(get_package_installation_directory_of_module, -1);
@@ -44,7 +44,7 @@ Init_gobject_gbinding(void)
44
44
  {
45
45
  VALUE RG_TARGET_NAMESPACE;
46
46
 
47
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BINDING, "Binding", mGLib);
47
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BINDING, "Binding", rbg_mGLib());
48
48
 
49
49
  RG_DEF_METHOD(unbind, 0);
50
50
  }
@@ -302,7 +302,7 @@ boxed_from_ruby(VALUE from, GValue *to)
302
302
  void
303
303
  Init_gobject_gboxed(void)
304
304
  {
305
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BOXED, "Boxed", mGLib);
305
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BOXED, "Boxed", rbg_mGLib());
306
306
 
307
307
  rbgobj_register_g2r_func(G_TYPE_BOXED, boxed_to_ruby);
308
308
  rbgobj_register_r2g_func(G_TYPE_BOXED, boxed_from_ruby);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2021 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2022 Ruby-GNOME Project Team
4
4
  * Copyright (C) 2002,2003 Masahiro Sakai
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -34,7 +34,6 @@ struct _GRClosure
34
34
  VALUE callback;
35
35
  VALUE extra_args;
36
36
  VALUE rb_holder;
37
- gint count;
38
37
  GList *objects;
39
38
  GValToRValSignalFunc g2r_func;
40
39
  RGClosureCallFunc call_func;
@@ -64,7 +63,7 @@ struct marshal_arg
64
63
  static int
65
64
  rclosure_alive_p(GRClosure *rclosure)
66
65
  {
67
- return (rclosure->count > 0 && !NIL_P(rclosure->rb_holder));
66
+ return !NIL_P(rclosure->rb_holder);
68
67
  }
69
68
 
70
69
  static VALUE
@@ -121,8 +120,8 @@ rclosure_marshal_do(VALUE arg_)
121
120
 
122
121
  ret = rb_apply(callback, id_call, args);
123
122
  } else {
124
- rb_warn("GRClosure invoking callback: already destroyed: %s",
125
- rclosure->tag[0] ? rclosure->tag : "(anonymous)");
123
+ g_warning("GRClosure invoking callback: already destroyed: %s",
124
+ rclosure->tag[0] ? rclosure->tag : "(anonymous)");
126
125
  }
127
126
 
128
127
  if (return_value && G_VALUE_TYPE(return_value))
@@ -159,43 +158,25 @@ rclosure_marshal(GClosure* closure,
159
158
  static void rclosure_weak_notify(gpointer data, GObject* where_the_object_was);
160
159
 
161
160
  static void
162
- rclosure_unref(GRClosure *rclosure)
161
+ rclosure_finalize(G_GNUC_UNUSED gpointer data, GClosure *closure)
163
162
  {
164
- rclosure->count--;
163
+ GRClosure *rclosure = (GRClosure *)closure;
165
164
 
166
- if (!rclosure_alive_p(rclosure)) {
167
- GList *next;
168
- for (next = rclosure->objects; next; next = next->next) {
169
- GObject *object = G_OBJECT(next->data);
170
- g_object_weak_unref(object, rclosure_weak_notify, rclosure);
171
- }
172
- g_list_free(rclosure->objects);
173
- rclosure->objects = NULL;
174
- if (!NIL_P(rclosure->rb_holder)) {
175
- RTYPEDDATA_DATA(rclosure->rb_holder) = NULL;
176
- rclosure->rb_holder = Qnil;
165
+ GList *next;
166
+ for (next = rclosure->objects; next; next = next->next) {
167
+ GObject *object = G_OBJECT(next->data);
168
+ g_object_weak_unref(object, rclosure_weak_notify, rclosure);
169
+ VALUE obj = rbgobj_ruby_object_from_instance2(object, FALSE);
170
+ if (!NIL_P(rclosure->rb_holder) && !NIL_P(obj)) {
171
+ rbgobj_object_remove_relative(obj, rclosure->rb_holder);
177
172
  }
178
173
  }
179
- }
180
-
181
- static void
182
- rclosure_invalidate(G_GNUC_UNUSED gpointer data, GClosure *closure)
183
- {
184
- GRClosure *rclosure = (GRClosure*)closure;
185
-
186
- if (rclosure->count > 0) {
187
- GList *next;
188
-
189
- rclosure->count = 1;
190
- for (next = rclosure->objects; next; next = next->next) {
191
- GObject *object = G_OBJECT(next->data);
192
- VALUE obj = rbgobj_ruby_object_from_instance2(object, FALSE);
193
- if (!NIL_P(rclosure->rb_holder) && !NIL_P(obj)) {
194
- rbgobj_object_remove_relative(obj, rclosure->rb_holder);
195
- }
196
- }
174
+ g_list_free(rclosure->objects);
175
+ rclosure->objects = NULL;
197
176
 
198
- rclosure_unref(rclosure);
177
+ if (!NIL_P(rclosure->rb_holder)) {
178
+ RTYPEDDATA_DATA(rclosure->rb_holder) = NULL;
179
+ rclosure->rb_holder = Qnil;
199
180
  }
200
181
  }
201
182
 
@@ -219,13 +200,7 @@ gr_closure_holder_free(void *data)
219
200
  if (!rclosure)
220
201
  return;
221
202
 
222
- if (rclosure->count > 0) {
223
- rclosure->count = 1;
224
-
225
- /* No need to remove us from the relatives hash of our objects, as
226
- * those aren't alive anymore anyway */
227
- rclosure_unref(rclosure);
228
- }
203
+ g_closure_unref((GClosure *)rclosure);
229
204
  }
230
205
 
231
206
  static const rb_data_type_t rbg_closure_holder_type = {
@@ -245,26 +220,24 @@ g_rclosure_new_raw(VALUE callback_proc,
245
220
  GValToRValSignalFunc g2r_func,
246
221
  RGClosureCallFunc call_func)
247
222
  {
248
- GRClosure* closure;
249
-
250
- closure = (GRClosure*)g_closure_new_simple(sizeof(GRClosure), NULL);
251
-
252
- closure->count = 1;
253
- closure->g2r_func = g2r_func;
254
- closure->call_func = call_func;
255
- closure->objects = NULL;
256
- closure->callback = callback_proc;
257
- closure->extra_args = extra_args;
258
- closure->rb_holder = TypedData_Wrap_Struct(rb_cObject,
259
- &rbg_closure_holder_type,
260
- closure);
261
- closure->tag[0] = '\0';
262
-
263
- g_closure_set_marshal((GClosure*)closure, &rclosure_marshal);
264
- g_closure_add_invalidate_notifier((GClosure*)closure, NULL,
265
- &rclosure_invalidate);
266
-
267
- return (GClosure*)closure;
223
+ GClosure *closure = g_closure_new_simple(sizeof(GRClosure), NULL);
224
+
225
+ GRClosure *rclosure = (GRClosure *)closure;
226
+
227
+ rclosure->g2r_func = g2r_func;
228
+ rclosure->call_func = call_func;
229
+ rclosure->objects = NULL;
230
+ rclosure->callback = callback_proc;
231
+ rclosure->extra_args = extra_args;
232
+ rclosure->rb_holder = TypedData_Wrap_Struct(rb_cObject,
233
+ &rbg_closure_holder_type,
234
+ rclosure);
235
+ rclosure->tag[0] = '\0';
236
+
237
+ g_closure_set_marshal(closure, &rclosure_marshal);
238
+ g_closure_add_finalize_notifier(closure, NULL, rclosure_finalize);
239
+
240
+ return closure;
268
241
  }
269
242
 
270
243
  GClosure *
@@ -287,34 +260,30 @@ g_rclosure_new_call(VALUE callback_proc,
287
260
  }
288
261
 
289
262
  static void
290
- rclosure_weak_notify(gpointer data, GObject* where_the_object_was)
263
+ rclosure_weak_notify(gpointer data, GObject *where_the_object_was)
291
264
  {
292
265
  GRClosure *rclosure = data;
293
- if (rclosure_alive_p(rclosure)) {
294
- rclosure->objects =
295
- g_list_remove(rclosure->objects, where_the_object_was);
296
- rclosure_unref(rclosure);
297
- }
266
+ rclosure->objects = g_list_remove(rclosure->objects, where_the_object_was);
267
+ g_closure_unref((GClosure *)rclosure);
298
268
  }
299
269
 
300
270
  void
301
271
  g_rclosure_attach(GClosure *closure, VALUE object)
302
272
  {
303
- static VALUE cGLibObject = Qnil;
304
273
  GRClosure *rclosure = (GRClosure *)closure;
305
-
306
274
  rbgobj_add_relative(object, rclosure->rb_holder);
275
+ }
307
276
 
308
- if (NIL_P(cGLibObject)) {
309
- cGLibObject = rb_const_get(mGLib, rb_intern("Object"));
310
- }
311
- if (rb_obj_is_kind_of(object, cGLibObject)) {
312
- GObject *gobject;
313
- gobject = RVAL2GOBJ(object);
314
- rclosure->count++;
315
- g_object_weak_ref(gobject, rclosure_weak_notify, rclosure);
316
- rclosure->objects = g_list_prepend(rclosure->objects, gobject);
317
- }
277
+ void
278
+ g_rclosure_attach_gobject(GClosure *closure, VALUE object)
279
+ {
280
+ GRClosure *rclosure = (GRClosure *)closure;
281
+ g_rclosure_attach(closure, object);
282
+
283
+ GObject *gobject = RVAL2GOBJ(object);
284
+ g_closure_ref(closure);
285
+ g_object_weak_ref(gobject, rclosure_weak_notify, rclosure);
286
+ rclosure->objects = g_list_prepend(rclosure->objects, gobject);
318
287
  }
319
288
 
320
289
  void
@@ -350,8 +319,9 @@ init_rclosure(void)
350
319
  static VALUE
351
320
  rg_initialize(VALUE self)
352
321
  {
353
- GClosure* closure = g_rclosure_new(rb_block_proc(), Qnil, NULL);
322
+ GClosure *closure = g_rclosure_new(rb_block_proc(), Qnil, NULL);
354
323
  G_INITIALIZE(self, closure);
324
+ g_closure_ref(closure);
355
325
  g_closure_sink(closure);
356
326
  return self;
357
327
  }
@@ -387,7 +357,7 @@ Init_gobject_gclosure(void)
387
357
 
388
358
  init_rclosure();
389
359
 
390
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_CLOSURE, "Closure", mGLib);
360
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_CLOSURE, "Closure", rbg_mGLib());
391
361
 
392
362
  RG_DEF_METHOD(initialize, 0);
393
363
  RG_DEF_METHOD_P(in_marshal, 0);
@@ -413,7 +413,7 @@ Init_gobject_genums(void)
413
413
  id_to_s = rb_intern("to_s");
414
414
  id_values = rb_intern("values");
415
415
 
416
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_ENUM, "Enum", mGLib);
416
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_ENUM, "Enum", rbg_mGLib());
417
417
 
418
418
  rbg_define_singleton_method(RG_TARGET_NAMESPACE, "gtype", generic_s_gtype, 0);
419
419
  rbg_define_method(RG_TARGET_NAMESPACE, "gtype", generic_gtype, 0);
@@ -542,7 +542,7 @@ Init_gobject_gflags(void)
542
542
  id_or = rb_intern("|");
543
543
  id_to_i = rb_intern("to_i");
544
544
 
545
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_FLAGS, "Flags", mGLib);
545
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_FLAGS, "Flags", rbg_mGLib());
546
546
 
547
547
  rbg_define_singleton_method(RG_TARGET_NAMESPACE, "gtype", generic_s_gtype, 0);
548
548
  rbg_define_method(RG_TARGET_NAMESPACE, "gtype", generic_gtype, 0);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2021 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2022 Ruby-GNOME Project Team
4
4
  * Copyright (C) 2002-2003 Masahiro Sakai
5
5
  * Copyright (C) 1998-2000 Yukihiro Matsumoto,
6
6
  * Daisuke Kanda,
@@ -30,6 +30,12 @@ VALUE RG_TARGET_NAMESPACE;
30
30
  static VALUE eNoPropertyError;
31
31
  static GQuark RUBY_GOBJECT_OBJ_KEY;
32
32
 
33
+ VALUE
34
+ rbg_cGLibObject(void)
35
+ {
36
+ return RG_TARGET_NAMESPACE;
37
+ }
38
+
33
39
  gboolean
34
40
  rbg_is_object(VALUE object)
35
41
  {
@@ -311,6 +317,12 @@ rg_s_new_bang(int argc, VALUE *argv, VALUE self)
311
317
  return result;
312
318
  }
313
319
 
320
+ static VALUE
321
+ rg_s_init(int argc, VALUE *argv, VALUE self)
322
+ {
323
+ return RUBY_Qnil;
324
+ }
325
+
314
326
  struct param_setup_arg {
315
327
  GObjectClass* gclass;
316
328
  GParameter* params;
@@ -872,6 +884,15 @@ rg_initialize(int argc, VALUE *argv, VALUE self)
872
884
  gobj = rbgobj_gobject_new(RVAL2GTYPE(self), params_hash);
873
885
 
874
886
  G_INITIALIZE(self, gobj);
887
+
888
+ rb_funcall(self, rb_intern("initialize_post"), 0);
889
+
890
+ return Qnil;
891
+ }
892
+
893
+ static VALUE
894
+ rg_initialize_post(VALUE self)
895
+ {
875
896
  return Qnil;
876
897
  }
877
898
 
@@ -956,6 +977,9 @@ rbgobj_class_init_func(gpointer g_class, G_GNUC_UNUSED gpointer class_data)
956
977
 
957
978
  g_object_class->set_property = set_prop_func;
958
979
  g_object_class->get_property = get_prop_func;
980
+
981
+ VALUE rb_class = GTYPE2CLASS(G_TYPE_FROM_CLASS(g_class));
982
+ rb_funcall(rb_class, rb_intern("init"), 0);
959
983
  }
960
984
 
961
985
  void
@@ -1062,11 +1086,11 @@ rg_s_type_register(int argc, VALUE *argv, VALUE self)
1062
1086
  void
1063
1087
  Init_gobject_gobject(void)
1064
1088
  {
1065
- RG_TARGET_NAMESPACE = G_DEF_CLASS_WITH_GC_FUNC(G_TYPE_OBJECT, "Object", mGLib,
1089
+ RG_TARGET_NAMESPACE = G_DEF_CLASS_WITH_GC_FUNC(G_TYPE_OBJECT, "Object", rbg_mGLib(),
1066
1090
  gobj_mark, NULL);
1067
1091
 
1068
1092
  #ifdef G_TYPE_INITIALLY_UNOWNED
1069
- G_DEF_CLASS(G_TYPE_INITIALLY_UNOWNED, "InitiallyUnowned", mGLib);
1093
+ G_DEF_CLASS(G_TYPE_INITIALLY_UNOWNED, "InitiallyUnowned", rbg_mGLib());
1070
1094
  #endif
1071
1095
 
1072
1096
  RUBY_GOBJECT_OBJ_KEY = g_quark_from_static_string("__ruby_gobject_object__");
@@ -1074,6 +1098,8 @@ Init_gobject_gobject(void)
1074
1098
  rb_define_alloc_func(RG_TARGET_NAMESPACE, rbgobj_object_alloc_func);
1075
1099
  RG_DEF_SMETHOD_BANG(new, -1);
1076
1100
 
1101
+ RG_DEF_SMETHOD(init, 0);
1102
+
1077
1103
  rbg_define_singleton_method(RG_TARGET_NAMESPACE, "property", &gobj_s_property, 1);
1078
1104
  rbg_define_singleton_method(RG_TARGET_NAMESPACE, "properties", &gobj_s_properties, -1);
1079
1105
  RG_DEF_SMETHOD(install_property, -1);
@@ -1089,6 +1115,7 @@ Init_gobject_gobject(void)
1089
1115
  RG_DEF_METHOD_P(destroyed, 0);
1090
1116
 
1091
1117
  RG_DEF_METHOD(initialize, -1);
1118
+ RG_DEF_PRIVATE_METHOD(initialize_post, 0);
1092
1119
  rbg_define_method(RG_TARGET_NAMESPACE, "ref_count", gobj_ref_count, 0); /* for debugging */
1093
1120
  RG_DEF_METHOD_P(floating, 0); /* for debugging */
1094
1121
  RG_DEF_METHOD(unref, 0);
@@ -1096,9 +1123,9 @@ Init_gobject_gobject(void)
1096
1123
  RG_DEF_METHOD(type_name, 0);
1097
1124
 
1098
1125
  RG_DEF_METHOD(bind_property, -1);
1099
- G_DEF_CLASS(G_TYPE_BINDING_FLAGS, "BindingFlags", mGLib);
1126
+ G_DEF_CLASS(G_TYPE_BINDING_FLAGS, "BindingFlags", rbg_mGLib());
1100
1127
 
1101
- eNoPropertyError = rb_define_class_under(mGLib, "NoPropertyError",
1128
+ eNoPropertyError = rb_define_class_under(rbg_mGLib(), "NoPropertyError",
1102
1129
  rb_eNameError);
1103
1130
 
1104
1131
  rbg_type_to_prop_setter_tables =
@@ -353,7 +353,7 @@ void
353
353
  Init_gobject_gparam(void)
354
354
  {
355
355
  qparamspec = g_quark_from_static_string("__ruby_gobject_param_spec__");
356
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_PARAM, "Param", mGLib);
356
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_PARAM, "Param", rbg_mGLib());
357
357
 
358
358
  /* GParamFlags */
359
359
  rb_define_const(RG_TARGET_NAMESPACE, "READABLE",
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2021 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2022 Ruby-GNOME Project Team
4
4
  * Copyright (C) 2002,2003 Masahiro Sakai
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -39,20 +39,28 @@ static const rb_data_type_t rg_glib_signal_type = {
39
39
  RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
40
40
  };
41
41
 
42
- VALUE
43
- rbgobj_signal_new(guint id)
42
+ static VALUE
43
+ rbgobj_signal_alloc_func(VALUE klass)
44
44
  {
45
- VALUE rb_query;
46
45
  GSignalQuery *query;
47
-
48
- rb_query = TypedData_Make_Struct(RG_TARGET_NAMESPACE,
49
- GSignalQuery,
50
- &rg_glib_signal_type,
51
- query);
52
- g_signal_query(id, query);
46
+ VALUE rb_query = TypedData_Make_Struct(RG_TARGET_NAMESPACE,
47
+ GSignalQuery,
48
+ &rg_glib_signal_type,
49
+ query);
53
50
  return rb_query;
54
51
  }
55
52
 
53
+ VALUE
54
+ rbgobj_signal_new(guint id)
55
+ {
56
+ ID id_new;
57
+ CONST_ID(id_new, "new");
58
+ return rb_funcall(RG_TARGET_NAMESPACE,
59
+ id_new,
60
+ 1,
61
+ UINT2NUM(id));
62
+ }
63
+
56
64
  static GSignalQuery *
57
65
  rbgobj_signal_get_raw(VALUE rb_signal)
58
66
  {
@@ -398,15 +406,16 @@ gobj_sig_connect_impl(gboolean after, int argc, VALUE *argv, VALUE self)
398
406
  rbgobj_get_signal_func(signal_id));
399
407
  }
400
408
  }
401
- g_rclosure_attach((GClosure *)rclosure, self);
409
+ g_rclosure_attach_gobject(rclosure, self);
402
410
  g_object = RVAL2GOBJ(self);
403
411
  tag = g_strdup_printf("%s::%s",
404
412
  G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(g_object)),
405
413
  sig_name);
406
- g_rclosure_set_tag((GClosure *)rclosure, tag);
414
+ g_rclosure_set_tag(rclosure, tag);
407
415
  g_free(tag);
408
416
  handler_id = g_signal_connect_closure_by_id(g_object, signal_id, detail,
409
417
  rclosure, after);
418
+ g_closure_unref(rclosure);
410
419
 
411
420
  return ULONG2NUM(handler_id);
412
421
  }
@@ -725,7 +734,7 @@ gobj_s_signal_handler_attach(VALUE klass,
725
734
  Qnil,
726
735
  rbgobj_get_signal_func(signal_id));
727
736
  g_rclosure_set_tag(rclosure, handler_name);
728
- g_rclosure_attach((GClosure *)rclosure, klass);
737
+ g_rclosure_attach(rclosure, klass);
729
738
  g_signal_override_class_closure(signal_id, cinfo->gtype, rclosure);
730
739
 
731
740
  {
@@ -745,6 +754,13 @@ rbgobj_signal_wrap(guint sig_id)
745
754
  return rbgobj_signal_new(sig_id);
746
755
  }
747
756
 
757
+ static VALUE
758
+ rg_initialize(VALUE self, VALUE id)
759
+ {
760
+ g_signal_query(NUM2UINT(id), rbgobj_signal_get_raw(self));
761
+ return RUBY_Qnil;
762
+ }
763
+
748
764
  static VALUE
749
765
  rg_id(VALUE self)
750
766
  {
@@ -957,8 +973,10 @@ Init_gobject_gsignal(void)
957
973
  {
958
974
  VALUE cSignalFlags, cSignalMatchType;
959
975
 
960
- RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Signal", rb_cObject);
976
+ RG_TARGET_NAMESPACE = rb_define_class_under(rbg_mGLib(), "Signal", rb_cObject);
977
+ rb_define_alloc_func(RG_TARGET_NAMESPACE, rbgobj_signal_alloc_func);
961
978
 
979
+ RG_DEF_METHOD(initialize, 1);
962
980
  RG_DEF_METHOD(id, 0);
963
981
  RG_DEF_METHOD(name, 0);
964
982
  RG_DEF_METHOD(flags, 0);
@@ -972,7 +990,7 @@ Init_gobject_gsignal(void)
972
990
  RG_DEF_METHOD(remove_emission_hook, 1);
973
991
 
974
992
  /* GSignalFlags */
975
- cSignalFlags = G_DEF_CLASS(G_TYPE_SIGNAL_FLAGS, "SignalFlags", mGLib);
993
+ cSignalFlags = G_DEF_CLASS(G_TYPE_SIGNAL_FLAGS, "SignalFlags", rbg_mGLib());
976
994
  G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, G_TYPE_SIGNAL_FLAGS, "G_SIGNAL_");
977
995
  rb_define_const(cSignalFlags, "MASK", INT2NUM(G_SIGNAL_FLAGS_MASK));
978
996
  rb_define_const(RG_TARGET_NAMESPACE, "FLAGS_MASK", INT2NUM(G_SIGNAL_FLAGS_MASK));
@@ -986,19 +1004,19 @@ Init_gobject_gsignal(void)
986
1004
  rbg_define_method(RG_TARGET_NAMESPACE, "no_hooks?", query_is_G_SIGNAL_NO_HOOKS, 0);
987
1005
 
988
1006
  /* GConnectFlags */
989
- G_DEF_CLASS(G_TYPE_CONNECT_FLAGS, "ConnectFlags", mGLib);
1007
+ G_DEF_CLASS(G_TYPE_CONNECT_FLAGS, "ConnectFlags", rbg_mGLib());
990
1008
  G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, G_TYPE_CONNECT_FLAGS, "G_");
991
1009
 
992
1010
  /* GSignalMatchType */
993
1011
  cSignalMatchType = G_DEF_CLASS(G_TYPE_SIGNAL_MATCH_TYPE,
994
- "SignalMatchType", mGLib);
1012
+ "SignalMatchType", rbg_mGLib());
995
1013
  G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, G_TYPE_SIGNAL_MATCH_TYPE, "G_SIGNAL_");
996
1014
  rb_define_const(cSignalMatchType, "MASK", INT2NUM(G_SIGNAL_MATCH_MASK));
997
1015
  rb_define_const(RG_TARGET_NAMESPACE, "MATCH_MASK", INT2NUM(G_SIGNAL_MATCH_MASK));
998
1016
 
999
1017
  rb_define_const(RG_TARGET_NAMESPACE, "TYPE_STATIC_SCOPE", INT2FIX(G_SIGNAL_TYPE_STATIC_SCOPE));
1000
1018
 
1001
- eNoSignalError = rb_define_class_under(mGLib, "NoSignalError", rb_eNameError);
1019
+ eNoSignalError = rb_define_class_under(rbg_mGLib(), "NoSignalError", rb_eNameError);
1002
1020
 
1003
1021
  rbg_signal_func_table = g_hash_table_new(g_direct_hash, g_direct_equal);
1004
1022
  g_mutex_init(&rbg_signal_func_table_mutex);
@@ -993,12 +993,12 @@ Init_gobject_gtype(void)
993
993
  id_lock = rb_intern("lock");
994
994
  id_unlock = rb_intern("unlock");
995
995
  lookup_class_mutex = rb_funcall(rb_cMutex, id_new, 0);
996
- rb_iv_set(mGLib, "lookup_class_mutex", lookup_class_mutex);
996
+ rb_iv_set(rbg_mGLib(), "lookup_class_mutex", lookup_class_mutex);
997
997
 
998
998
  dynamic_gtype_list = g_hash_table_new(g_str_hash, g_str_equal);
999
999
  id_gtype = rb_intern("__gobject_gtype__");
1000
1000
 
1001
- RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Type", rb_cObject);
1001
+ RG_TARGET_NAMESPACE = rb_define_class_under(rbg_mGLib(), "Type", rb_cObject);
1002
1002
 
1003
1003
  RG_DEF_SMETHOD(try_convert, 1);
1004
1004