glib2 3.4.3 → 3.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/ext/glib2/extconf.rb +1 -5
  4. data/ext/glib2/rbglib-bytes.c +1 -5
  5. data/ext/glib2/rbglib-gc.c +98 -52
  6. data/ext/glib2/rbglib-variant-type.c +1 -5
  7. data/ext/glib2/rbglib-variant.c +3 -5
  8. data/ext/glib2/rbglib.c +4 -0
  9. data/ext/glib2/rbglib.h +4 -1
  10. data/ext/glib2/rbglib_bookmarkfile.c +1 -1
  11. data/ext/glib2/rbglib_datetime.c +1 -5
  12. data/ext/glib2/rbglib_fileutils.c +1 -17
  13. data/ext/glib2/rbglib_iochannel.c +4 -4
  14. data/ext/glib2/rbglib_keyfile.c +1 -35
  15. data/ext/glib2/rbglib_maincontext.c +6 -32
  16. data/ext/glib2/rbglib_mainloop.c +2 -17
  17. data/ext/glib2/rbglib_matchinfo.c +1 -5
  18. data/ext/glib2/rbglib_pollfd.c +1 -25
  19. data/ext/glib2/rbglib_regex.c +1 -13
  20. data/ext/glib2/rbglib_source.c +1 -39
  21. data/ext/glib2/rbglib_spawn.c +5 -10
  22. data/ext/glib2/rbglib_spawnerror.c +2 -2
  23. data/ext/glib2/rbglib_threads.c +2 -15
  24. data/ext/glib2/rbglib_timezone.c +1 -5
  25. data/ext/glib2/rbglib_unichar.c +46 -5
  26. data/ext/glib2/rbglib_unicode.c +1 -18
  27. data/ext/glib2/rbglib_utils.c +1 -14
  28. data/ext/glib2/rbglib_win32.c +3 -7
  29. data/ext/glib2/rbgobj_binding.c +1 -7
  30. data/ext/glib2/rbgobj_closure.c +22 -9
  31. data/ext/glib2/rbgobj_object.c +113 -104
  32. data/ext/glib2/rbgobj_param.c +2 -8
  33. data/ext/glib2/rbgobj_paramspecs.c +6 -24
  34. data/ext/glib2/rbgobj_signal.c +81 -48
  35. data/ext/glib2/rbgobj_strv.c +2 -2
  36. data/ext/glib2/rbgobj_type.c +57 -67
  37. data/ext/glib2/rbgobj_value.c +3 -7
  38. data/ext/glib2/rbgobj_valuetypes.c +14 -62
  39. data/ext/glib2/rbgobject.c +4 -6
  40. data/ext/glib2/rbgobject.h +2 -27
  41. data/ext/glib2/rbgprivate.h +6 -6
  42. data/ext/glib2/rbgutil_callback.c +23 -26
  43. data/lib/glib2/deprecated.rb +22 -1
  44. data/lib/mkmf-gnome.rb +5 -5
  45. data/test/glib-test-utils.rb +18 -3
  46. data/test/run-test.rb +49 -15
  47. data/test/test-binding.rb +1 -11
  48. data/test/test-bytes.rb +1 -5
  49. data/test/test-date-time.rb +1 -3
  50. data/test/test-file-utils.rb +1 -32
  51. data/test/test-iochannel.rb +3 -5
  52. data/test/test-key-file.rb +5 -6
  53. data/test/test-match-info.rb +1 -5
  54. data/test/test-regex.rb +1 -5
  55. data/test/test-source.rb +1 -14
  56. data/test/test-spawn.rb +2 -1
  57. data/test/test-time-zone.rb +1 -5
  58. data/test/test-timeout.rb +2 -3
  59. data/test/test-unicode.rb +16 -12
  60. data/test/test-utils.rb +2 -8
  61. data/test/test-variant-type.rb +1 -3
  62. data/test/test-win32.rb +6 -6
  63. metadata +3 -5
  64. data/ext/glib2/rbgobj_valuearray.c +0 -100
  65. data/test/glib-test-init.rb +0 -19
@@ -1,7 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2004 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2004-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
@@ -116,7 +115,7 @@ enum_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
116
115
  VALUE enum_type, VALUE default_value, VALUE flags)
