glib2 4.2.5 → 4.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/ext/glib2/extconf.rb +2 -2
- data/ext/glib2/glib2.def +2 -4
- data/ext/glib2/rbglib-variant.c +1 -1
- data/ext/glib2/rbglib.c +10 -6
- data/ext/glib2/rbglib.h +2 -2
- data/ext/glib2/rbglib_fileutils.c +5 -4
- data/ext/glib2/rbglib_maincontext.c +12 -21
- data/ext/glib2/rbglib_unichar.c +31 -31
- data/ext/glib2/rbglib_unicode.c +2 -2
- data/ext/glib2/rbglib_utils.c +2 -2
- data/ext/glib2/rbglib_win32.c +4 -4
- data/ext/glib2/rbgobj_boxed.c +7 -7
- data/ext/glib2/rbgobj_enums.c +3 -4
- data/ext/glib2/rbgobj_flags.c +11 -11
- data/ext/glib2/rbgobj_object.c +105 -113
- data/ext/glib2/rbgobj_param.c +24 -24
- data/ext/glib2/rbgobj_paramspecs.c +18 -18
- data/ext/glib2/rbgobj_signal.c +26 -26
- data/ext/glib2/rbgobj_type.c +9 -17
- data/ext/glib2/rbgobj_typeinstance.c +88 -4
- data/ext/glib2/rbgobj_typeinterface.c +6 -6
- data/ext/glib2/rbgobj_value.c +13 -4
- data/ext/glib2/rbgobj_valuetypes.c +5 -5
- data/ext/glib2/rbgobject.c +20 -7
- data/ext/glib2/rbgobject.h +1 -2
- data/ext/glib2/rbgprivate.h +5 -1
- data/ext/glib2/rbgutil.c +20 -37
- data/ext/glib2/rbgutil.h +25 -7
- data/lib/glib2/deprecated.rb +11 -1
- data/lib/glib2/value.rb +46 -0
- data/lib/glib2.rb +2 -1
- data/test/test-value.rb +38 -3
- data/test/test-variant.rb +1 -1
- metadata +4 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2002-
|
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
|
-
|
33
|
-
|
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
|
-
|
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-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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);
|
data/ext/glib2/rbgobj_value.c
CHANGED
@@ -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
|
-
|
146
|
-
|
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
|
-
|
346
|
-
|
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
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2011-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
/**********************************************************************/
|
data/ext/glib2/rbgobject.c
CHANGED
@@ -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
|
-
|
101
|
-
|
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
|
-
|
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 (
|
141
|
-
|
147
|
+
if (G_TYPE_IS_INSTANTIATABLE(fundamental_type)) {
|
148
|
+
return rbgobj_instantiatable_to_ruby(instance, alloc);
|
142
149
|
} else {
|
143
|
-
|
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
|
}
|
data/ext/glib2/rbgobject.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2003-
|
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);
|
data/ext/glib2/rbgprivate.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2007-
|
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);
|
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-
|
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
|
-
|
35
|
+
rbg_define_setter_alias_if_need(VALUE klass, const char *name, int argc)
|
36
36
|
{
|
37
|
-
|
38
|
-
if ((argc != 1) || strncmp(name, "set_", 4))
|
37
|
+
if (argc != 1) {
|
39
38
|
return;
|
40
|
-
|
41
|
-
name
|
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
|
60
|
-
|
61
|
-
|
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
|
-
|
50
|
+
rbg_define_singleton_setter_alias_if_need(VALUE klass,
|
51
|
+
const char *name,
|
52
|
+
int argc)
|
70
53
|
{
|
71
|
-
|
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
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
95
|
-
|
96
|
-
|
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);
|
data/lib/glib2/deprecated.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2018-
|
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
|
data/lib/glib2/value.rb
ADDED
@@ -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-
|
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-value.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
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)
|
data/test/test-variant.rb
CHANGED
@@ -64,7 +64,7 @@ expected end of input:
|
|
64
64
|
|
65
65
|
test "#inspect" do
|
66
66
|
variant = GLib::Variant.new(29, "y")
|
67
|
-
assert_equal("#<GLib::Variant:0x00 type=y value=29>",
|
67
|
+
assert_equal("#<GLib::Variant:0x00 ptr=0x00 type=y value=29>",
|
68
68
|
variant.inspect.gsub(/0x\h+/, "0x00"))
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glib2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.7
|
5
5
|
platform: ruby
|
6
|
-
original_platform: ''
|
7
6
|
authors:
|
8
7
|
- The Ruby-GNOME Project Team
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-28 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: pkg-config
|
@@ -151,6 +150,7 @@ files:
|
|
151
150
|
- lib/glib2/deprecated.rb
|
152
151
|
- lib/glib2/regex.rb
|
153
152
|
- lib/glib2/time-zone.rb
|
153
|
+
- lib/glib2/value.rb
|
154
154
|
- lib/glib2/variant.rb
|
155
155
|
- lib/glib2/version.rb
|
156
156
|
- lib/gnome/rake/external-package.rb
|
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
|
-
rubygems_version: 3.6.
|
232
|
+
rubygems_version: 3.6.2
|
233
233
|
specification_version: 4
|
234
234
|
summary: Ruby/GLib2 is a Ruby binding of GLib-2.x.
|
235
235
|
test_files: []
|