glib2 3.4.0 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/Rakefile +6 -4
  4. data/ext/glib2/extconf.rb +1 -5
  5. data/ext/glib2/glib2.def +1 -0
  6. data/ext/glib2/rbglib-bytes.c +1 -5
  7. data/ext/glib2/rbglib-gc.c +98 -52
  8. data/ext/glib2/rbglib-variant-type.c +1 -5
  9. data/ext/glib2/rbglib-variant.c +3 -5
  10. data/ext/glib2/rbglib.c +4 -0
  11. data/ext/glib2/rbglib.h +13 -3
  12. data/ext/glib2/rbglib_bookmarkfile.c +4 -4
  13. data/ext/glib2/rbglib_datetime.c +1 -5
  14. data/ext/glib2/rbglib_error.c +3 -1
  15. data/ext/glib2/rbglib_fileutils.c +1 -17
  16. data/ext/glib2/rbglib_iochannel.c +4 -4
  17. data/ext/glib2/rbglib_keyfile.c +16 -41
  18. data/ext/glib2/rbglib_maincontext.c +6 -32
  19. data/ext/glib2/rbglib_mainloop.c +2 -17
  20. data/ext/glib2/rbglib_matchinfo.c +1 -5
  21. data/ext/glib2/rbglib_pollfd.c +1 -25
  22. data/ext/glib2/rbglib_regex.c +1 -13
  23. data/ext/glib2/rbglib_source.c +1 -39
  24. data/ext/glib2/rbglib_spawn.c +5 -10
  25. data/ext/glib2/rbglib_spawnerror.c +2 -2
  26. data/ext/glib2/rbglib_threads.c +2 -15
  27. data/ext/glib2/rbglib_timezone.c +1 -5
  28. data/ext/glib2/rbglib_unichar.c +46 -5
  29. data/ext/glib2/rbglib_unicode.c +1 -18
  30. data/ext/glib2/rbglib_utils.c +1 -14
  31. data/ext/glib2/rbglib_win32.c +3 -7
  32. data/ext/glib2/rbgobj_binding.c +1 -7
  33. data/ext/glib2/rbgobj_closure.c +22 -9
  34. data/ext/glib2/rbgobj_object.c +113 -104
  35. data/ext/glib2/rbgobj_param.c +2 -8
  36. data/ext/glib2/rbgobj_paramspecs.c +6 -24
  37. data/ext/glib2/rbgobj_signal.c +104 -92
  38. data/ext/glib2/rbgobj_strv.c +2 -2
  39. data/ext/glib2/rbgobj_type.c +58 -68
  40. data/ext/glib2/rbgobj_typeinterface.c +38 -2
  41. data/ext/glib2/rbgobj_value.c +3 -7
  42. data/ext/glib2/rbgobj_valuetypes.c +14 -62
  43. data/ext/glib2/rbgobject.c +4 -6
  44. data/ext/glib2/rbgobject.h +2 -27
  45. data/ext/glib2/rbgprivate.h +6 -6
  46. data/ext/glib2/rbgutil_callback.c +23 -26
  47. data/lib/glib2.rb +32 -3
  48. data/lib/glib2/deprecated.rb +22 -1
  49. data/lib/mkmf-gnome.rb +4 -4
  50. data/test/glib-test-utils.rb +18 -3
  51. data/test/run-test.rb +49 -14
  52. data/test/test-binding.rb +1 -11
  53. data/test/test-bytes.rb +1 -5
  54. data/test/test-date-time.rb +1 -3
  55. data/test/test-file-utils.rb +1 -32
  56. data/test/test-iochannel.rb +3 -5
  57. data/test/test-key-file.rb +5 -6
  58. data/test/test-match-info.rb +1 -5
  59. data/test/test-regex.rb +1 -5
  60. data/test/test-source.rb +1 -14
  61. data/test/test-spawn.rb +2 -1
  62. data/test/test-time-zone.rb +1 -5
  63. data/test/test-timeout.rb +2 -3
  64. data/test/test-unicode.rb +16 -12
  65. data/test/test-utils.rb +2 -8
  66. data/test/test-variant-type.rb +1 -3
  67. data/test/test-win32.rb +6 -6
  68. metadata +3 -7
  69. data/ext/glib2/glib-enum-types.c +0 -1233
  70. data/ext/glib2/glib-enum-types.h +0 -154
  71. data/ext/glib2/rbgobj_valuearray.c +0 -100
  72. data/test/glib-test-init.rb +0 -21
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2011-2021 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
@@ -69,7 +69,7 @@ rbgobj_gvalue_to_rvalue(const GValue* value)
69
69
  case G_TYPE_NONE:
70
70
  return Qnil;
71
71
  case G_TYPE_CHAR:
72
- return CHR2FIX(g_value_get_char(value));
72
+ return CHR2FIX(g_value_get_schar(value));
73
73
  case G_TYPE_UCHAR:
74
74
  return INT2FIX(g_value_get_uchar(value));
75
75
  case G_TYPE_BOOLEAN:
@@ -130,14 +130,12 @@ rbgobj_gvalue_to_rvalue(const GValue* value)
130
130
  return func(value);
131
131
  }
132
132
  }
133
- #if GLIB_CHECK_VERSION(2, 26, 0)
134
133
  case G_TYPE_VARIANT:
135
134
  {
136
135
  GVariant *variant = g_value_peek_pointer(value);
137
136
  rvalue = rbg_variant_to_ruby(variant);
138
137
  return rvalue;
139
138
  }
140
- #endif
141
139
  default:
142
140
  if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) {
143
141
  GValueToRValueFunc func;
@@ -248,7 +246,7 @@ rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
248
246
  case G_TYPE_NONE:
249
247
  return;
250
248
  case G_TYPE_CHAR:
251
- g_value_set_char(result, NUM2INT(val));
249
+ g_value_set_schar(result, NUM2INT(val));
252
250
  return;
253
251
  case G_TYPE_UCHAR:
254
252
  g_value_set_uchar(result, NUM2UINT(val));
@@ -318,11 +316,9 @@ rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
318
316
  return;
319
317
  }
320
318
  }
321
- #if GLIB_CHECK_VERSION(2, 26, 0)
322
319
  case G_TYPE_VARIANT:
323
320
  g_value_set_variant(result, rbg_variant_from_ruby(val));
324
321
  break;
325
- #endif
326
322
  default:
327
323
  if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) {
328
324
  RValueToGValueFunc func =
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2020 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
@@ -65,63 +65,23 @@ Init_gtype_pointer(void)
65
65
 
66
66
  /**********************************************************************/
67
67
 
68
- static GHashTable* boxed_ruby_value_table;
69
- static VALUE boxed_ruby_value_table_wrapper;
70
-
71
- typedef struct {
72
- VALUE obj;
73
- guint ref_count;
74
- } boxed_ruby_value_counter;
75
-
76
- static void
77
- boxed_ruby_value_counter_mark(G_GNUC_UNUSED gpointer key,
78
- gpointer value,
79
- G_GNUC_UNUSED gpointer user_data)
80
- {
81
- boxed_ruby_value_counter* counter = value;
82
- if (counter->ref_count)
83
- rb_gc_mark(counter->obj);
84
- }
85
-
86
- static void
87
- boxed_ruby_value_table_mark(GHashTable* table)
68
+ static gpointer
69
+ boxed_ruby_value_ref(gpointer boxed)
88
70
  {
89
- g_hash_table_foreach(table, boxed_ruby_value_counter_mark, NULL);
90
- }
91
-
92
- static VALUE
93
- boxed_ruby_value_ref(VALUE val)
94
- {
95
- if (!SPECIAL_CONST_P(val)){
96
- boxed_ruby_value_counter* counter;
97
-
98
- counter = g_hash_table_lookup(boxed_ruby_value_table, (gpointer)val);
99
-
100
- if (!counter){
101
- counter = g_new(boxed_ruby_value_counter, 1);
102
- counter->obj = val;
103
- counter->ref_count = 1;
104
- g_hash_table_insert(boxed_ruby_value_table, (gpointer)val,
105
- counter);
106
- } else {
107
- counter->ref_count += 1;
108
- }
71
+ VALUE value = POINTER2RVAL(boxed);
72
+ if (!SPECIAL_CONST_P(value)) {
73
+ rbg_gc_guard(boxed, value);
109
74
  }
110
- return val;
75
+ return boxed;
111
76
  }
112
77
 
113
78
  static void
114
- boxed_ruby_value_unref(VALUE val)
79
+ boxed_ruby_value_unref(gpointer boxed)
115
80
  {
116
- if (!SPECIAL_CONST_P(val)){
117
- boxed_ruby_value_counter* counter;
118
-
119
- counter = g_hash_table_lookup(boxed_ruby_value_table, (gpointer)val);
120
- counter->ref_count -= 1;
121
-
122
- if (!counter->ref_count)
123
- g_hash_table_remove(boxed_ruby_value_table, (gpointer)val);
124
- }
81
+ VALUE value = POINTER2RVAL(boxed);
82
+ if (SPECIAL_CONST_P(value))
83
+ return;
84
+ rbg_gc_unguard(boxed);
125
85
  }
126
86
 
127
87
  struct transform_arg {
@@ -203,13 +163,13 @@ rbgobj_ruby_value_get_type(void)
203
163
  VALUE
204
164
  g_value_get_ruby_value(const GValue* value)
205
165
  {
206
- return (VALUE)g_value_get_boxed(value);
166
+ return POINTER2RVAL(g_value_get_boxed(value));
207
167
  }
208
168
 
209
169
  void
210
170
  g_value_set_ruby_value(GValue* value, VALUE ruby)
211
171
  {
212
- g_value_set_boxed(value, (gconstpointer)ruby);
172
+ g_value_set_boxed(value, RVAL2POINTER(ruby));
213
173
  }
214
174
 
215
175
  static void
@@ -221,14 +181,6 @@ ruby_value_r2g(VALUE from, GValue* to)
221
181
  static void
222
182
  Init_boxed_ruby_value(void)
223
183
  {
224
- boxed_ruby_value_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
225
-
226
- boxed_ruby_value_table_wrapper =
227
- Data_Wrap_Struct(rb_cData,
228
- boxed_ruby_value_table_mark, NULL,
229
- boxed_ruby_value_table);
230
- rb_global_variable(&boxed_ruby_value_table_wrapper);
231
-
232
184
  rbgobj_register_g2r_func(RBGOBJ_TYPE_RUBY_VALUE, g_value_get_ruby_value);
233
185
  rbgobj_register_r2g_func(RBGOBJ_TYPE_RUBY_VALUE, ruby_value_r2g);
234
186
  }
@@ -1,11 +1,10 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2018 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2003-2006 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2003-2021 Ruby-GNOME Project Team
5
4
  * Copyright (C) 2002,2003 Masahiro Sakai
6
- * Copyright (C) 1998-2000 Yukihiro Matsumoto,
7
- * Daisuke Kanda,
8
- * Hiroshi Igarashi
5
+ * Copyright (C) 1998-2000 Yukihiro Matsumoto,
6
+ * Daisuke Kanda,
7
+ * Hiroshi Igarashi
9
8
  *
10
9
  * This library is free software; you can redistribute it and/or
11
10
  * modify it under the terms of the GNU Lesser General Public
@@ -405,7 +404,6 @@ Init_gobject(void)
405
404
  Init_gobject_gvaluetypes();
406
405
  Init_gobject_gboxed();
407
406
  Init_gobject_gstrv();
408
- Init_gobject_value_array();
409
407
  Init_gobject_genumflags();
410
408
  Init_gobject_gparam();
411
409
  Init_gobject_gparamspecs();
@@ -1,7 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2019 Ruby-GNOME Project Team
4
- * Copyright (C) 2003,2006 Ruby-GNOME Project Team
3
+ * Copyright (C) 2003-2021 Ruby-GNOME Project Team
5
4
  * Copyright (C) 2002,2003 Masahiro Sakai
6
5
  *
7
6
  * This library is free software; you can redistribute it and/or
@@ -206,6 +205,7 @@ extern void rbgobj_register_mark_func(GType gtype, RGMarkFunc mark);
206
205
  extern void rbgobj_register_free_func(GType gtype, RGFreeFunc free);
207
206
  extern VALUE rbgobj_cType;
208
207
  extern VALUE rbgobj_gtype_new(GType gtype);
208
+ /* Deprecated. Use rbgobj_gtype_from_ruby() instead. */
209
209
  extern GType rbgobj_gtype_get(VALUE obj);
210
210
 
211
211
  /* rbgobj_signal.c */
@@ -292,31 +292,6 @@ extern VALUE rbgobj_enum_alloc_func(VALUE klass);
292
292
  extern VALUE rbgobj_flags_alloc_func(VALUE klass);
293
293
 
294
294
 
295
- /* rbglib_mainloop.c */
296
- #if !GLIB_CHECK_VERSION(2,30,0)
297
- #define G_TYPE_MAIN_LOOP (g_main_loop_get_type())
298
- extern GType g_main_loop_get_type(void);
299
- #endif
300
-
301
- /* rbglib_maincontext.c */
302
- #if !GLIB_CHECK_VERSION(2,30,0)
303
- #define G_TYPE_MAIN_CONTEXT (g_main_context_get_type())
304
- #define G_TYPE_SOURCE (g_source_get_type())
305
- extern GType g_main_context_get_type(void);
306
- extern GType g_source_get_type(void);
307
- #endif
308
-
309
- #if !GLIB_CHECK_VERSION(2, 36, 0)
310
- #define G_TYPE_POLLFD (g_pollfd_get_type())
311
- extern GType g_pollfd_get_type(void);
312
- #endif
313
-
314
- /* rbglib_keyfile.c */
315
- #if !GLIB_CHECK_VERSION(2,31,2)
316
- #define G_TYPE_KEY_FILE (g_key_file_get_type())
317
- extern GType g_key_file_get_type(void);
318
- #endif
319
-
320
295
  /* rbgobj_convert.c */
321
296
  typedef struct {
322
297
  GType type;
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2007-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2007-2021 Ruby-GNOME Project Team
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -21,12 +21,13 @@
21
21
  #pragma once
22
22
 
23
23
  /*
24
- * CentOS 6: GLib 2.28
25
24
  * CentOS 7: GLib 2.50
25
+ * CentOS 8: GLib 2.56
26
26
  * Ubuntu 16.04: GLib 2.48
27
- * Ubuntu 18.04: GLib 2.54
27
+ * Ubuntu 18.04: GLib 2.56
28
+ * Ubuntu 20.04: GLib 2.64
28
29
  */
29
- #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_28
30
+ #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_48
30
31
 
31
32
  #include "rbgobject.h"
32
33
 
@@ -58,7 +59,7 @@ typedef struct {
58
59
  GType type;
59
60
  } boxed_holder;
60
61
 
61
- G_GNUC_INTERNAL extern GStaticPrivate rg_polling_key;
62
+ G_GNUC_INTERNAL extern GPrivate rg_polling_key;
62
63
  G_GNUC_INTERNAL extern rb_encoding *rbg_filename_encoding;
63
64
 
64
65
  extern VALUE rbgobj_cEnum;
@@ -181,7 +182,6 @@ G_GNUC_INTERNAL void Init_gobject_gvalue(void);
181
182
  G_GNUC_INTERNAL void Init_gobject_gvaluetypes(void);
182
183
  G_GNUC_INTERNAL void Init_gobject_gboxed(void);
183
184
  G_GNUC_INTERNAL void Init_gobject_gstrv(void);
184
- G_GNUC_INTERNAL void Init_gobject_value_array(void);
185
185
  G_GNUC_INTERNAL void Init_gobject_genumflags(void);
186
186
  G_GNUC_INTERNAL void Init_gobject_genums(void);
187
187
  G_GNUC_INTERNAL void Init_gobject_gflags(void);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2007-2019 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2007-2021 Ruby-GNOME Project Team
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -61,11 +61,11 @@ typedef struct _CallbackRequest {
61
61
  VALUE (*function)(VALUE);
62
62
  VALUE argument;
63
63
  VALUE result;
64
- GMutex *done_mutex;
65
- GCond *done_cond;
64
+ GMutex done_mutex;
65
+ GCond done_cond;
66
66
  } CallbackRequest;
67
67
 
68
- static GMutex *callback_dispatch_thread_mutex = NULL;
68
+ static GMutex callback_dispatch_thread_mutex;
69
69
  static GAsyncQueue *callback_request_queue = NULL;
70
70
  static ID id_callback_dispatch_thread;
71
71
  static gint callback_pipe_fds[2] = {-1, -1};
@@ -84,10 +84,10 @@ static VALUE
84
84
  process_request(void *user_data)
85
85
  {
86
86
  CallbackRequest *request = user_data;
87
- g_mutex_lock(request->done_mutex);
87
+ g_mutex_lock(&(request->done_mutex));
88
88
  request->result = rbgutil_protect(exec_callback, (VALUE)request);
89
- g_cond_signal(request->done_cond);
90
- g_mutex_unlock(request->done_mutex);
89
+ g_cond_signal(&(request->done_cond));
90
+ g_mutex_unlock(&(request->done_mutex));
91
91
 
92
92
  return Qnil;
93
93
  }
@@ -146,30 +146,30 @@ invoke_callback_in_ruby_thread(VALUE (*func)(VALUE), VALUE arg)
146
146
  {
147
147
  CallbackRequest request;
148
148
 
149
- g_mutex_lock(callback_dispatch_thread_mutex);
149
+ g_mutex_lock(&callback_dispatch_thread_mutex);
150
150
  if (callback_pipe_fds[0] == -1) {
151
151
  g_error("Please call rbgutil_start_callback_dispatch_thread() "
152
152
  "to dispatch a callback from non-ruby thread before "
153
153
  "callbacks are requested from non-ruby thread.");
154
- g_mutex_unlock(callback_dispatch_thread_mutex);
154
+ g_mutex_unlock(&callback_dispatch_thread_mutex);
155
155
  return Qnil;
156
156
  }
157
157
 
158
158
  request.function = func;
159
159
  request.argument = arg;
160
160
  request.result = Qnil;
161
- request.done_mutex = g_mutex_new();
162
- request.done_cond = g_cond_new();
161
+ g_mutex_init(&(request.done_mutex));
162
+ g_cond_init(&(request.done_cond));
163
163
 
164
- g_mutex_lock(request.done_mutex);
164
+ g_mutex_lock(&(request.done_mutex));
165
165
  queue_callback_request(&request);
166
- g_mutex_unlock(callback_dispatch_thread_mutex);
166
+ g_mutex_unlock(&callback_dispatch_thread_mutex);
167
167
 
168
- g_cond_wait(request.done_cond, request.done_mutex);
169
- g_mutex_unlock(request.done_mutex);
168
+ g_cond_wait(&(request.done_cond), &(request.done_mutex));
169
+ g_mutex_unlock(&(request.done_mutex));
170
170
 
171
- g_cond_free(request.done_cond);
172
- g_mutex_free(request.done_mutex);
171
+ g_cond_clear(&(request.done_cond));
172
+ g_mutex_clear(&(request.done_mutex));
173
173
 
174
174
 
175
175
  return request.result;
@@ -195,7 +195,7 @@ rbgutil_invoke_callback(VALUE (*func)(VALUE), VALUE arg)
195
195
  {
196
196
  #ifdef HAVE_NATIVETHREAD
197
197
  if (ruby_native_thread_p()) {
198
- if (!GPOINTER_TO_INT(g_static_private_get(&rg_polling_key))) {
198
+ if (!GPOINTER_TO_INT(g_private_get(&rg_polling_key))) {
199
199
  return rbgutil_protect(func, arg);
200
200
  }
201
201
  # ifdef HAVE_RB_THREAD_CALL_WITH_GVL
@@ -221,7 +221,7 @@ rbgutil_start_callback_dispatch_thread(void)
221
221
  #ifdef HAVE_NATIVETHREAD
222
222
  VALUE callback_dispatch_thread;
223
223
 
224
- g_mutex_lock(callback_dispatch_thread_mutex);
224
+ g_mutex_lock(&callback_dispatch_thread_mutex);
225
225
  callback_dispatch_thread = rb_ivar_get(mGLib, id_callback_dispatch_thread);
226
226
  if (NIL_P(callback_dispatch_thread)) {
227
227
  if (pipe(callback_pipe_fds) == -1)
@@ -231,7 +231,7 @@ rbgutil_start_callback_dispatch_thread(void)
231
231
  rb_ivar_set(mGLib, id_callback_dispatch_thread,
232
232
  callback_dispatch_thread);
233
233
  }
234
- g_mutex_unlock(callback_dispatch_thread_mutex);
234
+ g_mutex_unlock(&callback_dispatch_thread_mutex);
235
235
  #endif
236
236
  }
237
237
 
@@ -241,13 +241,13 @@ rbgutil_stop_callback_dispatch_thread(void)
241
241
  #ifdef HAVE_NATIVETHREAD
242
242
  VALUE callback_dispatch_thread;
243
243
 
244
- g_mutex_lock(callback_dispatch_thread_mutex);
244
+ g_mutex_lock(&callback_dispatch_thread_mutex);
245
245
  callback_dispatch_thread = rb_ivar_get(mGLib, id_callback_dispatch_thread);
246
246
  if (!NIL_P(callback_dispatch_thread)) {
247
247
  queue_callback_request(NULL);
248
248
  rb_ivar_set(mGLib, id_callback_dispatch_thread, Qnil);
249
249
  }
250
- g_mutex_unlock(callback_dispatch_thread_mutex);
250
+ g_mutex_unlock(&callback_dispatch_thread_mutex);
251
251
  #endif
252
252
  }
253
253
 
@@ -260,13 +260,10 @@ Init_gutil_callback(void)
260
260
  rb_eRuntimeError);
261
261
 
262
262
  #ifdef HAVE_NATIVETHREAD
263
- if (!g_thread_supported())
264
- g_thread_init(NULL);
265
-
266
263
  id_callback_dispatch_thread = rb_intern("callback_dispatch_thread");
267
264
  rb_ivar_set(mGLib, id_callback_dispatch_thread, Qnil);
268
265
 
269
266
  callback_request_queue = g_async_queue_new();
270
- callback_dispatch_thread_mutex = g_mutex_new();
267
+ g_mutex_init(&callback_dispatch_thread_mutex);
271
268
  #endif
272
269
  }
data/lib/glib2.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2005-2019 Ruby-GNOME Project Team
1
+ # Copyright (C) 2005-2021 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -117,17 +117,46 @@ end
117
117
  require "glib2.so"
118
118
 
119
119
  module GLib
120
+ SIGNAL_HANDLER_PREFIX = "signal_do_"
121
+ VIRTUAL_FUNCTION_IMPLEMENTATION_PREFIX = "virtual_do_"
122
+
120
123
  module MetaInterface
121
124
  class << self
122
- def signal_callback(klass, id)
125
+ def signal_callback(klass, name)
123
126
  lambda do |instance, *args|
124
- klass.instance_method(id).bind(instance).call(*args)
127
+ method_name = "#{SIGNAL_HANDLER_PREFIX}#{name}"
128
+ klass.instance_method(method_name).bind(instance).call(*args)
125
129
  end
126
130
  end
127
131
  end
128
132
  end
129
133
 
130
134
  class Instantiatable
135
+ class << self
136
+ def method_added(name)
137
+ super
138
+
139
+ case name.to_s
140
+ when /\A#{Regexp.escape(SIGNAL_HANDLER_PREFIX)}/o
141
+ signal_name = $POSTMATCH
142
+ begin
143
+ signal_ = signal(signal_name)
144
+ rescue NoSignalError
145
+ return
146
+ end
147
+ return unless signal_.class != self
148
+ signal_handler_attach(signal_, name.to_s) do |instance, *args|
149
+ instance.__send__(name, *args)
150
+ end
151
+ when /\A#{Regexp.escape(VIRTUAL_FUNCTION_IMPLEMENTATION_PREFIX)}/o
152
+ ancestors.each do |klass|
153
+ next unless klass.respond_to?(:implement_virtual_function)
154
+ return if klass.implement_virtual_function(self, name)
155
+ end
156
+ end
157
+ end
158
+ end
159
+
131
160
  private
132
161
  def create_signal_handler(signal_name, callback)
133
162
  callback