117
116
  {
118
117
  GParamSpec* pspec;
119
- GType gtype = rbgobj_gtype_get(enum_type);
118
+ GType gtype = rbgobj_gtype_from_ruby(enum_type);
120
119
 
121
120
  pspec = g_param_spec_enum(StringValuePtr(name),
122
121
  StringValuePtr(nick),
@@ -133,7 +132,7 @@ flags_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
133
132
  VALUE flags_type, VALUE default_value, VALUE flags)
134
133
  {
135
134
  GParamSpec* pspec;
136
- GType gtype = rbgobj_gtype_get(flags_type);
135
+ GType gtype = rbgobj_gtype_from_ruby(flags_type);
137
136
 
138
137
  pspec = g_param_spec_flags(StringValuePtr(name),
139
138
  StringValuePtr(nick),
@@ -167,7 +166,7 @@ param_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
167
166
  pspec = g_param_spec_param(StringValuePtr(name),
168
167
  StringValuePtr(nick),
169
168
  StringValuePtr(blurb),
170
- rbgobj_gtype_get(param_type),
169
+ rbgobj_gtype_from_ruby(param_type),
171
170
  NUM2UINT(flags));
172
171
  rbgobj_param_spec_initialize(self, pspec);
173
172
  return Qnil;
@@ -181,7 +180,7 @@ boxed_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
181
180
  pspec = g_param_spec_boxed(StringValuePtr(name),
182
181
  StringValuePtr(nick),
183
182
  StringValuePtr(blurb),
184
- rbgobj_gtype_get(boxed_type),
183
+ rbgobj_gtype_from_ruby(boxed_type),
185
184
  NUM2UINT(flags));
186
185
  rbgobj_param_spec_initialize(self, pspec);
187
186
  return Qnil;
@@ -199,20 +198,6 @@ pointer_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb, VALUE flags)
199
198
  return Qnil;
200
199
  }
201
200
 
202
- static VALUE
203
- value_array_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
204
- VALUE element_spec, VALUE flags)
205
- {
206
- GParamSpec* pspec;
207
- pspec = g_param_spec_value_array(StringValuePtr(name),
208
- StringValuePtr(nick),
209
- StringValuePtr(blurb),
210
- RVAL2GOBJ(element_spec),
211
- NUM2UINT(flags));
212
- rbgobj_param_spec_initialize(self, pspec);
213
- return Qnil;
214
- }
215
-
216
201
  static VALUE
217
202
  object_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
218
203
  VALUE object_type, VALUE flags)
@@ -221,7 +206,7 @@ object_initialize(VALUE self, VALUE name, VALUE nick, VALUE blurb,
221
206
  pspec = g_param_spec_object(StringValuePtr(name),
222
207
  StringValuePtr(nick),
223
208
  StringValuePtr(blurb),
224
- rbgobj_gtype_get(object_type),
209
+ rbgobj_gtype_from_ruby(object_type),
225
210
  NUM2UINT(flags));
226
211
  rbgobj_param_spec_initialize(self, pspec);
227
212
  return Qnil;
@@ -303,9 +288,6 @@ Init_gobject_gparamspecs(void)
303
288
  c = G_DEF_CLASS(G_TYPE_PARAM_POINTER, "Pointer", cParamSpec);
304
289
  rbg_define_method(c, "initialize", pointer_initialize, 4);
305
290
 
306
- c = G_DEF_CLASS(G_TYPE_PARAM_VALUE_ARRAY, "ValueArray", cParamSpec);
307
- rbg_define_method(c, "initialize", value_array_initialize, 5);
308
-
309
291
  c = G_DEF_CLASS(G_TYPE_PARAM_OBJECT, "Object", cParamSpec);
310
292
  rbg_define_method(c, "initialize", object_initialize, 5);
311
293
  }
@@ -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) 2002-2004 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-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
@@ -64,45 +63,57 @@ rbgobj_signal_get_raw(VALUE rb_signal)
64
63
  return query;
65
64
  }
66
65
 
67
- static VALUE signal_func_table;
66
+ static GHashTable *rbg_signal_func_table;
67
+ static GMutex rbg_signal_func_table_mutex;
68
68
 
69
69
  void
70
- rbgobj_set_signal_func(VALUE klass, const gchar *sig_name, GValToRValSignalFunc func)
70
+ rbgobj_set_signal_func(VALUE klass,
71
+ const gchar *signal_name,
72
+ GValToRValSignalFunc func)
71
73
  {
72
- VALUE obj = Data_Wrap_Struct(rb_cData, NULL, NULL, func);
73
- guint signal_id = g_signal_lookup(sig_name, CLASS2GTYPE(klass));
74
- rb_hash_aset(signal_func_table, UINT2NUM(signal_id), obj);
74
+ guint signal_id = g_signal_lookup(signal_name, CLASS2GTYPE(klass));
75
+ g_mutex_lock(&rbg_signal_func_table_mutex);
76
+ g_hash_table_insert(rbg_signal_func_table,
77
+ GUINT_TO_POINTER(signal_id),
78
+ func);
79
+ g_mutex_unlock(&rbg_signal_func_table_mutex);
75
80
  }
76
81
 
77
82
  GValToRValSignalFunc
78
83
  rbgobj_get_signal_func(guint signal_id)
79
84
  {
80
- GValToRValSignalFunc func = NULL;
81
- VALUE func_obj = rb_hash_aref(signal_func_table, UINT2NUM(signal_id));
82
- if (!NIL_P(func_obj))
83
- Data_Get_Struct(func_obj, void, func);
85
+ g_mutex_lock(&rbg_signal_func_table_mutex);
86
+ GValToRValSignalFunc func =
87
+ g_hash_table_lookup(rbg_signal_func_table,
88
+ GUINT_TO_POINTER(signal_id));
89
+ g_mutex_unlock(&rbg_signal_func_table_mutex);
84
90
  return func;
85
91
  }
86
92
 
87
- static VALUE signal_call_func_table;
93
+ static GHashTable *rbg_signal_call_func_table;
94
+ static GMutex rbg_signal_call_func_table_mutex;
88
95
 
