glib2 3.4.9 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/ext/glib2/extconf.rb +4 -3
  3. data/ext/glib2/glib2.def +5 -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 +79 -5
  8. data/ext/glib2/rbglib.c +30 -1
  9. data/ext/glib2/rbglib.h +17 -4
  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 +26 -18
  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 +2 -2
  45. data/ext/glib2/rbgobj_closure.c +55 -85
  46. data/ext/glib2/rbgobj_enums.c +4 -3
  47. data/ext/glib2/rbgobj_flags.c +2 -2
  48. data/ext/glib2/rbgobj_object.c +33 -6
  49. data/ext/glib2/rbgobj_param.c +2 -2
  50. data/ext/glib2/rbgobj_signal.c +37 -19
  51. data/ext/glib2/rbgobj_type.c +3 -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 +21 -2
  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 +11 -4
  61. data/ext/glib2/rbgutil.c +20 -1
  62. data/ext/glib2/rbgutil.h +6 -2
  63. data/ext/glib2/rbgutil_callback.c +14 -8
  64. data/lib/glib2/date-time.rb +35 -0
  65. data/lib/glib2/variant.rb +25 -0
  66. data/lib/glib2.rb +29 -2
  67. data/lib/mkmf-gnome.rb +5 -4
  68. data/test/glib-test-utils.rb +6 -2
  69. data/test/test-date-time.rb +14 -2
  70. data/test/test-glib2.rb +21 -9
  71. data/test/test-spawn.rb +3 -1
  72. data/test/test-variant.rb +44 -1
  73. metadata +8 -8
  74. data/ext/glib2/glib-enum-types.c +0 -1233
  75. data/ext/glib2/glib-enum-types.h +0 -154
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c89356959f6eaabab6237b23ed3e3820a0590869d2390ba5d6c6063aafe36fcb
4
- data.tar.gz: 07b367f72d3fe0cda25c855309a960f4d82367b98e2c92bdfe15cfea8dc2060f
3
+ metadata.gz: 3ffe632b39b4bf1a97a57a079224989e6a2e7c83f09b4a6a3d27806fd95f541f
4
+ data.tar.gz: 0dd688a0ce0b2dbb4df08c4a4c282245683a8f2cbea27d55b7f2833ae029c550
5
5
  SHA512:
6
- metadata.gz: 6ba67d05ed39fd2a1e8fa4f4ca4132b67670a1437469479a4904fce4783c73ab0353100bb9ddb416f250881070a68019058c4c1c7b429af959fa05e12e0a1fa1
7
- data.tar.gz: d87db1a676ee3c60e0855c29c567222524a9d14ee788a70af341866dff199ab46f8dfc58ca51c5b8612474df23ea2ad86bf6ec70950804898c88b2268bcde122
6
+ metadata.gz: edb56979dce1a887f979d32b1a86830ea1a57aee20b9cc68fb1e31b5b8f437ba8f4734601c1a810cea3d3fa09e4e90ad0bc997a3b035bade74ee22c6343675fd
7
+ data.tar.gz: 46d9ddd70c9edd57e4af6bdaf336817b47eb5a2f3371e53af5f2f08f8853fb24790bf547920aa1a1df11cbb30cefaa10d36f727302b4b1c9bed1702d34b7c550
data/ext/glib2/extconf.rb CHANGED
@@ -28,12 +28,13 @@ require "mkmf-gnome"
28
28
 
29
29
  unless required_pkg_config_package([package_id, 2, 12, 0],
30
30
  :alt_linux => "glib2-devel",
31
- :debian => "libglib2.0-dev",
32
- :redhat => "pkgconfig(#{package_id})",
33
31
  :arch_linux => "glib2",
32
+ :debian => "libglib2.0-dev",
33
+ :gentoo_linux => "dev-libs/glib",
34
34
  :homebrew => "glib",
35
35
  :macports => "glib2",
36
- :msys2 => "glib2")
36
+ :msys2 => "glib2",
37
+ :redhat => "pkgconfig(#{package_id})")
37
38
  exit(false)
38
39
  end
39
40
  PKGConfig.have_package('gthread-2.0')
data/ext/glib2/glib2.def CHANGED
@@ -76,11 +76,14 @@ EXPORTS
76
76
  g_rclosure_new
77
77
  g_rclosure_new_call
78
78
  g_rclosure_attach
79
+ g_rclosure_attach_gobject
79
80
  g_rclosure_set_tag
