glib2 4.2.4 → 4.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2023 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2025 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
@@ -365,14 +365,10 @@ rbgobj_class_info_lookup(VALUE klass)
365
365
  VALUE data = rb_hash_aref(klass_to_cinfo, klass);
366
366
  if (!NIL_P(data)) {
367
367
  RGObjClassInfo *cinfo;
368
- if (RTYPEDDATA_P(data)) {
369
- TypedData_Get_Struct(data,
370
- RGObjClassInfo,
371
- RTYPEDDATA_TYPE(data),
372
- cinfo);
373
- } else {
374
- Data_Get_Struct(data, RGObjClassInfo, cinfo);
375
- }
368
+ TypedData_Get_Struct(data,
369
+ RGObjClassInfo,
370
+ RTYPEDDATA_TYPE(data),
371
+ cinfo);
376
372
  return cinfo;
377
373
  }
378
374
 
@@ -638,7 +634,7 @@ rg_s_try_convert(VALUE self, VALUE value)
638
634
  return value;
639
635
 
640
636
  if (RVAL2CBOOL(rb_obj_is_kind_of(value, rb_cInteger))) {
641
- GType gtype = NUM2ULONG(value);
637
+ GType gtype = NUM2SIZET(value);
642
638
  if (!g_type_name(gtype))
643
639
  return Qnil;
644
640
  return rb_funcall(self, id_new, 1, value);
@@ -664,15 +660,11 @@ rg_s_try_convert(VALUE self, VALUE value)
664
660
  if (NIL_P(data))
665
661
  continue;
666
662
 
667
- if (RTYPEDDATA_P(data)) {
668
- TypedData_Get_Struct(data,
669
- RGObjClassInfo,
670
- RTYPEDDATA_TYPE(data),
671
- cinfo);
672
- } else {
673
- Data_Get_Struct(data, RGObjClassInfo, cinfo);
674
- }
675
- return rb_funcall(self, id_new, 1, ULONG2NUM(cinfo->gtype));
663
+ TypedData_Get_Struct(data,
664
+ RGObjClassInfo,
665
+ RTYPEDDATA_TYPE(data),
666
+ cinfo);
667
+ return rb_funcall(self, id_new, 1, SIZET2NUM(cinfo->gtype));
676
668
  }
677
669
  return Qnil;
678
670
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2023 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2025 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,10 +29,93 @@ typedef void (*ClassInfoCallbackFunc) (gpointer instance,
29
29
  const RGObjClassInfo *class_info,
30
30
  gpointer user_data);
31
31
 