89
96
  void
90
97
  rbgobj_set_signal_call_func(VALUE klass,
91
98
  const gchar *signal_name,
92
99
  RGClosureCallFunc func)
93
100
  {
94
- VALUE obj = Data_Wrap_Struct(rb_cData, NULL, NULL, func);
95
101
  guint signal_id = g_signal_lookup(signal_name, CLASS2GTYPE(klass));
96
- rb_hash_aset(signal_call_func_table, UINT2NUM(signal_id), obj);
102
+ g_mutex_lock(&rbg_signal_call_func_table_mutex);
103
+ g_hash_table_insert(rbg_signal_call_func_table,
104
+ GUINT_TO_POINTER(signal_id),
105
+ func);
106
+ g_mutex_unlock(&rbg_signal_call_func_table_mutex);
97
107
  }
98
108
 
99
109
  RGClosureCallFunc
100
110
  rbgobj_get_signal_call_func(guint signal_id)
101
111
  {
102
- RGClosureCallFunc func = NULL;
103
- VALUE func_obj = rb_hash_aref(signal_call_func_table, UINT2NUM(signal_id));
104
- if (!NIL_P(func_obj))
105
- Data_Get_Struct(func_obj, void, func);
112
+ g_mutex_lock(&rbg_signal_call_func_table_mutex);
113
+ RGClosureCallFunc func =
114
+ g_hash_table_lookup(rbg_signal_call_func_table,
115
+ GUINT_TO_POINTER(signal_id));
116
+ g_mutex_unlock(&rbg_signal_call_func_table_mutex);
106
117
  return func;
107
118
  }
108
119
 
@@ -150,7 +161,7 @@ rbg_rval2gtypes_body(VALUE value)
150
161
  struct rval2gtypes_args *args = (struct rval2gtypes_args *)value;
151
162
 
152
163
  for (i = 0; i < args->n; i++)
153
- args->result[i] = rbgobj_gtype_get(RARRAY_PTR(args->ary)[i]);
164
+ args->result[i] = rbgobj_gtype_from_ruby(RARRAY_PTR(args->ary)[i]);
154
165
 
155
166
  return Qnil;
156
167
  }
@@ -240,7 +251,7 @@ gobj_s_define_signal(int argc, VALUE* argv, VALUE self)
240
251
  g_rclosure_set_tag(class_closure, RVAL2CSTR(rb_method_name));
241
252
  }
242
253
 
243
- return_type = rbgobj_gtype_get(rbreturn_type);
254
+ return_type = rbgobj_gtype_from_ruby(rbreturn_type);
244
255
  param_types = RVAL2GTYPES_ACCEPT_NIL(params, n_params);
245
256
 