80
81
  rbgobj_ruby_value_get_type
81
82
  g_value_get_ruby_value
82
83
  g_value_set_ruby_value
83
84
  g_key_file_get_type
85
+ rbg_mGLib
86
+ rbg_cGLibObject
84
87
  rbg_rval_inspect
85
88
  rbg_string_value_ptr
86
89
  rbg_rval2cstr
@@ -127,6 +130,7 @@ EXPORTS
127
130
  rbg_rval2glist
128
131
  rbg_rval2gslist
129
132
  rbg_define_method
133
+ rbg_define_private_method
130
134
  rbg_define_singleton_method
131
135
  rbg_to_array
132
136
  rbg_to_hash
@@ -153,6 +157,7 @@ EXPORTS
153
157
  rbgutil_glibid_r2g_func
154
158
  rbgutil_sym_g2r_func
155
159
  rbgutil_protect
160
+ rbgutil_on_callback_error
156
161
  rbgutil_invoke_callback
157
162
  rbgutil_start_callback_dispatch_thread
158
163
  rbgutil_stop_callback_dispatch_thread
@@ -122,7 +122,7 @@ rg_pointer(VALUE self)
122
122
  void
123
123
  Init_glib_bytes(void)
124
124
  {
125
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BYTES, "Bytes", mGLib);
125
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BYTES, "Bytes", rbg_mGLib());
126
126
 
127
127
  RG_DEF_SMETHOD(try_convert, 1);
128
128
 
@@ -191,7 +191,7 @@ void
191
191
  Init_glib_gc(void)
192
192
  {
193
193
  VALUE gc_marker = rbg_gc_marker_new_raw();
194
- rb_ivar_set(mGLib, rb_intern("gc_marker"), gc_marker);
194
+ rb_ivar_set(rbg_mGLib(), rb_intern("gc_marker"), gc_marker);
195
195
  TypedData_Get_Struct(gc_marker,
196
196
  RBGGCMarker,
197
197
  &rbg_gc_marker_type,
@@ -234,7 +234,7 @@ rg_element(VALUE self)
234
234
  void
235
235
  Init_glib_variant_type(void)
236
236
  {
237
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_VARIANT_TYPE, "VariantType", mGLib);
237
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_VARIANT_TYPE, "VariantType", rbg_mGLib());
238
238
 
239
239
  RG_DEF_SMETHOD_P(valid, 1);
240
240
  RG_DEF_SMETHOD(scan, 1);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2015-2021 Ruby-GNOME Project Team
3
+ * Copyright (C) 2015-2022 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
@@ -69,9 +69,10 @@ rbg_variant_to_ruby(GVariant *variant)
69
69
  VALUE value = rbg_variant_to_ruby(val);
70
70
  g_variant_unref(val);
71
71
  return value;
72
- } else if (g_variant_type_is_array(type)) {
72
+ } else if (g_variant_type_is_array(type) ||
73
+ g_variant_type_is_tuple(type)) {
73
74
  gsize i, len = g_variant_n_children(variant);
74
- VALUE ary = rb_ary_new2(len);
75
+ VALUE ary = rb_ary_new_capa(len);
75
76
  for (i = 0; i < len; i++) {
76
77
  GVariant *val = g_variant_get_child_value(variant, i);
77
78
  rb_ary_store(ary, i, rbg_variant_to_ruby(val));
@@ -106,10 +107,53 @@ rg_variant_free(gpointer object)
106
107
  g_variant_unref(variant);
107
108
  }
108
109
 
110
+ static const rb_data_type_t rbg_variant_type = {
111
+ "GLib::Variant",
112
+ {
113
+ NULL,
114
+ rg_variant_free,
115
+ },
116
+ NULL,
117
+ NULL,
118
+ RUBY_TYPED_FREE_IMMEDIATELY,
119
+ };
120
+
109
121
  static VALUE
110
122
  rg_variant_allocate(VALUE klass)
111
123
  {
112
- return Data_Wrap_Struct(klass, NULL, rg_variant_free, NULL);
124
+ return TypedData_Wrap_Struct(klass, &rbg_variant_type, NULL);
125
+ }
126
+
127
+ static VALUE
128
+ rg_s_parse(int argc, VALUE *argv, VALUE klass)
129
+ {
130
+ VALUE rb_text;
131
+ VALUE rb_variant_type;
132
+ rb_scan_args(argc, argv, "11", &rb_text, &rb_variant_type);
133
+ const gchar *text = RVAL2CSTR(rb_text);
134
+ const gchar *limit = text + RSTRING_LEN(rb_text);
135
+ const GVariantType *variant_type = NULL;
136
+ if (!NIL_P(rb_variant_type)) {
137
+ variant_type = RVAL2GVARIANTTYPE(rb_variant_type);
138
+ }
139
+ GError *error = NULL;
140
+ GVariant *variant = g_variant_parse(variant_type,
141
+ text,
142
+ limit,
143
+ NULL,
144
+ &error);
145
+ if (error) {
146
+ GError *detailed_error = NULL;
147
+ gchar *context = g_variant_parse_error_print_context(error, text);
148
+ g_set_error_literal(&detailed_error,
149
+ error->domain,
150
+ error->code,
151
+ context);
152
+ g_free(context);
153
+ g_error_free(error);
154
+ RG_RAISE_ERROR(detailed_error);
155
+ }
156
+ return TypedData_Wrap_Struct(klass, &rbg_variant_type, variant);
113
157
  }
114
158
 
115
159
  static GVariant *
@@ -282,14 +326,44 @@ rg_type(VALUE self)
282
326
  return GVARIANTTYPE2RVAL((GVariantType *)g_variant_get_type(variant));
283
327
  }
