glib2 3.3.7 → 3.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b942598f5c00a7a244ac39b488f99db909b1366e32ec4aac9a9ceab228eedb39
4
- data.tar.gz: 2492a173ad5a94b094973ea8fa84fc134d5ed18a443fa3f044871f01ef91a975
3
+ metadata.gz: 2bd17bde266ff29b1445dd41b0a33549472b10082d3a33dd566e90200ee16ca1
4
+ data.tar.gz: f8ff9860d9fbe9a600546aaf66332022537f8ad5376712a6bdabc46b92903984
5
5
  SHA512:
6
- metadata.gz: 73912d2b11e3e4d11c1cbbe11c7efdcc34edb6e075e4710e7c738ab10d88d4d29e096d07afa4bd5d768296bc0def3a34a93ebe7cef5c95a49543ab2db1fd83d5
7
- data.tar.gz: 4455e42d37a1cf8112dd9b0ac11e1e4ff5af9a924a4aa1ee19a549646a30a34d328c96b904bcf3d45f5f420879490cad10b69ddf38c58b87efa57905be7a31df
6
+ metadata.gz: b47ecb4c251f0d6d573a25177c313c221563961ef55d89130a67ed1aabad171ec90147434c1c7aee708a448c2df43fd7704af2e95d6d82a48ad7f6b11e1163ed
7
+ data.tar.gz: 83491d543291507cfe2bb44a41689866dc1ae35d987f3fd3b4a8d02f3be33b81e8f2ccfd51a28d124c23dc7c7667848ec1bf5dc2374022ede9eec91256acbca5
data/README.md CHANGED
@@ -4,39 +4,24 @@ Ruby/GLib2 is a Ruby binding of GLib-2.12.x.
4
4
 
5
5
  ## Requirements
6
6
 
7
- Ruby >= 1.9.x: http://www.ruby-lang.org/
8
- pkg-config.rb: http://github.com/rcairo/pkg-config
9
- GLib >= 2.12.x: http://www.gtk.org/
7
+ * Ruby >= 1.9.x: https://www.ruby-lang.org/
8
+ * pkg-config.rb: https://github.com/rcairo/pkg-config
9
+ * GLib >= 2.12.x: https://www.gtk.org/
10
10
 
11
- ## Install (RubyGems)
11
+ ## Install
12
12
 