32
- static G_GNUC_NORETURN VALUE
33
- instantiatable_s_allocate(G_GNUC_UNUSED VALUE klass)
32
+ typedef struct {
33
+ VALUE self;
34
+ GTypeInstance* instance;
35
+ const RGObjClassInfo* cinfo;
36
+ } rbg_glib_instantiatable_holder;
37
+
38
+ static void
39
+ rbg_glib_instantiatable_holder_free(void *holder)
40
+ {
41
+ xfree(holder);
42
+ }
43
+
44
+ const rb_data_type_t rbg_glib_instantiatable_type = {
45
+ "GLib::Instantiatable",
46
+ {
47
+ NULL,
48
+ rbg_glib_instantiatable_holder_free,
49
+ },
50
+ NULL,
51
+ NULL,
52
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
53
+ };
54
+
55
+ static VALUE
56
+ instantiatable_s_allocate(VALUE klass)
57
+ {
58
+ rbg_glib_instantiatable_holder* holder;
59
+ VALUE rb_instantiatable;
60
+
61
+ rb_instantiatable = TypedData_Make_Struct(klass,
62
+ rbg_glib_instantiatable_holder,
63
+ &rbg_glib_instantiatable_type,
64
+ holder);
65
+ holder->self = rb_instantiatable;
66
+ holder->instance = NULL;
67
+ holder->cinfo = NULL;
68
+
69
+ return rb_instantiatable;
70
+ }
71
+
72
+ void
73
+ rbgobj_instantiatable_initialize(VALUE self, gpointer instance)
74
+ {
75
+ rbg_glib_instantiatable_holder* holder;
76
+ TypedData_Get_Struct(self,
77
+ rbg_glib_instantiatable_holder,
78
+ &rbg_glib_instantiatable_type,
79
+ holder);
80
+ holder->instance = instance;
81
+ holder->cinfo = RVAL2CINFO(self);
82
+ }
83
+
84
+ GTypeInstance *
85
+ rbgobj_instantiatable_get(VALUE self)
86
+ {
87
+ rbg_glib_instantiatable_holder* holder;
88
+ TypedData_Get_Struct(self,
89
+ rbg_glib_instantiatable_holder,
90
+ &rbg_glib_instantiatable_type,
91
+ holder);
92
+ return holder->instance;
93
+ }
94
+
95
+ VALUE
96
+ rbgobj_instantiatable_to_ruby(GTypeInstance *instance, gboolean alloc)
97
+ {
98
+ /* TODO: Add support for reusing existing associated Ruby object
99
+ * but how...? GTypeInstance doesn't provide
100
+ * g_type_instance_{get,set}_qdata() like
101
+ * g_object_{get,set}_qdata(). */
102
+ if (alloc) {
103
+ GType type = G_TYPE_FROM_INSTANCE(instance);
104
+ VALUE rb_instance = instantiatable_s_allocate(GTYPE2CLASS(type));
105
+ rbgobj_instantiatable_initialize(rb_instance, instance);
106
+ return rb_instance;
107
+ } else {
108
+ return Qnil;
109
+ }
110
+ }
111
+
112
+ static VALUE
113
+ rg_inspect(VALUE self)
34
114
  {
35
- rb_raise(rb_eTypeError, "abstract class");
115
+ rbg_glib_instantiatable_holder *holder;
116
+ TypedData_Get_Struct(self, rbg_glib_instantiatable_holder, &rbg_glib_instantiatable_type, holder);
117
+ return rb_sprintf("#<%" PRIsVALUE ":%p ptr=%p>",
118
+ rb_obj_class(self), (void *)self, holder->instance);
36
119
  }
37
120
 
38
121
  static VALUE
@@ -130,4 +213,5 @@ Init_gobject_typeinstance(void)
130
213
  rb_define_alloc_func(RG_TARGET_NAMESPACE, (VALUE(*)_((VALUE)))instantiatable_s_allocate);
131
214
  RG_DEF_METHOD(gtype, 0);
132
215
  RG_DEF_METHOD(clone, 0);
216
+ RG_DEF_METHOD(inspect, 0);
133
217
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2023 Ruby-GNOME Project Team
3
+ * Copyright (C) 2002-2025 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
@@ -173,11 +173,11 @@ void
173
173
  Init_gobject_typeinterface(void)
174
174
  {
175
175
  RG_TARGET_NAMESPACE = rb_define_module_under(rbg_mGLib(), "MetaInterface");
176
- rbg_define_method(RG_TARGET_NAMESPACE, "gtype", generic_s_gtype, 0);
177
- rbg_define_method(RG_TARGET_NAMESPACE,
178
- "to_s",
179
- rbgutil_generic_s_to_s_gtype_name_fallback,
180
- 0);
176
+ rb_define_method(RG_TARGET_NAMESPACE, "gtype", generic_s_gtype, 0);
177
+ rb_define_method(RG_TARGET_NAMESPACE,
178
+ "to_s",
179
+ rbgutil_generic_s_to_s_gtype_name_fallback,
180
+ 0);
181
181
  RG_DEF_ALIAS("inspect", "to_s");
182
182
  RG_DEF_METHOD(append_features, 1);
183
183
  RG_DEF_METHOD(included, 1);
@@ -142,8 +142,13 @@ rbgobj_gvalue_to_rvalue(const GValue* value)
142
142
  GValueToRValueFunc func;
143
143
  func = g_type_get_qdata(type, qGValueToRValueFunc);
144
144
  if (!func) {
145
- g_warning("rbgobj_gvalue_to_rvalue: unsupported type: %s\n",
146
- g_type_name(type));
145
+ if (G_TYPE_IS_INSTANTIATABLE(fundamental_type)) {
146
+ rvalue = rbgobj_instantiatable_to_ruby(g_value_peek_pointer(value), TRUE);
147
+ } else {
148
+ g_warning("rbgobj_gvalue_to_rvalue: unsupported type: %s\n",
149
+ g_type_name(type));
150
+ rvalue = Qnil;
151
+ }
147
152
  } else {
148
153
  rvalue = func(value);
149
154
  }
@@ -342,8 +347,12 @@ rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
342
347
  RValueToGValueFunc func =
343
348
  g_type_get_qdata(type, qRValueToGValueFunc);
344
349
  if (!func){
345
- g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n",
346
- g_type_name(type));
350
+ if (G_TYPE_IS_INSTANTIATABLE(fundamental_type)) {
351
+ g_value_set_instance(result, rbgobj_instantiatable_get(val));
352
+ } else {
353
+ g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n",
354
+ g_type_name(type));
355
+ }
347
356
  } else {
348
357
  func(val, result);
349
358
  }