284
328
 
329
+ static VALUE
330
+ rg_to_s(int argc, VALUE *argv, VALUE self)
331
+ {
332
+ VALUE options = Qnil;
333
+ gboolean type_annotate = false;
334
+ rb_scan_args(argc, argv, ":", &options);
335
+ if (!NIL_P(options)) {
336
+ ID keywords[1];
337
+ VALUE values[1];
338
+ keywords[0] = rb_intern("type_annotate");
339
+ rb_get_kwargs(options, keywords, 0, 1, values);
340
+ if (values[0] != Qundef) {
341
+ type_annotate = CBOOL2RVAL(values[0]);
342
+ }
343
+ }
344
+
345
+ GVariant *variant = _SELF(self);
346
+ gchar *string = g_variant_print(variant, type_annotate);
347
+ return CSTR2RVAL_FREE(string);
348
+ }
349
+
285
350
  void
286
351
  Init_glib_variant(void)
287
352
  {
288
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_VARIANT, "Variant", mGLib);
353
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_VARIANT, "Variant", rbg_mGLib());
289
354
 
290
355
  rb_define_alloc_func(RG_TARGET_NAMESPACE, rg_variant_allocate);
291
356
 
357
+ RG_DEF_SMETHOD(parse, -1);
358
+
292
359
  RG_DEF_METHOD(initialize, -1);
293
360
  RG_DEF_METHOD(value, 0);
294
361
  RG_DEF_METHOD(type, 0);
362
+ RG_DEF_METHOD(to_s, -1);
363
+
364
+ G_DEF_ERROR(G_VARIANT_PARSE_ERROR,
365
+ "VariantParseError",
366
+ rbg_mGLib(),
367
+ rb_eRuntimeError,
368
+ G_TYPE_VARIANT_PARSE_ERROR);
295
369
  }
data/ext/glib2/rbglib.c CHANGED
@@ -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-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
@@ -29,6 +29,12 @@ static ID id_inspect;
29
29
 
30
30
  VALUE RG_TARGET_NAMESPACE;
31
31
 
32
+ VALUE
33
+ rbg_mGLib(void)
34
+ {
35
+ return RG_TARGET_NAMESPACE;
36
+ }
37
+
32
38
  const gchar *
33
39
  rbg_rval2cstr(VALUE *str)
34
40
  {
@@ -1067,6 +1073,25 @@ rg_s_os_unix_p(G_GNUC_UNUSED VALUE self)
1067
1073
  #endif
1068
1074
  }
1069
1075
 
1076
+ static VALUE
1077
+ rg_s_malloc(G_GNUC_UNUSED VALUE self, VALUE size)
1078
+ {
1079
+ return POINTER2NUM(g_malloc(NUM2SIZET(size)));
1080
+ }
1081
+
1082
+ static VALUE
1083
+ rg_s_malloc0(G_GNUC_UNUSED VALUE self, VALUE size)
1084
+ {
1085
+ return POINTER2NUM(g_malloc0(NUM2SIZET(size)));
1086
+ }
1087
+
1088
+ static VALUE
1089
+ rg_s_free(G_GNUC_UNUSED VALUE self, VALUE address)
1090
+ {
1091
+ g_free(NUM2POINTER(address));
1092
+ return RUBY_Qnil;
1093
+ }
1094
+
1070
1095
  extern void Init_glib2(void);