246
257
  signal = g_signal_newv(signal_name,
@@ -440,30 +451,33 @@ struct emit_arg {
440
451
 
441
452
  GSignalQuery query;
442
453
  GQuark detail;
443
- GValueArray* instance_and_params;
454
+ GArray *instance_and_params;
444
455
  };
445
456
 
446
457
  static VALUE
447
458
  emit_body(VALUE rb_arg)
448
459
  {
449
460
  struct emit_arg *arg = (struct emit_arg *)rb_arg;
450
- GValue param = G_VALUE_INIT;
451
461
 
452
- g_value_init(&param, G_TYPE_FROM_INSTANCE(RVAL2GOBJ(arg->self)));
453
- rbgobj_rvalue_to_gvalue(arg->self, &param);
454
- g_value_array_append(arg->instance_and_params, &param);
455
- g_value_unset(&param);
462
+ gsize value_index = 0;
463
+ GValue *gself = &g_array_index(arg->instance_and_params,
464
+ GValue,
465
+ value_index);
466
+ g_value_init(gself, G_TYPE_FROM_INSTANCE(RVAL2GOBJ(arg->self)));
467
+ rbgobj_rvalue_to_gvalue(arg->self, gself);
468
+ value_index++;
456
469
 
457
470
  {
458
471
  guint i;
459
472
  for (i = 0; i < arg->query.n_params; i++){
460
473
  GType gtype = arg->query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
461
474
 
462
- g_value_init(&param, gtype);
463
-
464
- rbgobj_rvalue_to_gvalue(rb_ary_entry(arg->args, i), &param);
465
- g_value_array_append(arg->instance_and_params, &param);
466
- g_value_unset(&param);
475
+ GValue *gparam = &g_array_index(arg->instance_and_params,
476
+ GValue,
477
+ value_index);
478
+ g_value_init(gparam, gtype);
479
+ rbgobj_rvalue_to_gvalue(rb_ary_entry(arg->args, i), gparam);
480
+ value_index++;
467
481
  }
468
482
  }
469
483
 
@@ -475,7 +489,7 @@ emit_body(VALUE rb_arg)
475
489
  g_value_init(&return_value,
476
490
  arg->query.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
477
491
 
478
- g_signal_emitv(arg->instance_and_params->values,
492
+ g_signal_emitv((GValue *)(arg->instance_and_params->data),
479
493
  arg->query.signal_id, arg->detail,
480
494
  (use_ret) ? &return_value : NULL);
481
495
 
@@ -493,7 +507,7 @@ static VALUE
493
507
  emit_ensure(VALUE rb_arg)
494
508
  {
495
509
  struct emit_arg *arg = (struct emit_arg *)rb_arg;
496
- g_value_array_free(arg->instance_and_params);
510
+ g_array_unref(arg->instance_and_params);
497
511
  return Qnil;
498
512
  }
499
513
 
@@ -525,7 +539,13 @@ gobj_sig_emit(int argc, VALUE *argv, VALUE self)
525
539
  arg.query.n_params + 1);
526
540
 
527
541
  arg.self = self;
528
- arg.instance_and_params = g_value_array_new(1 + arg.query.n_params);
542
+ arg.instance_and_params = g_array_sized_new(FALSE,
543
+ TRUE,
544
+ sizeof(GValue),
545
+ 1 + arg.query.n_params);
546
+ g_array_set_clear_func(arg.instance_and_params,
547
+ (GDestroyNotify)g_value_unset);
548
+ g_array_set_size(arg.instance_and_params, 1 + arg.query.n_params);
529
549
 
530
550
  return rb_ensure(emit_body, (VALUE)&arg, emit_ensure, (VALUE)&arg);
531
551
  }
@@ -628,17 +648,24 @@ static VALUE
628
648
  chain_from_overridden_body(VALUE rb_arg)
629
649
  {
630
650
  struct emit_arg *arg = (struct emit_arg *)rb_arg;
631
- g_value_init(arg->instance_and_params->values,
632
- G_TYPE_FROM_INSTANCE(RVAL2GOBJ(arg->self)));
633
- rbgobj_rvalue_to_gvalue(arg->self, arg->instance_and_params->values);
651
+ gsize value_index = 0;
652
+ GValue *gself = &g_array_index(arg->instance_and_params,
653
+ GValue,
654
+ value_index);
655
+ g_value_init(gself, G_TYPE_FROM_INSTANCE(RVAL2GOBJ(arg->self)));
656
+ rbgobj_rvalue_to_gvalue(arg->self, gself);
657
+ value_index++;
634
658
 
635
659
  {
636
- GValue* params = arg->instance_and_params->values + 1;
637
660
  guint i;
638
661
  for (i = 0; i < arg->query.n_params; i++) {
639
662
  GType gtype = arg->query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
640
- g_value_init(params + i, gtype);
641
- rbgobj_rvalue_to_gvalue(rb_ary_entry(arg->args, i), params + i);
663
+ GValue *gparam = &g_array_index(arg->instance_and_params,
664
+ GValue,
665
+ value_index);
666
+ g_value_init(gparam, gtype);
667
+ rbgobj_rvalue_to_gvalue(rb_ary_entry(arg->args, i), gparam);
668
+ value_index++;
642
669
  }
643
670
  }
644
671
 
@@ -650,7 +677,7 @@ chain_from_overridden_body(VALUE rb_arg)
650
677
  g_value_init(&return_value,
651
678
  arg->query.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
652
679
 
653
- g_signal_chain_from_overridden(arg->instance_and_params->values,
680
+ g_signal_chain_from_overridden((GValue *)(arg->instance_and_params->data),
654
681
  (use_ret) ? &return_value : NULL);
655
682
 
656
683
  if (use_ret) {
@@ -682,7 +709,13 @@ gobj_sig_chain_from_overridden(int argc, VALUE *argv, VALUE self)
682
709
 
683
710
  arg.self = self;
684
711
  arg.args = rb_ary_new4(argc, argv);
685
- arg.instance_and_params = g_value_array_new(1 + argc);
712
+ arg.instance_and_params = g_array_sized_new(FALSE,
713
+ TRUE,
714
+ sizeof(GValue),
715
+ 1 + argc);
716
+ g_array_set_clear_func(arg.instance_and_params,
717
+ (GDestroyNotify)g_value_unset);
718
+ g_array_set_size(arg.instance_and_params, 1 + argc);
686
719
 
687
720
  return rb_ensure(chain_from_overridden_body, (VALUE)&arg,
688
721
  emit_ensure, (VALUE)&arg);
@@ -699,7 +732,7 @@ gobj_s_method_added(VALUE klass, VALUE id)
699
732
  if (cinfo->klass != klass) return Qnil;
700
733
  if (strncmp(default_handler_method_prefix, name, prefix_len)) return Qnil;
701
734
 
702
- signal_id = g_signal_lookup(name + prefix_len, cinfo->gtype);
735
+ signal_id = g_signal_lookup(name + prefix_len, cinfo->gtype);
703
736
  if (!signal_id) return Qnil;
704
737
 
705
738
  {
@@ -947,7 +980,7 @@ Init_gobject_gsignal(void)
947
980
  {
948
981
  VALUE cSignalFlags, cSignalMatchType;
949
982
 
950
- RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Signal", rb_cData);
983
+ RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Signal", rb_cObject);
951
984
 
952
985
  RG_DEF_METHOD(id, 0);
953
986
  RG_DEF_METHOD(name, 0);
@@ -990,11 +1023,11 @@ Init_gobject_gsignal(void)
990
1023
 
991
1024
  eNoSignalError = rb_define_class_under(mGLib, "NoSignalError", rb_eNameError);
992
1025
 
993
- signal_func_table = rb_hash_new();
994
- rb_global_variable(&signal_func_table);
1026
+ rbg_signal_func_table = g_hash_table_new(g_direct_hash, g_direct_equal);
1027
+ g_mutex_init(&rbg_signal_func_table_mutex);
995
1028
 
996
- signal_call_func_table = rb_hash_new();
997
- rb_global_variable(&signal_call_func_table);
1029
+ rbg_signal_call_func_table = g_hash_table_new(g_direct_hash, g_direct_equal);
1030
+ g_mutex_init(&rbg_signal_call_func_table_mutex);
998
1031
 
999
1032
  rbg_define_method(mMetaInterface, "define_signal", gobj_s_define_signal, -1);
1000
1033
  rb_define_alias(mMetaInterface, "signal_new", "define_signal");
@@ -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) 2005 Masao Mutoh
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -30,7 +30,7 @@ strv_to_ruby(const GValue *from)
30
30
  static void
31
31
  strv_from_ruby(VALUE from, GValue *to)
32
32
  {
33
- const gchar **strings = RVAL2STRV(from);
33
+ gchar **strings = RVAL2STRV(from);
34
34
  g_value_set_boxed(to, strings);
35
35
  g_free(strings);
36
36
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-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
@@ -31,9 +31,10 @@ static VALUE rb_cMutex;
31
31
  #endif
32
32
  static VALUE lookup_class_mutex;
33
33
 
34
+ static ID id_gtype;
35
+ static ID id_lock;
34
36
  static ID id_new;
35
37
  static ID id_superclass;
36
- static ID id_lock;
37
38
  static ID id_unlock;
38
39
  static GHashTable *gtype_to_cinfo;
39
40
  static VALUE klass_to_cinfo;
@@ -133,7 +134,7 @@ rbgobj_class_info_register_without_lock(GType gtype, VALUE klass)
133
134
  VALUE c;
134
135
 
135
136
  data_type = rbgobj_class_info_create_data_type(klass);
136
- c = TypedData_Make_Struct(rb_cData, RGObjClassInfo, data_type, cinfo);
137
+ c = TypedData_Make_Struct(rb_cObject, RGObjClassInfo, data_type, cinfo);
137
138
  cinfo->klass = klass;
138
139
  cinfo->gtype = gtype;
139
140
  cinfo->mark = NULL;
@@ -238,9 +239,7 @@ get_superclass(GType gtype, VALUE module)
238
239
  case G_TYPE_OBJECT:
239
240
  return cInstantiatable;
240
241
  case G_TYPE_BOXED:
241
- return rb_cObject;
242
242
  case G_TYPE_POINTER:
243
- return rb_cData;
244
243
  case G_TYPE_ENUM:
245
244
  case G_TYPE_FLAGS:
246
245
  return rb_cObject;
@@ -432,9 +431,9 @@ rbgobj_gtype_to_ruby_class(GType gtype)
432
431
  GType
433
432
  rbgobj_gtype_from_ruby(VALUE rb_gtype)
434
433
  {
435
- ID id_gtype;
436
-
437
- if (RB_TYPE_P(rb_gtype, RUBY_T_STRING)) {
434
+ if (NIL_P(rb_gtype)) {
435
+ return G_TYPE_NONE;
436
+ } else if (RB_TYPE_P(rb_gtype, RUBY_T_STRING)) {
438
437
  GType gtype;
439
438
  gtype = g_type_from_name(RVAL2CSTR(rb_gtype));
440
439
  if (gtype == G_TYPE_INVALID) {
@@ -443,14 +442,13 @@ rbgobj_gtype_from_ruby(VALUE rb_gtype)
443
442
  RVAL2CSTR(rb_gtype));
444
443
  }
445
444
  return gtype;
445
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_gtype, RG_TARGET_NAMESPACE))) {
446
+ return NUM2SIZET(rb_ivar_get(rb_gtype, id_gtype));
447
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_gtype, rb_cClass))) {
448
+ return CLASS2GTYPE(rb_gtype);
449
+ } else {
450
+ return NUM2SIZET(rb_to_int(rb_gtype));
446
451
  }
447
-
448
- CONST_ID(id_gtype, "gtype");
449
- if (rb_respond_to(rb_gtype, id_gtype)) {
450
- rb_gtype = rb_funcall(rb_gtype, id_gtype, 0);
451
- }
452
-
453
- return NUM2ULONG(rb_gtype);
454
452
  }
455
453
 
456
454
  VALUE
@@ -532,7 +530,7 @@ rbgobj_register_class(VALUE klass,
532
530
 
533
531
  if (klass2gtype) {
534
532
  data_type = rbgobj_class_info_create_data_type(klass);
535
- c = TypedData_Make_Struct(rb_cData, RGObjClassInfo, data_type, cinfo);
533
+ c = TypedData_Make_Struct(rb_cObject, RGObjClassInfo, data_type, cinfo);
536
534
  }
537
535
  if (gtype2klass && !cinfo)
538
536
  cinfo = g_new(RGObjClassInfo, 1);
@@ -607,26 +605,21 @@ init_typemap(void)
607
605
  /* GLib::Type */
608
606
 
609
607
  VALUE RG_TARGET_NAMESPACE;
610
- static ID id_gtype;
611
608
 
612
609
  VALUE
613
610
  rbgobj_gtype_new(GType gtype)
614
611
  {
615
612
  VALUE result = rb_obj_alloc(RG_TARGET_NAMESPACE);
616
- VALUE arg = ULONG2NUM(gtype);
613
+ VALUE arg = SIZET2NUM(gtype);
617
614
  rb_obj_call_init(result, 1, &arg);
618
615
  return result;
619
616
  }
620
617
 
618
+ /* Deprecated. Use rbgobj_gtype_from_ruby() instead. */
621
619
  GType
622
- rbgobj_gtype_get(VALUE self)
620
+ rbgobj_gtype_get(VALUE rb_gtype)
623
621
  {
624
- if (RVAL2CBOOL(rb_obj_is_kind_of(self, RG_TARGET_NAMESPACE))) {
625
- return NUM2ULONG(rb_ivar_get(self, id_gtype));
626
- } else {
627
- return CLASS2GTYPE(self);
628
- }
629
- rb_raise(rb_eTypeError, "Not a GLib::Type");
622
+ return rbgobj_gtype_from_ruby(rb_gtype);
630
623
  }
631
624
 
632
625
  static VALUE
@@ -690,7 +683,7 @@ rg_initialize(VALUE self, VALUE type)
690
683
  GType gtype;
691
684
 
692
685
  if (RVAL2CBOOL(rb_obj_is_kind_of(type, rb_cInteger))) {
693
- gtype = NUM2ULONG(type);
686
+ gtype = NUM2SIZET(type);
694
687
  if (!g_type_name(gtype))
695
688
  gtype = G_TYPE_INVALID;
696
689
  } else {
@@ -700,7 +693,7 @@ rg_initialize(VALUE self, VALUE type)
700
693
  if (G_TYPE_INVALID == gtype)
701
694
  rb_raise(rb_eArgError, "invalid GType");
702
695
 
703
- rb_ivar_set(self, id_gtype, ULONG2NUM(gtype));
696
+ rb_ivar_set(self, id_gtype, SIZET2NUM(gtype));
704
697
 
705
698
  return Qnil;
706
699
  }
@@ -708,7 +701,7 @@ rg_initialize(VALUE self, VALUE type)
708
701
  static VALUE
709
702
  rg_inspect(VALUE self)
710
703
  {
711
- GType gtype = rbgobj_gtype_get(self);
704
+ GType gtype = rbgobj_gtype_from_ruby(self);
712
705
  gchar* str;
713
706
  VALUE result;
714
707
 
@@ -725,8 +718,8 @@ rg_operator_type_compare(VALUE self, VALUE other)
725
718
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
726
719
  return Qnil;
727
720
  else {
728
- GType a = rbgobj_gtype_get(self);
729
- GType b = rbgobj_gtype_get(other);
721
+ GType a = rbgobj_gtype_from_ruby(self);
722
+ GType b = rbgobj_gtype_from_ruby(other);
730
723
 
731
724
  if (a==b)
732
725
  return INT2FIX(0);
@@ -745,8 +738,8 @@ rg_operator_type_eq(VALUE self, VALUE other)
745
738
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
746
739
  return Qnil;
747
740
  else {
748
- GType a = rbgobj_gtype_get(self);
749
- GType b = rbgobj_gtype_get(other);
741
+ GType a = rbgobj_gtype_from_ruby(self);
742
+ GType b = rbgobj_gtype_from_ruby(other);
750
743
  return CBOOL2RVAL(a == b);
751
744
  }
752
745
  }
@@ -757,8 +750,8 @@ rg_operator_type_lt_eq(VALUE self, VALUE other)
757
750
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
758
751
  return Qnil;
759
752
  else {
760
- GType a = rbgobj_gtype_get(self);
761
- GType b = rbgobj_gtype_get(other);
753
+ GType a = rbgobj_gtype_from_ruby(self);
754
+ GType b = rbgobj_gtype_from_ruby(other);
762
755
  return CBOOL2RVAL(g_type_is_a(a, b));
763
756
  }
764
757
  }
@@ -769,8 +762,8 @@ rg_operator_type_gt_eq(VALUE self, VALUE other)
769
762
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
770
763
  return Qnil;
771
764
  else {
772
- GType a = rbgobj_gtype_get(self);
773
- GType b = rbgobj_gtype_get(other);
765
+ GType a = rbgobj_gtype_from_ruby(self);
766
+ GType b = rbgobj_gtype_from_ruby(other);
774
767
  return CBOOL2RVAL(g_type_is_a(b, a));
775
768
  }
776
769
  }
@@ -781,8 +774,8 @@ rg_operator_type_lt(VALUE self, VALUE other)
781
774
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
782
775
  return Qnil;
783
776
  else {
784
- GType a = rbgobj_gtype_get(self);
785
- GType b = rbgobj_gtype_get(other);
777
+ GType a = rbgobj_gtype_from_ruby(self);
778
+ GType b = rbgobj_gtype_from_ruby(other);
786
779
  return CBOOL2RVAL(g_type_is_a(a, b) && a != b);
787
780
  }
788
781
  }
@@ -793,8 +786,8 @@ rg_operator_type_gt(VALUE self, VALUE other)
793
786
  if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
794
787
  return Qnil;
795
788
  else {
796
- GType a = rbgobj_gtype_get(self);
797
- GType b = rbgobj_gtype_get(other);
789
+ GType a = rbgobj_gtype_from_ruby(self);
790
+ GType b = rbgobj_gtype_from_ruby(other);
798
791
  return CBOOL2RVAL(g_type_is_a(b, a) && a != b);
799
792
  }
800
793
  }
@@ -808,112 +801,113 @@ rg_hash(VALUE self)
808
801
  static VALUE
809
802
  rg_to_class(VALUE self)
810
803
  {
811
- return GTYPE2CLASS(rbgobj_gtype_get(self));
804
+ return GTYPE2CLASS(rbgobj_gtype_from_ruby(self));
812
805
  }
813
806
 
814
807
  static VALUE
815
808
  rg_fundamental(VALUE self)
816
809
  {
817
- return rbgobj_gtype_new(G_TYPE_FUNDAMENTAL(rbgobj_gtype_get(self)));
810
+ return rbgobj_gtype_new(G_TYPE_FUNDAMENTAL(rbgobj_gtype_from_ruby(self)));
818
811
  }
819
812
 
820
813
  static VALUE
821
814
  rg_fundamental_p(VALUE self)
822
815
  {
823
- return CBOOL2RVAL(G_TYPE_IS_FUNDAMENTAL(rbgobj_gtype_get(self)));
816
+ return CBOOL2RVAL(G_TYPE_IS_FUNDAMENTAL(rbgobj_gtype_from_ruby(self)));
824
817
  }
825
818
 
826
819
  static VALUE
827
820
  rg_derived_p(VALUE self)
828
821
  {
829
- return CBOOL2RVAL(G_TYPE_IS_DERIVED(rbgobj_gtype_get(self)));
822
+ return CBOOL2RVAL(G_TYPE_IS_DERIVED(rbgobj_gtype_from_ruby(self)));
830
823
  }
831
824
 
832
825
  static VALUE
833
826
  rg_interface_p(VALUE self)
834
827
  {
835
- return CBOOL2RVAL(G_TYPE_IS_INTERFACE(rbgobj_gtype_get(self)));
828
+ return CBOOL2RVAL(G_TYPE_IS_INTERFACE(rbgobj_gtype_from_ruby(self)));
836
829
  }
837
830
 
838
831
  static VALUE
839
832
  rg_classed_p(VALUE self)
840
833
  {
841
- return CBOOL2RVAL(G_TYPE_IS_CLASSED(rbgobj_gtype_get(self)));
834
+ return CBOOL2RVAL(G_TYPE_IS_CLASSED(rbgobj_gtype_from_ruby(self)));
842
835
  }
843
836
 
844
837
  static VALUE
845
838
  rg_instantiatable_p(VALUE self)
846
839
  {
847
- return CBOOL2RVAL(G_TYPE_IS_INSTANTIATABLE(rbgobj_gtype_get(self)));
840
+ return CBOOL2RVAL(G_TYPE_IS_INSTANTIATABLE(rbgobj_gtype_from_ruby(self)));
848
841
  }
849
842
 
850
843
  static VALUE
851
844
  rg_derivable_p(VALUE self)
852
845
  {
853
- return CBOOL2RVAL(G_TYPE_IS_DERIVABLE(rbgobj_gtype_get(self)));
846
+ return CBOOL2RVAL(G_TYPE_IS_DERIVABLE(rbgobj_gtype_from_ruby(self)));
854
847
  }
855
848
 
856
849
  static VALUE
857
850
  rg_deep_derivable_p(VALUE self)
858
851
  {
859
- return CBOOL2RVAL(G_TYPE_IS_DEEP_DERIVABLE(rbgobj_gtype_get(self)));
852
+ return CBOOL2RVAL(G_TYPE_IS_DEEP_DERIVABLE(rbgobj_gtype_from_ruby(self)));
860
853
  }
861
854
 
862
855
  static VALUE
863
856
  rg_abstract_p(VALUE self)
864
857
  {
865
- return CBOOL2RVAL(G_TYPE_IS_ABSTRACT(rbgobj_gtype_get(self)));
858
+ return CBOOL2RVAL(G_TYPE_IS_ABSTRACT(rbgobj_gtype_from_ruby(self)));
866
859
  }
867
860
 
868
861
  static VALUE
869
862
  rg_value_abstract_p(VALUE self)
870
863
  {
871
- return CBOOL2RVAL(G_TYPE_IS_VALUE_ABSTRACT(rbgobj_gtype_get(self)));
864
+ return CBOOL2RVAL(G_TYPE_IS_VALUE_ABSTRACT(rbgobj_gtype_from_ruby(self)));
872
865
  }
873
866
 
874
867
  static VALUE
875
868
  rg_value_type_p(VALUE self)
876
869
  {
877
- return CBOOL2RVAL(G_TYPE_IS_VALUE_TYPE(rbgobj_gtype_get(self)));
870
+ return CBOOL2RVAL(G_TYPE_IS_VALUE_TYPE(rbgobj_gtype_from_ruby(self)));
878
871
  }
879
872
 
880
873
  static VALUE
881
874
  rg_has_value_table(VALUE self)
882
875
  {
883
- return CBOOL2RVAL(G_TYPE_HAS_VALUE_TABLE(rbgobj_gtype_get(self)));
876
+ return CBOOL2RVAL(G_TYPE_HAS_VALUE_TABLE(rbgobj_gtype_from_ruby(self)));
884
877
  }
885
878
 
886
879
  static VALUE
887
880
  rg_name(VALUE self)
888
881
  {
889
- return rb_str_new2(g_type_name(rbgobj_gtype_get(self)));
882
+ return rb_str_new2(g_type_name(rbgobj_gtype_from_ruby(self)));
890
883
  }
891
884
 
892
885
  static VALUE
893
886
  rg_parent(VALUE self)
894
887
  {
895
- GType parent = g_type_parent(rbgobj_gtype_get(self));
888
+ GType parent = g_type_parent(rbgobj_gtype_from_ruby(self));
896
889
  return parent ? rbgobj_gtype_new(parent) : Qnil;
897
890
  }
898
891
 
899
892
  static VALUE
900
893
  rg_depth(VALUE self)
901
894
  {
902
- return UINT2NUM(g_type_depth(rbgobj_gtype_get(self)));
895
+ return UINT2NUM(g_type_depth(rbgobj_gtype_from_ruby(self)));
903
896
  }
904
897
 
905
898
  static VALUE
906
899
  rg_next_base(VALUE leaf_type, VALUE root_type)
907
900
  {
908
- GType ret = g_type_next_base(rbgobj_gtype_get(leaf_type),
909
- rbgobj_gtype_get(root_type));
901
+ GType ret = g_type_next_base(rbgobj_gtype_from_ruby(leaf_type),
902
+ rbgobj_gtype_from_ruby(root_type));
910
903
  return ret ? rbgobj_gtype_new(ret) : Qnil;
911
904
  }
912
905
 
913
906
  static VALUE
914
907
  rg_type_is_a_p(VALUE self, VALUE is_a_type)
915
908
  {
916
- return CBOOL2RVAL(g_type_is_a(rbgobj_gtype_get(self), rbgobj_gtype_get(is_a_type)));
909
+ return CBOOL2RVAL(g_type_is_a(rbgobj_gtype_from_ruby(self),
910
+ rbgobj_gtype_from_ruby(is_a_type)));
917
911
  }
918
912
 
919
913
  #if 0
@@ -934,7 +928,7 @@ rg_children(VALUE self)
934
928
  VALUE result;
935
929
  guint i;
936
930
 
937
- types = g_type_children(rbgobj_gtype_get(self), &n_children);
931
+ types = g_type_children(rbgobj_gtype_from_ruby(self), &n_children);
938
932
  result = rb_ary_new2(n_children);
939
933
  for (i = 0; i < n_children; i++)
940
934
  rb_ary_store(result, i, rbgobj_gtype_new(types[i]));
@@ -951,7 +945,7 @@ rg_interfaces(VALUE self)
951
945
  VALUE result;
952
946
  guint i;
953
947
 
954
- types = g_type_interfaces(rbgobj_gtype_get(self), &n_interfaces);
948
+ types = g_type_interfaces(rbgobj_gtype_from_ruby(self), &n_interfaces);
955
949
  result = rb_ary_new2(n_interfaces);
956
950
  for (i = 0; i < n_interfaces; i++)
957
951
  rb_ary_store(result, i, rbgobj_gtype_new(types[i]));
@@ -964,7 +958,7 @@ static VALUE
964
958
  rg_class_size(VALUE self)
965
959
  {
966
960
  GTypeQuery query;
967
- g_type_query(rbgobj_gtype_get(self), &query);
961
+ g_type_query(rbgobj_gtype_from_ruby(self), &query);
968
962
  return UINT2NUM(query.class_size);
969
963
  }
970
964
 
@@ -972,7 +966,7 @@ static VALUE
972
966
  rg_instance_size(VALUE self)
973
967
  {
974
968
  GTypeQuery query;
975
- g_type_query(rbgobj_gtype_get(self), &query);
969
+ g_type_query(rbgobj_gtype_from_ruby(self), &query);
976
970
  return UINT2NUM(query.instance_size);
977
971
  }
978
972
 
@@ -989,10 +983,6 @@ _def_fundamental_type(VALUE ary, GType gtype, const char* name)
989
983
  void
990
984
  Init_gobject_gtype(void)
991
985
  {
992
- #if !GLIB_CHECK_VERSION(2, 35, 1)
993
- g_type_init();
994
- #endif
995
-
996
986
  init_typemap();
997
987
 
998
988
  /* type */