@@ -374,7 +383,7 @@ rg_initialize(int argc, VALUE *argv, VALUE self)
374
383
 
375
384
  rb_scan_args(argc, argv, "11", &rb_gtype, &rb_value);
376
385
 
377
- g_value_init(&value, NUM2ULONG(rb_to_int(rb_gtype)));
386
+ g_value_init(&value, NUM2SIZET(rb_to_int(rb_gtype)));
378
387
  if (argc == 2) {
379
388
  rbgobj_rvalue_to_gvalue(rb_value, &value);
380
389
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2022 Ruby-GNOME Project Team
3
+ * Copyright (C) 2011-2025 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
@@ -96,10 +96,10 @@ Init_gtype_pointer(void)
96
96
  {
97
97
  VALUE cPtr = G_DEF_CLASS(G_TYPE_POINTER, "Pointer", rbg_mGLib());
98
98
  rb_define_alloc_func(cPtr, ptr_alloc);
99
- rbg_define_singleton_method(cPtr, "gtype", ptr_s_gtype, 0);
100
- rbg_define_method(cPtr, "initialize", ptr_initialize, 1);
101
- rbg_define_method(cPtr, "gtype", ptr_gtype, 0);
102
- rbg_define_method(cPtr, "to_i", ptr_to_i, 0);
99
+ rb_define_singleton_method(cPtr, "gtype", ptr_s_gtype, 0);
100
+ rb_define_method(cPtr, "initialize", ptr_initialize, 1);
101
+ rb_define_method(cPtr, "gtype", ptr_gtype, 0);
102
+ rb_define_method(cPtr, "to_i", ptr_to_i, 0);
103
103
  }
104
104
 
105
105
  /**********************************************************************/
@@ -64,7 +64,9 @@ rbgobj_initialize_object(VALUE obj, gpointer cobj)
64
64
  rbgobj_boxed_initialize(obj, cobj);
65
65
  break;
66
66
  default:
67
- rbgobj_convert_initialize(type, obj, cobj);
67
+ if (!rbgobj_convert_initialize(type, obj, cobj)) {
68
+ rbgobj_instantiatable_initialize(obj, cobj);
69
+ }
68
70
  break;
69
71
  }
70
72
  }
@@ -97,8 +99,12 @@ rbgobj_instance_from_ruby_object(VALUE obj)
97
99
  {
98
100
  gpointer instance;
99
101
  if (!rbgobj_convert_robj2instance(fundamental_type, obj, &instance)) {
100
- rb_raise(rb_eTypeError, "%s isn't supported",
101
- rb_class2name(CLASS_OF(obj)));
102
+ if (G_TYPE_IS_INSTANTIATABLE(fundamental_type)) {
103
+ return rbgobj_instantiatable_get(obj);
104
+ } else {
105
+ rb_raise(rb_eTypeError, "%s isn't supported",
106
+ rb_class2name(CLASS_OF(obj)));
107
+ }
102
108
  }
103
109
  return instance;
104
110
  }
@@ -131,16 +137,23 @@ rbgobj_ruby_object_from_instance2(gpointer instance, gboolean alloc)
131
137
  }
132
138
  }
133
139
 