1071
1096
 
1072
1097
  void
@@ -1153,6 +1178,10 @@ Init_glib2(void)
1153
1178
  RG_DEF_SMETHOD_P(os_beos, 0);
1154
1179
  RG_DEF_SMETHOD_P(os_unix, 0);
1155
1180
 
1181
+ RG_DEF_SMETHOD(malloc, 1);
1182
+ RG_DEF_SMETHOD(malloc0, 1);
1183
+ RG_DEF_SMETHOD(free, 1);
1184
+
1156
1185
  rb_define_const(RG_TARGET_NAMESPACE, "DIR_SEPARATOR", CSTR2RVAL(G_DIR_SEPARATOR_S));
1157
1186
  rb_define_const(RG_TARGET_NAMESPACE, "SEARCHPATH_SEPARATOR", CSTR2RVAL(G_SEARCHPATH_SEPARATOR_S));
1158
1187
 
data/ext/glib2/rbglib.h CHANGED
@@ -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
@@ -31,9 +31,9 @@
31
31
 
32
32
  G_BEGIN_DECLS
33
33
 
34
- #define RBGLIB_MAJOR_VERSION 3
35
- #define RBGLIB_MINOR_VERSION 4
36
- #define RBGLIB_MICRO_VERSION 9
34
+ #define RBGLIB_MAJOR_VERSION 4
35
+ #define RBGLIB_MINOR_VERSION 0
36
+ #define RBGLIB_MICRO_VERSION 0
37
37
 
38
38
  #ifndef RB_ZALLOC
39
39
  # ifdef ZALLOC
@@ -142,6 +142,14 @@ G_BEGIN_DECLS
142
142
  #define RVAL2POINTER(value) ((gpointer)(value))
143
143
  #define POINTER2RVAL(pointer) ((VALUE)(pointer))
144
144
 
145
+ #if SIZEOF_VOIDP == SIZEOF_LONG
146
+ # define NUM2POINTER(number) ((gpointer)NUM2ULONG(number))
147
+ # define POINTER2NUM(pointer) ULONG2NUM((unsigned long)pointer)
148
+ #else
149
+ # define NUM2POINTER(number) ((gpointer)NUM2ULL(number))
150
+ # define POINTER2NUM(pointer) ULL2NUM((unsigned LONG_LONG)pointer)
151
+ #endif
152
+
145
153
  #define GINTS2RVAL(ary, n) rbg_gints2rval(ary, n)
146
154
  #define GINTS2RVAL_FREE(ary, n) rbg_gints2rval(ary, n)
147
155
 
@@ -165,8 +173,13 @@ G_BEGIN_DECLS
165
173
  # define RUBY_GLIB2_VAR extern
166
174
  #endif
167
175
 
176
+ /* Deprecated. Use rbg_mGLib() instead. */
177
+ G_GNUC_DEPRECATED_FOR(rbg_mGLib())
168
178
  RUBY_GLIB2_VAR VALUE mGLib;
169
179
 
180
+ extern VALUE rbg_mGLib(void);
181
+ extern VALUE rbg_cGLibObject(void);
182
+
170
183
  extern const gchar *rbg_rval_inspect(VALUE object);
171
184
 
172
185
  extern gchar* rbg_string_value_ptr(volatile VALUE* ptr); /* no longer used */
@@ -500,9 +500,10 @@ rg_move_item(VALUE self, VALUE old_uri, VALUE new_uri)
500
500
  void
501
501
  Init_glib_bookmark_file(void)
502
502
  {
503
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BOOKMARK_FILE, "BookmarkFile", mGLib);
503
+ VALUE RG_TARGET_NAMESPACE =
504
+ G_DEF_CLASS(G_TYPE_BOOKMARK_FILE, "BookmarkFile", rbg_mGLib());
504
505
 