13
- ```
14
- % sudo gem install glib2
15
- ```
16
- Windows:
17
-
18
- ```
19
- > gem install glib2 --platform x86-mingw32
20
- ```
21
-
22
- ## Install (traditional)
23
-
24
- Install ruby-1.9.x or later, pkg-config.rb and GLib-2.12.x.
25
-
26
- ```
27
- % ruby extconf.rb
28
- % make
29
- % sudo make install
13
+ ```bash
14
+ gem install glib2
30
15
  ```
31
16
 
32
17
  ## Copying
33
18
 
34
- Copyright (c) 2002-2010 Ruby-GNOME2 Project Team
19
+ Copyright (c) 2002-2019 Ruby-GNOME Project Team
35
20
 
36
- This program is free software.
37
- You can distribute/modify this program under the terms of
38
- the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
21
+ This program is free software.
22
+ You can distribute/modify this program under the terms of
23
+ the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
39
24
 
40
25
  ## Project Website
41
26
 
42
- https://ruby-gnome2.osdn.jp/
27
+ https://ruby-gnome2.osdn.jp/
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2017 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2017-2019 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
@@ -27,6 +27,26 @@
27
27
  #if GLIB_CHECK_VERSION(2, 32, 0)
28
28
  static VALUE RG_TARGET_NAMESPACE;
29
29
 
30
+ static VALUE
31
+ rg_s_try_convert(VALUE self, VALUE value)
32
+ {
33
+ if (NIL_P(value)) {
34
+ return value;
35
+ }
36
+
37
+ if (RVAL2CBOOL(rb_obj_is_kind_of(value, self))) {
38
+ return value;
39
+ }
40
+
41
+ if (RB_TYPE_P(value, RUBY_T_STRING)) {
42
+ ID id_new;
43
+ CONST_ID(id_new, "new");
44
+ return rb_funcall(self, id_new, 1, value);
45
+ }
46
+
47
+ return Qnil;
48
+ }
49
+
30
50
  static VALUE
31
51
  rg_initialize(int argc, VALUE *argv, VALUE self)
32
52
  {
@@ -37,13 +57,14 @@ rg_initialize(int argc, VALUE *argv, VALUE self)
37
57
  if (NIL_P(rb_data)) {
38
58
  bytes = g_bytes_new(NULL, 0);
39
59
  } else {
40
- const gchar *data = RVAL2CSTR_PTR(rb_data);
41
- if (RB_OBJ_FROZEN(rb_data)) {
42
- bytes = g_bytes_new_static(data, RSTRING_LEN(rb_data));
43
- rb_iv_set(self, "source", rb_data);
44
- } else {
45
- bytes = g_bytes_new(data, RSTRING_LEN(rb_data));
60
+ const gchar *data;
61
+ if (!RB_OBJ_FROZEN(rb_data)) {
62
+ rb_data = rb_str_dup(rb_data);
63
+ rb_str_freeze(rb_data);
46
64
  }
65
+ data = RVAL2CSTR_PTR(rb_data);
66
+ bytes = g_bytes_new_static(data, RSTRING_LEN(rb_data));
67
+ rb_iv_set(self, "source", rb_data);
47
68
  }
48
69
  G_INITIALIZE(self, bytes);
49
70
 
@@ -98,6 +119,8 @@ Init_glib_bytes(void)
98
119
  #if GLIB_CHECK_VERSION(2, 32, 0)
99
120
  RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BYTES, "Bytes", mGLib);
100
121
 
122
+ RG_DEF_SMETHOD(try_convert, 1);
123
+
101
124
  RG_DEF_METHOD(initialize, -1);
102
125
  RG_DEF_METHOD(to_s, 0);
103
126
  RG_DEF_ALIAS("to_str", "to_s");
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2015 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2019 Ruby-GNOME2 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
@@ -220,7 +220,7 @@ rbg_cstr2rval_with_free(gchar *str)
220
220
  return rbg_cstr2rval_free(str);
221
221
  }
222
222
 
223
- static rb_encoding *filename_encoding_if_not_utf8;
223
+ rb_encoding *rbg_filename_encoding;
224
224
 
225
225
  static VALUE
226
226
  rbg_filename_to_ruby_body(VALUE filename)
@@ -234,9 +234,9 @@ rbg_filename_to_ruby_body(VALUE filename)
234
234
 
235
235
  /* if needed, change encoding of Ruby String to filename encoding, so that
236
236
  upcoming File operations will work properly */
237
- return filename_encoding_if_not_utf8 != NULL ?
238
- rb_str_export_to_enc(rb_filename, filename_encoding_if_not_utf8) :
239
- rb_filename;
237
+ return rbg_filename_encoding == rb_utf8_encoding() ?
238
+ rb_filename :
239
+ rb_str_export_to_enc(rb_filename, rbg_filename_encoding);
240
240
  }
241
241
 
242
242
  static VALUE
@@ -257,7 +257,7 @@ rbg_filename_to_ruby(const gchar *filename)
257
257
  if (filename == NULL)
258
258
  return Qnil;
259
259
 
260
- if (filename_encoding_if_not_utf8 == NULL)
260
+ if (rbg_filename_encoding == rb_utf8_encoding())
261
261
  return CSTR2RVAL(filename);
262
262
 
263
263
  filename_utf8 = g_filename_to_utf8(filename, -1, NULL, &written, &error);
@@ -278,15 +278,15 @@ rbg_filename_to_ruby_free(gchar *filename)
278
278
  return Qnil;
279
279
 
280
280
  /* convert filename to UTF-8 if needed */
281
- if (filename_encoding_if_not_utf8 != NULL) {
281
+ if (rbg_filename_encoding == rb_utf8_encoding()) {
282
+ filename_utf8 = filename;
283
+ } else {
282
284
  GError *error = NULL;
283
285
 
284
286
  filename_utf8 = g_filename_to_utf8(filename, -1, NULL, &written, &error);
285
287
  g_free(filename);
286
288
  if (error != NULL)
287
289
  RAISE_GERROR(error);
288
- } else {
289
- filename_utf8 = filename;
290
290
  }
291
291
 
292
292
  return rb_ensure(rbg_filename_to_ruby_body, (VALUE)filename_utf8,
@@ -306,10 +306,14 @@ rbg_filename_from_ruby(VALUE filename)
306
306
  filename = rb_str_export_to_enc(filename, rb_utf8_encoding());
307
307
 
308
308
  /* convert it to filename encoding if needed */
309
- if (filename_encoding_if_not_utf8 == NULL)
310
- return g_strdup(RSTRING_PTR(filename));
311
-
312
- retval = g_filename_from_utf8(RSTRING_PTR(filename), -1, NULL, &written, &error);
309
+ if (rbg_filename_encoding == rb_utf8_encoding())
310
+ return g_strndup(RSTRING_PTR(filename), RSTRING_LEN(filename));
311
+
312
+ retval = g_filename_from_utf8(RSTRING_PTR(filename),
313
+ RSTRING_LEN(filename),
314
+ NULL,
315
+ &written,
316
+ &error);
313
317
  if (error != NULL)
314
318
  RAISE_GERROR(error);
315
319
 
@@ -1097,12 +1101,13 @@ Init_glib2(void)
1097
1101
  || filename_charsets[0] == NULL
1098
1102
  || !strcmp(filename_charsets[0], "UTF-8")
1099
1103
  || rb_enc_find(filename_charsets[0]) == rb_enc_find("ASCII-8BIT")) {
1100
- /* set to NULL, mean do not perform transcoding, either filename
1101
- encoding is unknown, UTF-8, or unsupported */
1102
- filename_encoding_if_not_utf8 = NULL;
1104
+ rbg_filename_encoding = rb_utf8_encoding();
1103
1105
  } else {
1104
- filename_encoding_if_not_utf8 = rb_enc_find(filename_charsets[0]);
1106
+ rbg_filename_encoding = rb_enc_find(filename_charsets[0]);
1105
1107
  }
1108
+ rb_define_const(RG_TARGET_NAMESPACE,
1109
+ "FILENAME_ENCODING",
1110
+ rb_enc_from_encoding(rbg_filename_encoding));
1106
1111
 
1107
1112
  /* Don't implement them.
1108
1113
  #define G_DIR_SEPARATOR_S
@@ -36,7 +36,7 @@ extern "C" {
36
36
 
37
37
  #define RBGLIB_MAJOR_VERSION 3
38
38
  #define RBGLIB_MINOR_VERSION 3
39
- #define RBGLIB_MICRO_VERSION 7
39
+ #define RBGLIB_MICRO_VERSION 8
40
40
 
41
41
  #ifndef RB_ZALLOC
42
42
  # ifdef ZALLOC
@@ -35,12 +35,18 @@ rg_s_convert(G_GNUC_UNUSED VALUE self, VALUE str, VALUE to, VALUE from)
35
35
 
36
36
  StringValue(str);
37
37
  ret = g_convert(RSTRING_PTR(str), RSTRING_LEN(str),
38
- StringValuePtr(to), StringValuePtr(from),
38
+ StringValueCStr(to), StringValueCStr(from),
39
39
  NULL, &written, &err);
40
40
 
41
41
  if (err != NULL)
42
42
  RAISE_GERROR(err);
43
- s = rb_str_new(ret, written);
43
+ {
44
+ rb_encoding *encoding = rb_enc_find(StringValueCStr(to));
45
+ if (!encoding) {
46
+ encoding = rb_ascii8bit_encoding();
47
+ }
48
+ s = rb_enc_str_new(ret, written, encoding);
49
+ }
44
50
  g_free(ret);
45
51
  return s;
46
52
  }
@@ -110,7 +116,7 @@ rg_s_filename_from_utf8(G_GNUC_UNUSED VALUE self, VALUE str)
110
116
 
111
117
  if (err != NULL)
112
118
  RAISE_GERROR(err);
113
- s = rb_str_new(ret, written);
119
+ s = rb_enc_str_new(ret, written, rbg_filename_encoding);
114
120
  g_free(ret);
115
121
  return s;
116
122
  }
@@ -1,7 +1,7 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2019 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2004-2006 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2019 Ruby-GNOME Project Team
4
+ * Copyright (C) 2004-2006 Ruby-GNOME Project Team
5
5
  * Copyright (C) 2002,2003 Masahiro Sakai
6
6
  *
7
7
  * This library is free software; you can redistribute it and/or
@@ -27,9 +27,11 @@
27
27
 
28
28
  VALUE RG_TARGET_NAMESPACE;
29
29
 
30
+ static ID id_find;
30
31
  static ID id_new;
31
- static ID id_to_s;
32
32
  static ID id_to_i;
33
+ static ID id_to_s;
34
+ static ID id_values;
33
35
 
34
36
  /**********************************************************************/
35
37
 
@@ -55,31 +57,20 @@ nick_to_const_name(const gchar *nick)
55
57
  VALUE
56
58
  rg_enum_resolve_value(VALUE klass, VALUE nick)
57
59
  {
58
- VALUE value = Qnil;
59
- gchar *const_nick;
60
- ID const_nick_id;
61
-
62
60
  if (RVAL2CBOOL(rb_obj_is_kind_of(nick, klass)))
63
61
  return nick;
64
-
65
- nick = rb_funcall(nick, id_to_s, 0);
66
- const_nick = nick_to_const_name(RVAL2CSTR(nick));
67
- const_nick_id = rb_intern(const_nick);
68
- if (rb_const_defined(klass, const_nick_id)) {
69
- value = rb_const_get(klass, const_nick_id);
70
- }
71
- g_free(const_nick);
72
-
73
- return value;
62
+ return rb_funcall(klass, id_find, 1, nick);
74
63
  }
75
64
 
76
65
  void
77
66
  rg_enum_add_constants(VALUE mod, GType enum_type, const gchar *strip_prefix)
78
67
  {
68
+ VALUE klass;
79
69
  GEnumClass *gclass;
80
70
  guint i;
81
71
  size_t prefix_len = strlen(strip_prefix);
82
72
 
73
+ klass = GTYPE2CLASS(enum_type);
83
74
  gclass = G_ENUM_CLASS(g_type_class_ref(enum_type));
84
75
 
85
76
  for (i = 0; i < gclass->n_values; i++) {
@@ -90,8 +81,9 @@ rg_enum_add_constants(VALUE mod, GType enum_type, const gchar *strip_prefix)
90
81
  value->value_name, strip_prefix);
91
82
  } else {
92
83
  const char* name = value->value_name + prefix_len;
93
- rbgobj_define_const(mod, name,
94
- rbgobj_make_enum(value->value, enum_type));
84
+ rbgobj_define_const(mod,
85
+ name,
86
+ rb_funcall(klass, id_find, 1, INT2NUM(value->value)));
95
87
  }
96
88
  }
97
89
 
@@ -135,16 +127,20 @@ enum_get_holder(VALUE rb_enum)
135
127
  return holder;
136
128
  }
137
129
 
138
- static VALUE
139
- make_enum(gint n, VALUE klass)
140
- {
141
- return rb_funcall(klass, id_new, 1, INT2NUM(n));
142
- }
143
-
144
130
  VALUE
145
131
  rbgobj_make_enum(gint n, GType gtype)
146
132
  {
147
- return make_enum(n, GTYPE2CLASS(gtype));
133
+ VALUE klass = GTYPE2CLASS(gtype);
134
+ VALUE enum_value;
135
+
136
+ enum_value = rb_funcall(klass, id_find, 1, INT2NUM(n));
137
+ if (NIL_P(enum_value)) {
138
+ enum_value = rb_funcall(klass,
139
+ id_new,
140
+ 1,
141
+ INT2NUM(n));
142
+ }
143
+ return enum_value;
148
144
  }
149
145
 
150
146
  gint
@@ -184,36 +180,25 @@ void
184
180
  rbgobj_init_enum_class(VALUE klass)
185
181
  {
186
182
  GEnumClass* gclass = g_type_class_ref(CLASS2GTYPE(klass));
183
+ VALUE values;
187
184
  guint i;
188
185
 
186
+ values = rb_hash_new();
187
+ rb_iv_set(klass, "values", values);
189
188
  for (i = 0; i < gclass->n_values; i++) {
190
189
  GEnumValue* entry = &(gclass->values[i]);
190
+ VALUE rb_raw_enum_value;
191
+ VALUE value;
191
192
  gchar *const_nick_name;
192
193
 
194
+ rb_raw_enum_value = INT2NUM(entry->value);
195
+ value = rb_funcall(klass, id_new, 1, rb_raw_enum_value);
196
+ rb_hash_aset(values, rb_raw_enum_value, value);
193
197
  const_nick_name = nick_to_const_name(entry->value_nick);
194
-
195
- #if 0
196
- {
197
- ID id = rb_intern(const_nick_name);
198
- if (rb_is_const_id(id)) {
199
- VALUE value;
200
-
201
- value = make_enum(entry->value, klass);
202
- rb_define_const(klass, const_nick_name, value);
203
- }
198
+ if (const_nick_name) {
199
+ rbgobj_define_const(klass, const_nick_name, value);
200
+ g_free(const_nick_name);
204
201
  }
205
- #else
206
- {
207
- if (const_nick_name) {
208
- VALUE value;
209
-
210
- value = make_enum(entry->value, klass);
211
- rbgobj_define_const(klass, const_nick_name, value);
212
- }
213
- }
214
- #endif
215
-
216
- g_free(const_nick_name);
217
202
  }
218
203
 
219
204
  g_type_class_unref(gclass);
@@ -230,42 +215,32 @@ rg_s_range(VALUE self)
230
215
  return result;
231
216
  }
232
217
 
233
- struct enum_s_values_body_args {
234
- GEnumClass *gclass;
235
- VALUE self;
236
- };
237
-
238
- static VALUE
239
- enum_s_values_body(VALUE value)
240
- {
241
- struct enum_s_values_body_args *args = (struct enum_s_values_body_args *)value;
242
- VALUE result = rb_ary_new();
243
- guint i;
244
-
245
- for (i = 0; i < args->gclass->n_values; i++)
246
- rb_ary_push(result, make_enum(args->gclass->values[i].value, args->self));
247
-
248
- return result;
249
- }
250
-
251
218
  static VALUE
252
- enum_s_values_ensure(VALUE gclass)
219
+ rg_s_values(VALUE self)
253
220
  {
254
- g_type_class_unref((GEnumClass *)gclass);
255
-
256
- return Qnil;
221
+ VALUE values = rb_iv_get(self, "values");
222
+ return rb_funcall(values, id_values, 0);
257
223
  }
258
224
 
259
225
  static VALUE
260
- rg_s_values(VALUE self)
226
+ rg_s_find(VALUE self, VALUE key)
261
227
  {
262
- struct enum_s_values_body_args args = {
263
- g_type_class_ref(CLASS2GTYPE(self)),
264
- self
265
- };
266
-
267
- return rb_ensure(enum_s_values_body, (VALUE)&args,
268
- enum_s_values_ensure, (VALUE)args.gclass);
228
+ if (RB_TYPE_P(key, RUBY_T_FIXNUM)) {
229
+ VALUE values = rb_iv_get(self, "values");
230
+ return rb_hash_aref(values, key);
231
+ } else if (RB_TYPE_P(key, RUBY_T_STRING) || RB_TYPE_P(key, RUBY_T_SYMBOL)) {
232
+ VALUE nick = rb_funcall(key, id_to_s, 0);
233
+ gchar *const_nick = nick_to_const_name(RVAL2CSTR(nick));
234
+ ID const_nick_id = rb_intern(const_nick);
235
+ g_free(const_nick);
236
+ if (rb_const_defined(self, const_nick_id)) {
237
+ return rb_const_get(self, const_nick_id);
238
+ } else {
239
+ return Qnil;
240
+ }
241
+ } else {
242
+ return Qnil;
243
+ }
269
244
  }
270
245
 
271
246
  VALUE
@@ -433,9 +408,11 @@ rg_coerce(VALUE self, VALUE other)
433
408
  void
434
409
  Init_gobject_genums(void)
435
410
  {
411
+ id_find = rb_intern("find");
436
412
  id_new = rb_intern("new");
437
- id_to_s = rb_intern("to_s");
438
413
  id_to_i = rb_intern("to_i");
414
+ id_to_s = rb_intern("to_s");
415
+ id_values = rb_intern("values");
439
416
 
440
417
  RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_ENUM, "Enum", mGLib);
441
418
 
@@ -444,6 +421,7 @@ Init_gobject_genums(void)
444
421
 
445
422
  RG_DEF_SMETHOD(range, 0);
446
423
  RG_DEF_SMETHOD(values, 0);
424
+ RG_DEF_SMETHOD(find, 1);
447
425
 
448
426
  rb_define_alloc_func(RG_TARGET_NAMESPACE, rbgobj_enum_alloc_func);
449
427
 
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2018 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2002-2019 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
@@ -377,7 +377,7 @@ rbgobj_class_info_lookup(VALUE klass)
377
377
  if (TYPE(klass) == T_CLASS) {
378
378
  VALUE super;
379
379
  super = rb_funcall(klass, id_superclass, 0);
380
- return rbgobj_lookup_class(super);
380
+ return rbgobj_class_info_lookup(super);
381
381
  }
382
382
 
383
383
  rb_raise(rb_eRuntimeError, "can't get gobject class information");
@@ -605,6 +605,61 @@ rbgobj_gtype_get(VALUE self)
605
605
  rb_raise(rb_eTypeError, "Not a GLib::Type");
606
606
  }
607
607
 
608
+ static VALUE
609
+ rg_s_try_convert(VALUE self, VALUE value)
610
+ {
611
+ ID id_new;
612
+ CONST_ID(id_new, "new");
613
+
614
+ if (NIL_P(value))
615
+ return Qnil;
616
+
617
+ if (RVAL2CBOOL(rb_obj_is_kind_of(value, RG_TARGET_NAMESPACE)))
618
+ return value;
619
+
620
+ if (RVAL2CBOOL(rb_obj_is_kind_of(value, rb_cInteger))) {
621
+ GType gtype = NUM2ULONG(value);
622
+ if (!g_type_name(gtype))
623
+ return Qnil;
624
+ return rb_funcall(self, id_new, 1, value);
625
+ }
626
+
627
+ if (RB_TYPE_P(value, RUBY_T_SYMBOL)) {
628
+ value = rb_sym2str(value);
629
+ }
630
+
631
+ if (RB_TYPE_P(value, RUBY_T_STRING)) {
632
+ GType gtype = g_type_from_name(RVAL2CSTR(value));
633
+ if (gtype == G_TYPE_INVALID) {
634
+ return Qnil;
635
+ }
636
+ return rb_funcall(self, id_new, 1, value);
637
+ }
638
+
639
+ if (RVAL2CBOOL(rb_obj_is_kind_of(value, rb_cClass))) {
640
+ for (; !NIL_P(value); value = rb_funcall(value, id_superclass, 0)) {
641
+ RGObjClassInfo *cinfo;
642
+ VALUE data = rb_hash_aref(klass_to_cinfo, value);
643
+
644
+ if (NIL_P(data))
645
+ continue;
646
+
647
+ if (RTYPEDDATA_P(data)) {
648
+ TypedData_Get_Struct(data,
649
+ RGObjClassInfo,
650
+ RTYPEDDATA_TYPE(data),
651
+ cinfo);
652
+ } else {
653
+ Data_Get_Struct(data, RGObjClassInfo, cinfo);
654
+ }
655
+ return rb_funcall(self, id_new, 1, ULONG2NUM(cinfo->gtype));
656
+ }
657
+ return Qnil;
658
+ }
659
+
660
+ return Qnil;
661
+ }
662
+
608
663
  static VALUE
609
664
  rg_initialize(VALUE self, VALUE type)
610
665
  {
@@ -930,6 +985,8 @@ Init_gobject_gtype(void)
930
985
 
931
986
  RG_TARGET_NAMESPACE = rb_define_class_under(mGLib, "Type", rb_cObject);
932
987
 
988
+ RG_DEF_SMETHOD(try_convert, 1);
989
+
933
990
  rb_define_alias(CLASS_OF(RG_TARGET_NAMESPACE), "[]", "new");
934
991
  RG_DEF_METHOD(initialize, 1);
935
992
  RG_DEF_METHOD(inspect, 0);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2007-2018 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2007-2019 Ruby-GNOME2 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
@@ -60,6 +60,7 @@ typedef struct {
60
60
  } boxed_holder;
61
61
 
62
62
  G_GNUC_INTERNAL extern GStaticPrivate rg_polling_key;
63
+ G_GNUC_INTERNAL extern rb_encoding *rbg_filename_encoding;
63
64
 
64
65
  extern VALUE rbgobj_cEnum;
65
66
  extern VALUE rbgobj_cFlags;
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2018-2019 Ruby-GNOME2 Project Team
3
+ # Copyright (C) 2018-2019 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
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Ruby/GLib2 provides " +
26
26
  "base features for GLib2 based bindings and " +
27
27
  "many useful utility features."
28
- s.author = "The Ruby-GNOME2 Project Team"
28
+ s.author = "The Ruby-GNOME Project Team"
29
29
  s.email = "ruby-gnome2-devel-en@lists.sourceforge.net"
30
30
  s.homepage = "https://ruby-gnome2.osdn.jp/"
31
31
  s.licenses = ["LGPL-2.1+"]
@@ -112,7 +112,10 @@ GType #{@enum_name}_get_type (void);
112
112
  data.force_encoding("utf-8") if data.respond_to?(:force_encoding)
113
113
  data.scan(/^\s*typedef\s+enum\s*(\/\*<\s*flags\s*>\*\/)?\s*
114
114
  \{?\s*(.*?)
115
- \}\s*(\w+);/mx) do |force_flags, constants, name|
115
+ \}\s*(\w+)
116
+ # GLIB_DEPRECATED_TYPE_IN_2_38_FOR(GTestSubprocessFlags)
117
+ (?:\s+[\w()\s]+)?
118
+ ;/mx) do |force_flags, constants, name|
116
119
  enum_options = {}
117
120
  enum_options[:force_flags] = !force_flags.nil?
118
121
  force_flags_patterns = [(options[:force_flags] || [])].flatten
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2005-2018 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2005-2019 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
@@ -148,23 +148,50 @@ module GLib
148
148
 
149
149
 
150
150
  class Enum
151
- def _dump(limit)
152
- Marshal.dump(to_i, limit)
151
+ class << self
152
+ def try_convert(value)
153
+ if value.is_a?(self)
154
+ value
155
+ else
156
+ find(value)
157
+ end
158
+ end
159
+
160
+ def _load(obj)
161
+ new(Marshal.load(obj))
162
+ end
153
163
  end
154
164
 
155
- def self._load(obj)
156
- new(Marshal.load(obj))
165
+ def _dump(limit)
166
+ Marshal.dump(to_i, limit)
157
167
  end
158
168
  end
159
169
 
160
170
 
161
171
  class Flags
162
- def _dump(limit)
163
- Marshal.dump(to_i, limit)
172
+ class << self
173
+ def try_convert(value)
174
+ case value
175
+ when self
176
+ value
177
+ when Integer, String, Symbol, Array
178
+ begin
179
+ new(value)
180
+ rescue ArgumentError
181
+ nil
182
+ end
183
+ else
184
+ nil
185
+ end
186
+ end
187
+
188
+ def _load(obj)
189
+ new(Marshal.load(obj))
190
+ end
164
191
  end
165
192
 
166
- def self._load(obj)
167
- new(Marshal.load(obj))
193
+ def _dump(limit)
194
+ Marshal.dump(to_i, limit)
168
195
  end
169
196
 
170
197
  # FIXME
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2017 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2017-2019 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
@@ -21,6 +21,27 @@ class TestGLibBytes < Test::Unit::TestCase
21
21
  only_glib_version(2, 32, 0)
22
22
  end
23
23
 
24
+ sub_test_case ".try_convert" do
25
+ def test_nil
26
+ assert_nil(GLib::Bytes.try_convert(nil))
27
+ end
28
+
29
+ def test_bytes
30
+ bytes = GLib::Bytes.new("Hello")
31
+ assert_equal(bytes,
32
+ GLib::Bytes.try_convert(bytes))
33
+ end
34
+
35
+ def test_string
36
+ assert_equal("Hello",
37
+ GLib::Bytes.try_convert("Hello").to_s)
38
+ end
39
+
40
+ def test_unconvertable
41
+ assert_nil(GLib::Bytes.try_convert([]))
42
+ end
43
+ end
44
+
24
45
  sub_test_case ".new" do
25
46
  def create_bytes(options={})
26
47
  data = "Hello"
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2015-2019 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
@@ -14,10 +14,41 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require 'test/unit'
18
- require 'glib2'
19
-
20
17
  class TestEnum < Test::Unit::TestCase
18
+ sub_test_case(".try_convert") do
19
+ def test_nil
20
+ assert_nil(GLib::NormalizeMode.try_convert(nil))
21
+ end
22
+
23
+ def test_enum
24
+ assert_equal(GLib::NormalizeMode::NFD,
25
+ GLib::NormalizeMode.try_convert(GLib::NormalizeMode::NFD))
26
+ end
27
+
28
+ def test_integer
29
+ assert_equal(GLib::NormalizeMode::NFD,
30
+ GLib::NormalizeMode.try_convert(GLib::NormalizeMode::NFD.to_i))
31
+ end
32
+
33
+ def test_string
34
+ assert_equal(GLib::NormalizeMode::NFD,
35
+ GLib::NormalizeMode.try_convert("nfd"))
36
+ end
37
+
38
+ def test_symbol
39
+ assert_equal(GLib::NormalizeMode::NFD,
40
+ GLib::NormalizeMode.try_convert(:nfd))
41
+ end
42
+
43
+ def test_nonexistent
44
+ assert_nil(GLib::NormalizeMode.try_convert(:nonexistent))
45
+ end
46
+
47
+ def test_unconvertable
48
+ assert_nil(GLib::NormalizeMode.try_convert([]))
49
+ end
50
+ end
51
+
21
52
  def test_enum_by_symbol
22
53
  original = [0x00c1].pack("U*") # A with acute
23
54
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2015-2019 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
@@ -13,11 +13,47 @@
13
13
  # You should have received a copy of the GNU Lesser General Public
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
-
17
- require 'test/unit'
18
- require 'glib2'
19
16
 
20
17
  class TestFlags < Test::Unit::TestCase
18
+ sub_test_case(".try_convert") do
19
+ def test_nil
20
+ assert_nil(GLib::KeyFile::Flags.try_convert(nil))
21
+ end
22
+
23
+ def test_flags
24
+ assert_equal(GLib::KeyFile::Flags::KEEP_COMMENTS,
25
+ GLib::KeyFile::Flags.try_convert(GLib::KeyFile::Flags::KEEP_COMMENTS))
26
+ end
27
+
28
+ def test_integer
29
+ assert_equal(GLib::KeyFile::Flags.new(1),
30
+ GLib::KeyFile::Flags.try_convert(1))
31
+ end
32
+
33
+ def test_string
34
+ assert_equal(GLib::KeyFile::Flags.new("keep_comments"),
35
+ GLib::KeyFile::Flags.try_convert("keep_comments"))
36
+ end
37
+
38
+ def test_symbol
39
+ assert_equal(GLib::KeyFile::Flags.new(:keep_comments),
40
+ GLib::KeyFile::Flags.try_convert(:keep_comments))
41
+ end
42
+
43
+ def test_array
44
+ assert_equal(GLib::KeyFile::Flags.new(1 | 2),
45
+ GLib::KeyFile::Flags.try_convert([1, :keep_translations]))
46
+ end
47
+
48
+ def test_nonexistent
49
+ assert_nil(GLib::KeyFile::Flags.try_convert(:nonexistent))
50
+ end
51
+
52
+ def test_unconvertable
53
+ assert_nil(GLib::KeyFile::Flags.try_convert({}))
54
+ end
55
+ end
56
+
21
57
  {
22
58
  '<=>' => [
23
59
  [0b0000, 0.0, nil],
@@ -1,6 +1,6 @@
1
- # encoding: ascii-8bit
1
+ # coding: ascii-8bit
2
2
  #
3
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
3
+ # Copyright (C) 2015-2019 Ruby-GNOME2 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
@@ -49,37 +49,37 @@ class TestGLib < Test::Unit::TestCase
49
49
  def test_convert
50
50
  assert_kind_of(String, GLib.charset)
51
51
 
52
- sjis = "\202\261\202\361\202\311\202\277\202\315\220\242\212E"
53
- euc = "\244\263\244\363\244\313\244\301\244\317\300\244\263\246"
54
- utf8 = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257\344\270\226\347\225\214"
55
- assert_equal(GLib.convert(sjis, "UTF-8", "SHIFT_JIS"), utf8)
56
- assert_equal(GLib.convert(sjis, "EUC-JP", "SHIFT_JIS"), euc)
57
- assert_equal(GLib.convert(sjis, "SHIFT_JIS", "SHIFT_JIS"), sjis)
58
- assert_equal(GLib.convert(euc, "UTF-8", "EUC-JP"), utf8)
59
- assert_equal(GLib.convert(euc, "EUC-JP", "EUC-JP"), euc)
60
- assert_equal(GLib.convert(euc, "SHIFT_JIS", "EUC-JP"), sjis)
61
- assert_equal(GLib.convert(utf8, "UTF-8", "UTF-8"), utf8)
62
- assert_equal(GLib.convert(utf8, "EUC-JP", "UTF-8"), euc)
63
- assert_equal(GLib.convert(utf8, "SHIFT_JIS", "UTF-8"), sjis)
52
+ sjis = "\202\261\202\361\202\311\202\277\202\315\220\242\212E".force_encoding("Shift_JIS")
53
+ euc = "\244\263\244\363\244\313\244\301\244\317\300\244\263\246".force_encoding("EUC-JP")
54
+ utf8 = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257\344\270\226\347\225\214".force_encoding("UTF-8")
55
+ assert_equal(utf8, GLib.convert(sjis, "UTF-8", "SHIFT_JIS"))
56
+ assert_equal(euc, GLib.convert(sjis, "EUC-JP", "SHIFT_JIS"))
57
+ assert_equal(sjis, GLib.convert(sjis, "SHIFT_JIS", "SHIFT_JIS"))
58
+ assert_equal(utf8, GLib.convert(euc, "UTF-8", "EUC-JP"))
59
+ assert_equal(euc, GLib.convert(euc, "EUC-JP", "EUC-JP"))
60
+ assert_equal(sjis, GLib.convert(euc, "SHIFT_JIS", "EUC-JP"))
61
+ assert_equal(utf8, GLib.convert(utf8, "UTF-8", "UTF-8"))
62
+ assert_equal(euc, GLib.convert(utf8, "EUC-JP", "UTF-8"))
63
+ assert_equal(sjis, GLib.convert(utf8, "SHIFT_JIS", "UTF-8"))
64
64
  end
65
65
 
66
- def tet_locale_to_utf8
67
- assert_equal(Encoding::UTF8,
66
+ def test_locale_to_utf8
67
+ assert_equal(Encoding::UTF_8,
68
68
  GLib.locale_to_utf8("ascii").encoding)
69
69
  end
70
70
 
71
- def tet_locale_from_utf8
71
+ def test_locale_from_utf8
72
72
  assert_equal(Encoding::ASCII_8BIT,
73
73
  GLib.locale_from_utf8("ascii").encoding)
74
74
  end
75
75
 
76
- def tet_filename_to_utf8
77
- assert_equal(Encoding::UTF8,
76
+ def test_filename_to_utf8
77
+ assert_equal(Encoding::UTF_8,
78
78
  GLib.filename_to_utf8("ascii.txt").encoding)
79
79
  end
80
80
 
81
- def tet_filename_from_utf8
82
- assert_equal(Encoding::ASCII_8BIT,
81
+ def test_filename_from_utf8
82
+ assert_equal(GLib::FILENAME_ENCODING,
83
83
  GLib.filename_from_utf8("ascii.txt").encoding)
84
84
  end
85
85
 
@@ -0,0 +1,51 @@
1
+ # Copyright (C) 2019 Ruby-GNOME Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ class TestGLibType < Test::Unit::TestCase
18
+ sub_test_case(".try_convert") do
19
+ def test_nil
20
+ assert_nil(GLib::Type.try_convert(nil))
21
+ end
22
+
23
+ def test_type
24
+ assert_equal(GLib::Type::STRING,
25
+ GLib::Type.try_convert(GLib::Type::STRING))
26
+ end
27
+
28
+ def test_integer
29
+ assert_equal(GLib::Type::STRING,
30
+ GLib::Type.try_convert(GLib::Type::STRING.to_i))
31
+ end
32
+
33
+ def test_string
34
+ assert_equal(GLib::Type::STRING,
35
+ GLib::Type.try_convert("gchararray"))
36
+ end
37
+
38
+ def test_symbol
39
+ assert_equal(GLib::Type::STRING,
40
+ GLib::Type.try_convert(:gchararray))
41
+ end
42
+
43
+ def test_nonexistent
44
+ assert_nil(GLib::Type.try_convert(:nonexistent))
45
+ end
46
+
47
+ def test_unconvertable
48
+ assert_nil(GLib::Type.try_convert([]))
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib2
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.7
4
+ version: 3.3.8
5
5
  platform: ruby
6
6
  authors:
7
- - The Ruby-GNOME2 Project Team
7
+ - The Ruby-GNOME Project Team
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2019-08-16 00:00:00.000000000 Z
11
+ date: 2019-09-09 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: pkg-config
@@ -192,6 +193,7 @@ files:
192
193
  - test/test-time-zone.rb
193
194
  - test/test-timeout.rb
194
195
  - test/test-type-interface.rb
196
+ - test/test-type.rb
195
197
  - test/test-unicode.rb
196
198
  - test/test-utils.rb
197
199
  - test/test-value.rb