134
- switch (G_TYPE_FUNDAMENTAL(type)) {
140
+ GType fundamental_type = G_TYPE_FUNDAMENTAL(type);
141
+ switch (fundamental_type) {
135
142
  case G_TYPE_OBJECT:
136
143
  return rbgobj_get_ruby_object_from_gobject(instance, alloc);
137
144
  case G_TYPE_PARAM:
138
145
  return rbgobj_get_ruby_object_from_param_spec(instance, alloc);
139
146
  default:
140
- if (alloc) {
141
- rb_raise(rb_eTypeError, "%s isn't supported", g_type_name(type));
147
+ if (G_TYPE_IS_INSTANTIATABLE(fundamental_type)) {
148
+ return rbgobj_instantiatable_to_ruby(instance, alloc);
142
149
  } else {
143
- return Qnil;
150
+ if (alloc) {
151
+ rb_raise(rb_eTypeError,
152
+ "%s isn't supported",
153
+ g_type_name(type));
154
+ } else {
155
+ return Qnil;
156
+ }
144
157
  }
145
158
  }
146
159
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2003-2023 Ruby-GNOME Project Team
3
+ * Copyright (C) 2003-2025 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
@@ -162,7 +162,6 @@ extern VALUE rbgobj_get_relative_removable(VALUE obj, ID obj_ivar_id,
162
162
  extern void rbgobj_remove_relative(VALUE obj, ID obj_ivar_id, VALUE hash_key);
163
163
  extern void rbgobj_remove_relative_all(VALUE obj, ID obj_ivar_id);
164
164
 
165
- extern GObject* rbgobj_gobject_new(GType type, VALUE params_hash);
166
165
  extern VALUE rbgobj_create_object(VALUE klass); /* deprecated */
167
166
 
168
167
  extern VALUE rbgobj_get_ruby_object_from_gobject(GObject* gobj, gboolean alloc);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2007-2024 Ruby-GNOME Project Team
3
+ * Copyright (C) 2007-2025 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,6 +69,7 @@ typedef struct {
69
69
 
70
70
  G_GNUC_INTERNAL extern GPrivate rg_polling_key;
71
71
  G_GNUC_INTERNAL extern rb_encoding *rbg_filename_encoding;
72
+ G_GNUC_INTERNAL extern const rb_data_type_t rbg_glib_instantiatable_type;
72
73
 
73
74
  extern VALUE rbgobj_cEnum;
74
75
  extern VALUE rbgobj_cFlags;
@@ -86,13 +87,16 @@ extern VALUE rbgobj_mMetaSignal;
86
87
  extern void rbgobj_define_property_accessors(VALUE klass);
87
88
  extern void rbgobj_define_action_methods(VALUE klass);
88
89
 
90
+ extern void rbgobj_instantiatable_initialize(VALUE self, gpointer instance);
89
91
  extern void rbgobj_param_spec_initialize(VALUE self, GParamSpec* pspec);
90
92
  extern void rbgobj_boxed_initialize(VALUE obj, gpointer boxed);
91
93
 
92
94
  extern GParamSpec* rbgobj_get_param_spec(VALUE obj);
93
95
  extern GObject* rbgobj_get_gobject(VALUE obj);
96
+ extern GTypeInstance *rbgobj_instantiatable_get(VALUE self);
94
97
 
95
98
  extern VALUE rbgobj_get_ruby_object_from_param_spec(GParamSpec* pspec, gboolean alloc);
99
+ extern VALUE rbgobj_instantiatable_to_ruby(GTypeInstance *instance, gboolean alloc);
96
100
 
97
101
  extern void rbgobj_init_object_class(VALUE klass);
98
102
  extern void rbgobj_init_flags_class(VALUE klass);
@@ -146,7 +150,6 @@ G_GNUC_INTERNAL void Init_glib_gc(void);
146
150
  G_GNUC_INTERNAL void Init_gutil(void);
147
151
  G_GNUC_INTERNAL void Init_gutil_callback(void);
148
152
  G_GNUC_INTERNAL void Init_glib_gettext(void);
149
- G_GNUC_INTERNAL void Init_glib_int64(void);
150
153
  G_GNUC_INTERNAL void Init_glib_error(void);
151
154
  G_GNUC_INTERNAL void Init_glib_error_conversions(void);
152
155
  G_GNUC_INTERNAL void Init_glib_threads(void);
data/ext/glib2/rbgutil.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2023 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2025 Ruby-GNOME Project Team
4
4
  * Copyright (C) 2002-2004 Masao Mutoh
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -32,52 +32,35 @@ static ID id_allocate;
32
32
  static ID id_equal;
33
33
 
34
34
  void
35
- rbg_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
35
+ rbg_define_setter_alias_if_need(VALUE klass, const char *name, int argc)
36
36
  {
37
- rb_define_method(klass, name, func, argc);
38
- if ((argc != 1) || strncmp(name, "set_", 4))
37
+ if (argc != 1) {
39
38
  return;
40
-
41
- name += 4;
42
- rb_funcall(klass, rbgutil_id_module_eval, 3,
43
- CSTR2RVAL_FREE(g_strdup_printf("def %s=(val); set_%s(val); val; end\n",
44
- name, name)),
45
- rb_str_new2(__FILE__),
46
- INT2NUM(__LINE__));
47
- }
48
-
49
- void
50
- rbg_define_private_method(VALUE klass,
51
- const char *name,
52
- VALUE (*func)(ANYARGS),
53
- int argc)
54
- {
55
- rb_define_private_method(klass, name, func, argc);
56
- if ((argc != 1) || strncmp(name, "set_", 4))
39
+ }
40
+ if (strncmp(name, "set_", 4) != 0) {
57
41
  return;
42
+ }
58
43
 
59
- name += 4;
60
- rb_funcall(klass, rbgutil_id_module_eval, 3,
61
- CSTR2RVAL_FREE(g_strdup_printf("def %s=(val); set_%s(val); val; end\n"
62
- "private :%s=\n",
63
- name, name, name)),
64
- rb_str_new2(__FILE__),
65
- INT2NUM(__LINE__));
44
+ gchar *equal_name = g_strdup_printf("%s=", name + 4);
45
+ rb_define_alias(klass, equal_name, name);
46
+ g_free(equal_name);
66
47
  }
67
48
 
68
49
  void
69
- rbg_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
50
+ rbg_define_singleton_setter_alias_if_need(VALUE klass,
51
+ const char *name,
52
+ int argc)
70
53
  {
71
- rb_define_singleton_method(obj, name, func, argc);
72
- if ((argc != 1) || strncmp(name, "set_", 4))
54
+ if (argc != 1) {
73
55
  return;
56
+ }
57
+ if (strncmp(name, "set_", 4) != 0) {
58
+ return;
59
+ }
74
60
 
75
- name += 4;
76
- rb_funcall(obj, rbgutil_id_module_eval, 3,
77
- CSTR2RVAL_FREE(g_strdup_printf("def self.%s=(val); set_%s(val); val; end\n",
78
- name, name)),
79
- rb_str_new2(__FILE__),
80
- INT2NUM(__LINE__));
61
+ gchar *equal_name = g_strdup_printf("%s=", name + 4);
62
+ rb_define_alias(rb_singleton_class(klass), equal_name, name);
63
+ g_free(equal_name);
81
64
  }
82
65
 
83
66
  void
data/ext/glib2/rbgutil.h CHANGED
@@ -37,7 +37,15 @@ G_BEGIN_DECLS
37
37
  #define RG_DEF_MODFUNC_OPERATOR(ope, func, argc) \
38
38
  rb_define_module_function(RG_TARGET_NAMESPACE, ope, rg_m_operator_ ## func, argc)
39
39
  #define RG_DEF_SMETHOD(method, argc) \
40
- rbg_define_singleton_method(RG_TARGET_NAMESPACE, #method, rg_s_ ## method, argc)
40
+ do { \
41
+ rb_define_singleton_method(RG_TARGET_NAMESPACE, \
42
+ #method, \
43
+ rg_s_##method, \
44
+ argc); \
45
+ rbg_define_singleton_setter_alias_if_need(RG_TARGET_NAMESPACE, \
46
+ #method, \
47
+ argc); \
48
+ } while (FALSE)
41
49
  #define RG_DEF_SMETHOD_P(method, argc) \
42
50
  rb_define_singleton_method(RG_TARGET_NAMESPACE, #method"?", rg_s_ ## method ## _p, argc)
43
51
  #define RG_DEF_SMETHOD_BANG(method, argc) \
@@ -45,7 +53,10 @@ G_BEGIN_DECLS
45
53
  #define RG_DEF_SMETHOD_OPERATOR(ope, func, argc) \
46
54
  rb_define_singleton_method(RG_TARGET_NAMESPACE, ope, rg_s_operator_ ## func, argc)
47
55
  #define RG_DEF_METHOD(method, argc) \
48
- rbg_define_method(RG_TARGET_NAMESPACE, #method, rg_ ## method, argc)
56
+ do { \
57
+ rb_define_method(RG_TARGET_NAMESPACE, #method, rg_ ## method, argc); \
58
+ rbg_define_setter_alias_if_need(RG_TARGET_NAMESPACE, #method, argc); \
59
+ } while (FALSE)
49
60
  #define RG_DEF_METHOD_P(method, argc) \
50
61
  rb_define_method(RG_TARGET_NAMESPACE, #method"?", rg_ ## method ## _p, argc)
51
62
  #define RG_DEF_METHOD_BANG(method, argc) \
@@ -58,7 +69,10 @@ G_BEGIN_DECLS
58
69
  #define RG_DEF_SALIAS(new, old) \
59
70
  rb_define_alias(rb_class_of(RG_TARGET_NAMESPACE), new, old)
60
71
  #define RG_DEF_PRIVATE_METHOD(method, argc) \
61
- rbg_define_private_method(RG_TARGET_NAMESPACE, #method, rg_ ## method, argc)
72
+ do { \
73
+ rb_define_private_method(RG_TARGET_NAMESPACE, #method, rg_##method, argc); \
74
+ rbg_define_setter_alias_if_need(RG_TARGET_NAMESPACE, #method, argc); \
75
+ } while (FALSE)
62
76
 
63
77
  #define RG_REG_GLIBID_SETTER(name) \
64
78
  rbgobj_register_property_setter(CLASS2GTYPE(RG_TARGET_NAMESPACE), name, rbgutil_glibid_r2g_func)
@@ -75,7 +89,8 @@ G_BEGIN_DECLS
75
89
  #define G_REPLACE_SET_PROPERTY(klass, name, function, args) \
76
90
  rb_undef_method(klass, "set_" name); \
77
91
  rb_undef_method(klass, name "="); \
78
- rbg_define_method(klass, "set_" name, function, args)
92
+ rb_define_method(klass, "set_" name, function, args); \
93
+ rbg_define_setter_alias_if_need(klass, "set_" name, args)
79
94
 
80
95
  #define G_REPLACE_GET_PROPERTY(klass, name, function, args) \
81
96
  rb_undef_method(klass, name); \
@@ -91,9 +106,12 @@ G_BEGIN_DECLS
91
106
  #define RBG_STRING_SET_UTF8_ENCODING(string) \
92
107
  (rbgutil_string_set_utf8_encoding(string))
93
108
 
94
- extern void rbg_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc);
95
- extern void rbg_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc);
96
- extern void rbg_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc);
109
+ extern void rbg_define_setter_alias_if_need(VALUE klass,
110
+ const char *name,
111
+ int argc);
112
+ extern void rbg_define_singleton_setter_alias_if_need(VALUE klass,
113
+ const char *name,
114
+ int argc);
97
115
  extern VALUE rbgutil_def_setters(VALUE klass);
98
116
  extern void rbgutil_set_properties(VALUE self, VALUE hash);
99
117
  extern VALUE rbgutil_protect(VALUE (*proc) (VALUE), VALUE data);
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2018-2021 Ruby-GNOME Project Team
1
+ # Copyright (C) 2018-2025 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
@@ -47,4 +47,14 @@ module GLib
47
47
  warn: "Use 'GLib.format_size(size, flags: :iec_units)'.") do |_, size|
48
48
  format_size(size, flags: :iec_units)
49
49
  end
50
+
51
+ define_deprecated_singleton_method(
52
+ :set_ruby_thread_priority,
53
+ warn: "This doesn't nothing.") do |_, _priority|
54
+ end
55
+
56
+ define_deprecated_singleton_method(
57
+ :ruby_thread_priority=,
58
+ warn: "This doesn't nothing.") do |_, _priority|
59
+ end
50
60
  end
@@ -0,0 +1,46 @@
1
+ # Copyright (C) 2025 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
+ module GLib
18
+ class Value
19
+ class << self
20
+ def try_convert(value)
21
+ case value
22
+ when String
23
+ new(GLib::Type::STRING, value)
24
+ when Integer
25
+ if value.negative?
26
+ if value < GLib::MININT32
27
+ new(GLib::Type::INT64, value)
28
+ else
29
+ new(GLib::Type::INT, value)
30
+ end
31
+ else
32
+ if value > GLib::MAXUINT32
33
+ new(GLib::Type::UINT64, value)
34
+ else
35
+ new(GLib::Type::UINT, value)
36
+ end
37
+ end
38
+ when Float
39
+ new(GLib::Type::DOUBLE, value)
40
+ else
41
+ nil
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/glib2.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2005-2024 Ruby-GNOME Project Team
1
+ # Copyright (C) 2005-2025 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
@@ -341,6 +341,7 @@ require "glib2/deprecated"
341
341
  require "glib2/date-time"
342
342
  require "glib2/regex"
343
343
  require "glib2/time-zone"
344
+ require "glib2/value"
344
345
  require "glib2/variant"
345
346
 
346
347
  =begin
data/test/test-glib2.rb CHANGED
@@ -1,6 +1,4 @@
1
- # coding: ascii-8bit
2
- #
3
- # Copyright (C) 2015-2022 Ruby-GNOME Project Team
1
+ # Copyright (C) 2015-2024 Ruby-GNOME Project Team
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -49,9 +47,12 @@ class TestGLib < Test::Unit::TestCase
49
47
  def test_convert
50
48
  assert_kind_of(String, GLib.charset)
51
49
 
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")
50
+ # U+3042 HIRAGANA LETTER A
51
+ # U+3044 HIRAGANA LETTER I
52
+ # U+3046 HIRAGANA LETTER U
53
+ utf8 = "\u3042\u3044\u3046"
54
+ sjis = utf8.encode("Shift_JIS")
55
+ euc = utf8.encode("EUC-JP")
55
56
  assert_equal(utf8, GLib.convert(sjis, "UTF-8", "SHIFT_JIS"))
56
57
  assert_equal(euc, GLib.convert(sjis, "EUC-JP", "SHIFT_JIS"))
57
58
  assert_equal(sjis, GLib.convert(sjis, "SHIFT_JIS", "SHIFT_JIS"))
data/test/test-value.rb CHANGED
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013-2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2013-2025 Ruby-GNOME Project Team
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -19,6 +17,43 @@
19
17
  class TestGLibValue < Test::Unit::TestCase
20
18
  include GLibTestUtils
21
19
 
20
+ sub_test_case(".try_convert") do
21
+ def test_string
22
+ assert_equal(GLib::Type::STRING,
23
+ GLib::Value.try_convert("Hello").type)
24
+ end
25
+
26
+ def test_integer_negative_small
27
+ assert_equal(GLib::Type::INT,
28
+ GLib::Value.try_convert(-(2 ** 31)).type)
29
+ end
30
+
31
+ def test_integer_negative_large
32
+ assert_equal(GLib::Type::INT64,
33
+ GLib::Value.try_convert(-(2 ** 31 + 1)).type)
34
+ end
35
+
36
+ def test_integer_zero
37
+ assert_equal(GLib::Type::UINT,
38
+ GLib::Value.try_convert(0).type)
39
+ end
40
+
41
+ def test_integer_positive_small
42
+ assert_equal(GLib::Type::UINT,
43
+ GLib::Value.try_convert(2 ** 32 - 1).type)
44
+ end
45
+
46
+ def test_integer_positive_large
47
+ assert_equal(GLib::Type::UINT64,
48
+ GLib::Value.try_convert(2 ** 32).type)
49
+ end
50
+
51
+ def test_float
52
+ assert_equal(GLib::Type::DOUBLE,
53
+ GLib::Value.try_convert(-0.0).type)
54
+ end
55
+ end
56
+
22
57
  def test_type
23
58
  value = GLib::Value.new(GLib::Type::UINT, 29)
24
59
  assert_equal(GLib::Type::UINT, value.type)