505
- G_DEF_ERROR(G_BOOKMARK_FILE_ERROR, "BookmarkFileError", mGLib,
506
+ G_DEF_ERROR(G_BOOKMARK_FILE_ERROR, "BookmarkFileError", rbg_mGLib(),
506
507
  rb_eRuntimeError, G_TYPE_BOOKMARK_FILE_ERROR);
507
508
 
508
509
  RG_DEF_METHOD(initialize, 0);
@@ -23,8 +23,6 @@
23
23
  #include "rbgprivate.h"
24
24
  #include "rbglib.h"
25
25
 
26
- #define RG_TARGET_NAMESPACE mGLib
27
-
28
26
  static VALUE
29
27
  rg_s_convert(G_GNUC_UNUSED VALUE self, VALUE str, VALUE to, VALUE from)
30
28
  {
@@ -171,6 +169,8 @@ rg_s_utf8_validate(G_GNUC_UNUSED VALUE self, VALUE str)
171
169
  void
172
170
  Init_glib_convert(void)
173
171
  {
172
+ VALUE RG_TARGET_NAMESPACE = rbg_mGLib();
173
+
174
174
  VALUE cCharError = G_DEF_ERROR2(G_CONVERT_ERROR, "ConvertError", RG_TARGET_NAMESPACE, rb_eIOError);
175
175
 
176
176
  rb_define_const(cCharError, "NO_CONVERSION", INT2NUM(G_CONVERT_ERROR_NO_CONVERSION));
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2016-2021 Ruby-GNOME Project Team
2
+ * Copyright (C) 2016-2022 Ruby-GNOME Project Team
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -53,7 +53,7 @@ is_timezone(VALUE rb_timezone)
53
53
  {
54
54
  VALUE rb_cTimeZone;
55
55
 
56
- rb_cTimeZone = rb_const_get(mGLib, rb_intern("TimeZone"));
56
+ rb_cTimeZone = rb_const_get(rbg_mGLib(), rb_intern("TimeZone"));
57
57
  return RVAL2CBOOL(rb_obj_is_kind_of(rb_timezone, rb_cTimeZone));
58
58
  }
59
59
 
@@ -230,12 +230,20 @@ rg_format(VALUE self, VALUE rb_format)
230
230
  return CSTR2RVAL(g_date_time_format(_SELF(self), format));
231
231
  }
232
232
 
233
+ #if GLIB_CHECK_VERSION(2, 62, 0)
234
+ static VALUE
235
+ rg_format_iso8601(VALUE self)
236
+ {
237
+ return CSTR2RVAL(g_date_time_format_iso8601(_SELF(self)));
238
+ }
239
+ #endif
240
+
233
241
  void
234
242
  Init_glib_date_time(void)
235
243
  {
236
244
  VALUE RG_TARGET_NAMESPACE;
237
245
 
238
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_DATE_TIME, "DateTime", mGLib);
246
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_DATE_TIME, "DateTime", rbg_mGLib());
239
247
 
240
248
  RG_DEF_SMETHOD(now, -1);
241
249
 
@@ -247,4 +255,7 @@ Init_glib_date_time(void)
247
255
  RG_DEF_METHOD(minute, 0);
248
256
  RG_DEF_METHOD(second, 0);
249
257
  RG_DEF_METHOD(format, 1);
258
+ #if GLIB_CHECK_VERSION(2, 62, 0)
259
+ RG_DEF_METHOD(format_iso8601, 0);
260
+ #endif
250
261
  }
@@ -23,8 +23,13 @@
23
23
  #include <ctype.h>
24
24
 
25
25
  static ID id_code;
26
+ static ID id_CODE;
27
+ static const char *name_CODE = "CODE";
26
28
  static ID id_domain;
27
- static ID id_code_classes;
29
+ static ID id_DOMAIN;
30
+ static const char *name_DOMAIN = "DOMAIN";
31
+ static ID id_CODE_CLASSES;
32
+ static const char *name_CODE_CLASSES = "CODE_CLASSES";
28
33
  static VALUE gerror_table;
29
34
  static VALUE generic_error;
30
35
  static VALUE error_info;
@@ -44,13 +49,9 @@ rbgerr_gerror2exception(GError *error)
44
49
  exception_klass = rb_hash_aref(gerror_table, UINT2NUM(error->domain));
45
50
  if (NIL_P(exception_klass)) {
46
51
  exception_klass = generic_error;
47
- } else {
48
- VALUE code_class = Qnil;
49
- VALUE code_classes;
50
- code_classes = rb_ivar_get(exception_klass, id_code_classes);
51
- if (!NIL_P(code_classes)) {
52
- code_class = rb_hash_aref(code_classes, INT2NUM(error->code));
53
- }
52
+ } else if (rb_const_defined_at(exception_klass, id_CODE_CLASSES)) {
53
+ VALUE code_classes = rb_const_get(exception_klass, id_CODE_CLASSES);
54
+ VALUE code_class = rb_hash_aref(code_classes, INT2NUM(error->code));
54
55
  if (!NIL_P(code_class)) {
55
56
  exception_klass = code_class;
56
57
  }
@@ -111,16 +112,17 @@ rbgerr_define_gerror(GQuark domain, const gchar *name, VALUE module, VALUE paren
111
112
  VALUE code_classes;
112
113
  VALUE rb_domain = rb_str_new_cstr(g_quark_to_string(domain));
113
114
  rbgutil_string_set_utf8_encoding(rb_domain);
115
+ rb_obj_freeze(rb_domain);
114
116
 
115
117
  error_class = rb_define_class_under(module, name, parent);
116
- rb_ivar_set(error_class, id_code, Qnil);
117
- rb_ivar_set(error_class, id_domain, rb_domain);
118
+ rb_define_const(error_class, name_CODE, Qnil);
119
+ rb_define_const(error_class, name_DOMAIN, rb_domain);
118
120
  rb_prepend_module(error_class, error_info);
119
121
 
120
122
  rb_hash_aset(gerror_table, UINT2NUM(domain), error_class);
121
123
 
122
124
  code_classes = rb_hash_new();
123
- rb_ivar_set(error_class, id_code_classes, code_classes);
125
+ rb_define_const(error_class, name_CODE_CLASSES, code_classes);
124
126
 
125
127
  if (gtype != G_TYPE_INVALID) {
126
128
  GEnumClass* gclass = g_type_class_ref(gtype);
@@ -146,14 +148,16 @@ rbgerr_define_gerror(GQuark domain, const gchar *name, VALUE module, VALUE paren
146
148
  code_class_name,
147
149
  error_class);
148
150
  g_free(code_class_name);
149
- rb_ivar_set(code_class, id_code, INT2NUM(entry->value));
150
- rb_ivar_set(code_class, id_domain, rb_domain);
151
+ rb_define_const(code_class, name_CODE, INT2NUM(entry->value));
152
+ rb_define_const(code_class, name_DOMAIN, rb_domain);
151
153
  rb_hash_aset(code_classes, INT2NUM(entry->value), code_class);
152
154
  }
153
155
 
154
156
  g_type_class_unref(gclass);
155
157
  }
156
158
 
159
+ rb_obj_freeze(code_classes);
160
+
157
161
  return error_class;
158
162
  }
159
163
 
@@ -161,8 +165,8 @@ static VALUE
161
165
  rg_initialize(int argc, VALUE *argv, VALUE self)
162
166
  {
163
167
  VALUE klass = rb_obj_class(self);
164
- rb_ivar_set(self, id_code, rb_ivar_get(klass, id_code));
165
- rb_ivar_set(self, id_domain, rb_ivar_get(klass, id_domain));
168
+ rb_ivar_set(self, id_code, rb_const_get(klass, id_CODE));
169
+ rb_ivar_set(self, id_domain, rb_const_get(klass, id_DOMAIN));
166
170
  return rb_call_super(argc, argv);
167
171
  }
168
172
 
@@ -178,18 +182,22 @@ void
178
182
  Init_glib_error(void)
179
183
  {
180
184
  id_code = rb_intern("@code");
185
+ id_CODE = rb_intern(name_CODE);
181
186
  id_domain = rb_intern("@domain");
182
- id_code_classes = rb_intern("@code_classes");
187
+ id_DOMAIN = rb_intern(name_DOMAIN);
188
+ id_CODE_CLASSES = rb_intern(name_CODE_CLASSES);
183
189
  gerror_table = rb_hash_new();
184
190
  rb_global_variable(&gerror_table);
185
191
 
186
192
  #define RG_TARGET_NAMESPACE error_info
187
- error_info = rb_define_module_under(mGLib, "ErrorInfo");
193
+ error_info = rb_define_module_under(rbg_mGLib(), "ErrorInfo");
188
194
  rb_define_attr(error_info, "code", TRUE, FALSE);
189
195
  rb_define_attr(error_info, "domain", TRUE, FALSE);
190
196
  RG_DEF_METHOD(initialize, -1);
191
197
 
192
- generic_error = rb_define_class_under(mGLib, "Error", rb_eRuntimeError);
198
+ generic_error = rb_define_class_under(rbg_mGLib(), "Error", rb_eRuntimeError);
199
+ rb_define_const(generic_error, name_CODE, Qnil);
200
+ rb_define_const(generic_error, name_DOMAIN, Qnil);
193
201
  rb_include_module(generic_error, error_info);
194
202
  }
195
203
 
@@ -71,7 +71,7 @@ rbglib_m_format_size(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
71
71
  void
72
72
  Init_glib_fileutils(void)
73
73
  {
74
- VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_FILE_ERROR, "FileError", mGLib, rb_eIOError);
74
+ VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_FILE_ERROR, "FileError", rbg_mGLib(), rb_eIOError);
75
75
 
76
76
  rb_define_const(RG_TARGET_NAMESPACE, "EXIST", INT2NUM(G_FILE_ERROR_EXIST));
77
77
  rb_define_const(RG_TARGET_NAMESPACE, "ISDIR", INT2NUM(G_FILE_ERROR_ISDIR));
@@ -98,6 +98,6 @@ Init_glib_fileutils(void)
98
98
  rb_define_const(RG_TARGET_NAMESPACE, "PERM", INT2NUM(G_FILE_ERROR_PERM));
99
99
  rb_define_const(RG_TARGET_NAMESPACE, "FAILED", INT2NUM(G_FILE_ERROR_FAILED));
100
100
 
101
- rbg_define_singleton_method(mGLib, "format_size",
101
+ rbg_define_singleton_method(rbg_mGLib(), "format_size",
102
102
  rbglib_m_format_size, -1);
103
103
  }
@@ -43,6 +43,6 @@ Init_glib_gettext(void)
43
43
  {
44
44
  VALUE RG_TARGET_NAMESPACE;
45
45
 
46
- RG_TARGET_NAMESPACE = rb_define_module_under(mGLib, "GetText");
46
+ RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "GetText");
47
47
  RG_DEF_SMETHOD(bindtextdomain, -1);
48
48
  }
@@ -24,8 +24,6 @@
24
24
  #undef _
25
25
  #include <glib/gi18n.h>
26
26
 
27
- #define RG_TARGET_NAMESPACE mGLib
28
-
29
27
  static VALUE
30
28
  rg_s_language_names(G_GNUC_UNUSED VALUE self)
31
29
  {
@@ -35,6 +33,8 @@ rg_s_language_names(G_GNUC_UNUSED VALUE self)
35
33
  void
36
34
  Init_glib_i18n(void)
37
35
  {
36
+ VALUE RG_TARGET_NAMESPACE = rbg_mGLib();
37
+
38
38
  /* glib/gi18n.h */
39
39
  RG_DEF_SMETHOD(language_names, 0);
40
40
  }
@@ -23,7 +23,7 @@
23
23
  void
24
24
  Init_glib_io_constants(void)
25
25
  {
26
- VALUE RG_TARGET_NAMESPACE = mGLib;
26
+ VALUE RG_TARGET_NAMESPACE = rbg_mGLib();
27
27
 
28
28
  /* GIOCondition */
29
29
  G_DEF_CLASS(G_TYPE_IO_CONDITION, "IOCondition", RG_TARGET_NAMESPACE);
@@ -777,7 +777,7 @@ rg_print(int argc, VALUE *argv, VALUE out)
777
777
  void
778
778
  Init_glib_io_channel(void)
779
779
  {
780
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_IO_CHANNEL, "IOChannel", mGLib);
780
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_IO_CHANNEL, "IOChannel", rbg_mGLib());
781
781
 
782
782
  rb_include_module(RG_TARGET_NAMESPACE, rb_mEnumerable);
783
783
 
@@ -851,7 +851,7 @@ Init_glib_io_channel(void)
851
851
  rb_define_const(RG_TARGET_NAMESPACE, "FLAG_GET_MASK", INT2NUM(G_IO_FLAG_GET_MASK));
852
852
  rb_define_const(RG_TARGET_NAMESPACE, "FLAG_SET_MASK", INT2NUM(G_IO_FLAG_SET_MASK));
853
853
 
854
- rb_mIOChannelSource = rb_define_module_under(mGLib, "IOChannelSource");
854
+ rb_mIOChannelSource = rb_define_module_under(rbg_mGLib(), "IOChannelSource");
855
855
  rb_define_method(rb_mIOChannelSource,
856
856
  "set_callback",
857
857
  rg_io_channel_source_set_callback,
@@ -47,9 +47,9 @@ Init_glib_io_channel_win32_socket(void)
47
47
  /* GIOWin32Channel */
48
48
  VALUE RG_TARGET_NAMESPACE;
49
49
  RG_TARGET_NAMESPACE =
50
- rb_define_class_under(mGLib,
50
+ rb_define_class_under(rbg_mGLib(),
51
51
  "IOChannelWin32Socket",
52
- rb_const_get(mGLib, rb_intern("IOChannel")));
52
+ rb_const_get(rbg_mGLib(), rb_intern("IOChannel")));
53
53
  RG_DEF_METHOD(initialize, 1);
54
54
  #endif
55
55
  }
@@ -32,7 +32,7 @@ rg_s_from_errno(G_GNUC_UNUSED VALUE self, VALUE errno_)
32
32
  void
33
33
  Init_glib_io_channelerror(void)
34
34
  {
35
- VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_IO_CHANNEL_ERROR, "IOChannelError", mGLib, rb_eIOError);
35
+ VALUE RG_TARGET_NAMESPACE = G_DEF_ERROR2(G_IO_CHANNEL_ERROR, "IOChannelError", rbg_mGLib(), rb_eIOError);
36
36
 
37
37
  /* GIOChannelError */
38
38
  RG_DEF_SMETHOD(from_errno, 1);
@@ -631,8 +631,8 @@ rg_remove_comment(VALUE self, VALUE group_name, VALUE key)
631
631
  void
632
632
  Init_glib_keyfile(void)
633
633
  {
634
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_KEY_FILE, "KeyFile", mGLib);
635
- G_DEF_ERROR(G_KEY_FILE_ERROR, "KeyFileError", mGLib,
634
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_KEY_FILE, "KeyFile", rbg_mGLib());
635
+ G_DEF_ERROR(G_KEY_FILE_ERROR, "KeyFileError", rbg_mGLib(),
636
636
  rb_eRuntimeError, G_TYPE_KEY_FILE_ERROR);
637
637
 
638
638
  RG_DEF_METHOD(initialize, 0);
@@ -498,11 +498,11 @@ child_watch_add(VALUE self, VALUE pid)
498
498
  void
499
499
  Init_glib_main_context(void)
500
500
  {
501
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MAIN_CONTEXT, "MainContext", mGLib);
501
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MAIN_CONTEXT, "MainContext", rbg_mGLib());
502
502
 
503
- VALUE timeout = rb_define_module_under(mGLib, "Timeout");
504
- VALUE idle = rb_define_module_under(mGLib, "Idle");
505
- VALUE child_watch = rb_define_module_under(mGLib, "ChildWatch");
503
+ VALUE timeout = rb_define_module_under(rbg_mGLib(), "Timeout");
504
+ VALUE idle = rb_define_module_under(rbg_mGLib(), "Idle");
505
+ VALUE child_watch = rb_define_module_under(rbg_mGLib(), "ChildWatch");
506
506
 
507
507
  id_call = rb_intern("call");
508
508
 
@@ -510,10 +510,10 @@ Init_glib_main_context(void)
510
510
 
511
511
  main_thread = g_thread_self();
512
512
 
513
- rbg_define_singleton_method(mGLib, "set_ruby_thread_priority",
513
+ rbg_define_singleton_method(rbg_mGLib(), "set_ruby_thread_priority",
514
514
  ruby_source_set_priority, 1);
515
515
 
516
- mGLibSource = rb_const_get(mGLib, rb_intern("Source"));
516
+ mGLibSource = rb_const_get(rbg_mGLib(), rb_intern("Source"));
517
517
  rbg_define_singleton_method(mGLibSource, "remove", source_remove, 1);
518
518
  rbg_define_singleton_method(mGLibSource, "current", source_current_source, 0);
519
519
  /*
@@ -119,7 +119,7 @@ rg_context(VALUE self)
119
119
  void
120
120
  Init_glib_main_loop(void)
121
121
  {
122
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MAIN_LOOP, "MainLoop", mGLib);
122
+ VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MAIN_LOOP, "MainLoop", rbg_mGLib());
123
123
 
124
124
  RG_DEF_METHOD(initialize, -1);
125
125
  RG_DEF_METHOD(run, 0);
@@ -163,7 +163,7 @@ Init_glib_matchinfo(void)
163
163
  {
164
164
  VALUE RG_TARGET_NAMESPACE;
165
165
 
166
- RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MATCH_INFO, "MatchInfo", mGLib);
166
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_MATCH_INFO, "MatchInfo", rbg_mGLib());
167
167
  RG_DEF_METHOD(regex, 0);
168
168
  RG_DEF_METHOD(string, 0);
169
169
  RG_DEF_METHOD_P(matches, 0);