glib2 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3023 -0
- data/README +28 -0
- data/Rakefile +87 -0
- data/extconf.rb +61 -0
- data/sample/bookmarkfile.rb +66 -0
- data/sample/completion.rb +45 -0
- data/sample/idle.rb +41 -0
- data/sample/iochannel.rb +44 -0
- data/sample/keyfile.rb +62 -0
- data/sample/shell.rb +36 -0
- data/sample/spawn.rb +25 -0
- data/sample/timeout.rb +28 -0
- data/sample/timeout2.rb +35 -0
- data/sample/timer.rb +40 -0
- data/sample/type-register.rb +103 -0
- data/sample/type-register2.rb +104 -0
- data/sample/utils.rb +54 -0
- data/src/glib-enum-types.c +1032 -0
- data/src/glib-enum-types.h +140 -0
- data/src/lib/glib-mkenums.rb +199 -0
- data/src/lib/glib2.rb +220 -0
- data/src/lib/mkmf-gnome2.rb +390 -0
- data/src/lib/pkg-config.rb +137 -0
- data/src/rbgcompat.h +30 -0
- data/src/rbglib.c +320 -0
- data/src/rbglib.h +96 -0
- data/src/rbglib_bookmarkfile.c +595 -0
- data/src/rbglib_completion.c +192 -0
- data/src/rbglib_convert.c +195 -0
- data/src/rbglib_error.c +95 -0
- data/src/rbglib_fileutils.c +83 -0
- data/src/rbglib_i18n.c +44 -0
- data/src/rbglib_int64.c +157 -0
- data/src/rbglib_iochannel.c +883 -0
- data/src/rbglib_keyfile.c +846 -0
- data/src/rbglib_maincontext.c +917 -0
- data/src/rbglib_mainloop.c +87 -0
- data/src/rbglib_messages.c +150 -0
- data/src/rbglib_pollfd.c +111 -0
- data/src/rbglib_shell.c +68 -0
- data/src/rbglib_source.c +190 -0
- data/src/rbglib_spawn.c +345 -0
- data/src/rbglib_threads.c +51 -0
- data/src/rbglib_timer.c +127 -0
- data/src/rbglib_unicode.c +611 -0
- data/src/rbglib_utils.c +386 -0
- data/src/rbglib_win32.c +136 -0
- data/src/rbgobj_boxed.c +251 -0
- data/src/rbgobj_closure.c +337 -0
- data/src/rbgobj_convert.c +167 -0
- data/src/rbgobj_enums.c +961 -0
- data/src/rbgobj_fundamental.c +30 -0
- data/src/rbgobj_object.c +892 -0
- data/src/rbgobj_param.c +390 -0
- data/src/rbgobj_paramspecs.c +305 -0
- data/src/rbgobj_signal.c +963 -0
- data/src/rbgobj_strv.c +61 -0
- data/src/rbgobj_type.c +851 -0
- data/src/rbgobj_typeinstance.c +121 -0
- data/src/rbgobj_typeinterface.c +148 -0
- data/src/rbgobj_typemodule.c +66 -0
- data/src/rbgobj_typeplugin.c +49 -0
- data/src/rbgobj_value.c +313 -0
- data/src/rbgobj_valuearray.c +59 -0
- data/src/rbgobj_valuetypes.c +298 -0
- data/src/rbgobject.c +406 -0
- data/src/rbgobject.h +265 -0
- data/src/rbgprivate.h +88 -0
- data/src/rbgutil.c +222 -0
- data/src/rbgutil.h +82 -0
- data/src/rbgutil_callback.c +231 -0
- data/test/glib-test-init.rb +6 -0
- data/test/glib-test-utils.rb +12 -0
- data/test/run-test.rb +25 -0
- data/test/test_enum.rb +99 -0
- data/test/test_file_utils.rb +15 -0
- data/test/test_glib2.rb +120 -0
- data/test/test_iochannel.rb +275 -0
- data/test/test_key_file.rb +38 -0
- data/test/test_mkenums.rb +25 -0
- data/test/test_signal.rb +20 -0
- data/test/test_timeout.rb +28 -0
- data/test/test_unicode.rb +369 -0
- data/test/test_utils.rb +37 -0
- data/test/test_win32.rb +13 -0
- metadata +165 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_typeinstance.c -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/07/04 13:13:19 $
|
8
|
+
created at: Sat May 27 14:18:55 JST 2006
|
9
|
+
|
10
|
+
Copyright (C) 2002-2006 Ruby-GNOME2 Project Team
|
11
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
12
|
+
|
13
|
+
**********************************************************************/
|
14
|
+
|
15
|
+
#include "rbgprivate.h"
|
16
|
+
|
17
|
+
VALUE cInstantiatable;
|
18
|
+
|
19
|
+
typedef void (*ClassInfoCallbackFunc) (gpointer instance,
|
20
|
+
const RGObjClassInfo *class_info,
|
21
|
+
gpointer user_data);
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
instantiatable_s_allocate(klass)
|
25
|
+
VALUE klass;
|
26
|
+
{
|
27
|
+
rb_raise(rb_eTypeError, "abstract class");
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE
|
31
|
+
instantiatable_get_gtype(self)
|
32
|
+
VALUE self;
|
33
|
+
{
|
34
|
+
return rbgobj_gtype_new(G_TYPE_FROM_INSTANCE(rbgobj_instance_from_ruby_object(self)));
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE
|
38
|
+
instantiatable_clone(self)
|
39
|
+
VALUE self;
|
40
|
+
{
|
41
|
+
rb_raise(rb_eTypeError, "can't clone %s", rb_class2name(CLASS_OF(self)));
|
42
|
+
}
|
43
|
+
|
44
|
+
/**********************************************************************/
|
45
|
+
|
46
|
+
static void
|
47
|
+
each_cinfo(gpointer instance, ClassInfoCallbackFunc func, gpointer user_data)
|
48
|
+
{
|
49
|
+
const GType gtype = G_TYPE_FROM_INSTANCE(instance);
|
50
|
+
GType* interfaces;
|
51
|
+
guint n_interfaces = 0;
|
52
|
+
|
53
|
+
interfaces = g_type_interfaces(gtype, &n_interfaces);
|
54
|
+
{
|
55
|
+
guint i;
|
56
|
+
for (i = 0; i < n_interfaces; i++) {
|
57
|
+
const RGObjClassInfo *info;
|
58
|
+
|
59
|
+
info = GTYPE2CINFO_NO_CREATE(interfaces[i]);
|
60
|
+
if (info)
|
61
|
+
func(instance, info, user_data);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
g_free(interfaces);
|
65
|
+
|
66
|
+
{
|
67
|
+
GType type;
|
68
|
+
for (type = gtype; type != G_TYPE_INVALID; type = g_type_parent(type)) {
|
69
|
+
const RGObjClassInfo *info;
|
70
|
+
|
71
|
+
info = GTYPE2CINFO_NO_CREATE(type);
|
72
|
+
if (info)
|
73
|
+
func(instance, info, user_data);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
static void
|
79
|
+
call_cinfo_free(gpointer instance, const RGObjClassInfo *cinfo, gpointer user_data)
|
80
|
+
{
|
81
|
+
if (cinfo->free) cinfo->free(instance);
|
82
|
+
}
|
83
|
+
|
84
|
+
static void
|
85
|
+
call_cinfo_mark(gpointer instance, const RGObjClassInfo *cinfo, gpointer user_data)
|
86
|
+
{
|
87
|
+
if (cinfo->mark) cinfo->mark(instance);
|
88
|
+
}
|
89
|
+
|
90
|
+
void
|
91
|
+
rbgobj_instance_call_cinfo_mark(gpointer instance)
|
92
|
+
{
|
93
|
+
each_cinfo(instance, call_cinfo_mark, NULL);
|
94
|
+
}
|
95
|
+
|
96
|
+
void
|
97
|
+
rbgobj_instance_call_cinfo_free(gpointer instance)
|
98
|
+
{
|
99
|
+
each_cinfo(instance, call_cinfo_free, NULL);
|
100
|
+
}
|
101
|
+
|
102
|
+
void
|
103
|
+
rbgobj_gc_mark_instance(gpointer instance)
|
104
|
+
{
|
105
|
+
VALUE obj = rbgobj_ruby_object_from_instance2(instance, FALSE);
|
106
|
+
rb_gc_mark(obj);
|
107
|
+
}
|
108
|
+
|
109
|
+
/**********************************************************************/
|
110
|
+
|
111
|
+
void
|
112
|
+
Init_gobject_typeinstance()
|
113
|
+
{
|
114
|
+
/* should be renamed to GLib::Instance? */
|
115
|
+
cInstantiatable = rb_define_class_under(mGLib, "Instantiatable", rb_cObject);
|
116
|
+
rb_extend_object(cInstantiatable, mMetaInterface);
|
117
|
+
|
118
|
+
rb_define_alloc_func(cInstantiatable, (VALUE(*)_((VALUE)))instantiatable_s_allocate);
|
119
|
+
rb_define_method(cInstantiatable, "gtype", instantiatable_get_gtype, 0);
|
120
|
+
rb_define_method(cInstantiatable, "clone", instantiatable_clone, 0);
|
121
|
+
}
|
@@ -0,0 +1,148 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_typeinterface.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 16:07:28 $
|
8
|
+
created at: Sat May 27 16:04:13 JST 2006
|
9
|
+
|
10
|
+
Copyright (C) 2002-2006 Ruby-GNOME2 Project Team
|
11
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
12
|
+
|
13
|
+
**********************************************************************/
|
14
|
+
|
15
|
+
#include "rbgprivate.h"
|
16
|
+
|
17
|
+
VALUE rbgobj_mInterface;
|
18
|
+
VALUE mMetaInterface;
|
19
|
+
|
20
|
+
static VALUE
|
21
|
+
interface_s_append_features(self, klass)
|
22
|
+
VALUE self, klass;
|
23
|
+
{
|
24
|
+
if (!rb_obj_is_kind_of(klass, cInstantiatable))
|
25
|
+
rb_raise(rb_eTypeError, "Not a subclass of GLib::Instantiatable");
|
26
|
+
return rb_call_super(1, &klass);
|
27
|
+
}
|
28
|
+
|
29
|
+
#if GLIB_CHECK_VERSION(2,4,0)
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
interface_s_install_property(self, pspec_obj)
|
33
|
+
VALUE self, pspec_obj;
|
34
|
+
{
|
35
|
+
const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
|
36
|
+
gpointer ginterface;
|
37
|
+
GParamSpec* pspec;
|
38
|
+
|
39
|
+
if (cinfo->klass != self)
|
40
|
+
rb_raise(rb_eTypeError, "%s isn't registered class", rb_class2name(self));
|
41
|
+
|
42
|
+
pspec = G_PARAM_SPEC(RVAL2GOBJ(pspec_obj));
|
43
|
+
ginterface = g_type_default_interface_ref(cinfo->gtype);
|
44
|
+
g_object_interface_install_property(ginterface, pspec);
|
45
|
+
g_type_default_interface_unref(ginterface);
|
46
|
+
|
47
|
+
/* FIXME: define accessor methods */
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
interface_s_property(self, property_name)
|
53
|
+
VALUE self, property_name;
|
54
|
+
{
|
55
|
+
gpointer ginterface;
|
56
|
+
const char* name;
|
57
|
+
GParamSpec* prop;
|
58
|
+
VALUE result;
|
59
|
+
GType gtype = CLASS2GTYPE(self);
|
60
|
+
|
61
|
+
if (SYMBOL_P(property_name))
|
62
|
+
name = rb_id2name(SYM2ID(property_name));
|
63
|
+
else
|
64
|
+
name = StringValuePtr(property_name);
|
65
|
+
|
66
|
+
if (!G_TYPE_IS_INTERFACE(gtype))
|
67
|
+
rb_raise(rb_eTypeError, "%s isn't interface module", rb_class2name(self));
|
68
|
+
/* XXX: g_type_default_interface_ref(G_TYPE_INTERFACE) causes SEGV. */
|
69
|
+
if (gtype == G_TYPE_INTERFACE) {
|
70
|
+
rb_raise(rb_const_get(mGLib, rb_intern("NoPropertyError")),
|
71
|
+
"No such property: %s", name);
|
72
|
+
}
|
73
|
+
|
74
|
+
ginterface = g_type_default_interface_ref(gtype);
|
75
|
+
prop = g_object_interface_find_property(ginterface, name);
|
76
|
+
if (!prop){
|
77
|
+
g_type_default_interface_unref(ginterface);
|
78
|
+
rb_raise(rb_const_get(mGLib, rb_intern("NoPropertyError")),
|
79
|
+
"No such property: %s", name);
|
80
|
+
}
|
81
|
+
result = GOBJ2RVAL(prop);
|
82
|
+
g_type_default_interface_unref(ginterface);
|
83
|
+
|
84
|
+
return result;
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
interface_s_properties(int argc, VALUE* argv, VALUE self)
|
89
|
+
{
|
90
|
+
guint n_properties;
|
91
|
+
GParamSpec** props;
|
92
|
+
VALUE inherited_too;
|
93
|
+
VALUE ary = rb_ary_new();
|
94
|
+
int i;
|
95
|
+
gpointer ginterface;
|
96
|
+
GType gtype = CLASS2GTYPE(self);
|
97
|
+
|
98
|
+
if (rb_scan_args(argc, argv, "01", &inherited_too) == 0)
|
99
|
+
inherited_too = Qtrue;
|
100
|
+
|
101
|
+
if (!G_TYPE_IS_INTERFACE(gtype))
|
102
|
+
rb_raise(rb_eTypeError, "%s isn't interface module", rb_class2name(self));
|
103
|
+
/* XXX: g_type_default_interface_ref(G_TYPE_INTERFACE) causes SEGV. */
|
104
|
+
if (gtype == G_TYPE_INTERFACE) return ary;
|
105
|
+
|
106
|
+
ginterface = g_type_default_interface_ref(gtype);
|
107
|
+
props = g_object_interface_list_properties(ginterface, &n_properties);
|
108
|
+
for (i = 0; i < n_properties; i++){
|
109
|
+
if (RVAL2CBOOL(inherited_too) || GTYPE2CLASS(props[i]->owner_type) == self)
|
110
|
+
rb_ary_push(ary, rb_str_new2(props[i]->name));
|
111
|
+
}
|
112
|
+
g_free(props);
|
113
|
+
g_type_default_interface_unref(ginterface);
|
114
|
+
|
115
|
+
return ary;
|
116
|
+
}
|
117
|
+
|
118
|
+
#endif
|
119
|
+
|
120
|
+
void
|
121
|
+
rbgobj_init_interface(VALUE interf)
|
122
|
+
{
|
123
|
+
static VALUE rb_mGLibInterface = Qnil;
|
124
|
+
|
125
|
+
rb_extend_object(interf, mMetaInterface);
|
126
|
+
if (CLASS2GTYPE(interf) == G_TYPE_INTERFACE) {
|
127
|
+
rb_mGLibInterface = interf;
|
128
|
+
} else {
|
129
|
+
rb_extend_object(interf, rb_mGLibInterface);
|
130
|
+
rb_include_module(interf, rb_mGLibInterface);
|
131
|
+
rbgobj_define_property_accessors(interf);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
void
|
136
|
+
Init_gobject_typeinterface()
|
137
|
+
{
|
138
|
+
mMetaInterface = rb_define_module_under(mGLib, "MetaInterface");
|
139
|
+
rb_define_method(mMetaInterface, "gtype", generic_s_gtype, 0);
|
140
|
+
rb_define_method(mMetaInterface, "append_features", interface_s_append_features, 1);
|
141
|
+
#if GLIB_CHECK_VERSION(2,4,0)
|
142
|
+
rb_define_method(mMetaInterface, "install_property", interface_s_install_property, 1);
|
143
|
+
rb_define_method(mMetaInterface, "property", interface_s_property, 1);
|
144
|
+
rb_define_method(mMetaInterface, "properties", interface_s_properties, -1);
|
145
|
+
#endif
|
146
|
+
|
147
|
+
rbgobj_mInterface = G_DEF_INTERFACE(G_TYPE_INTERFACE, "Interface", mGLib);
|
148
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_typemodule.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 14:27:07 $
|
8
|
+
created at: Sat Jul 27 16:56:01 JST 2002
|
9
|
+
|
10
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
11
|
+
|
12
|
+
**********************************************************************/
|
13
|
+
|
14
|
+
#include "rbgprivate.h"
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
use(self)
|
18
|
+
VALUE self;
|
19
|
+
{
|
20
|
+
return CBOOL2RVAL(g_type_module_use(G_TYPE_MODULE(RVAL2GOBJ(self))));
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
unuse(self)
|
25
|
+
VALUE self;
|
26
|
+
{
|
27
|
+
g_type_module_unuse(G_TYPE_MODULE(RVAL2GOBJ(self)));
|
28
|
+
return self;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
get_name(self)
|
33
|
+
VALUE self;
|
34
|
+
{
|
35
|
+
return rb_str_new2(G_TYPE_MODULE(RVAL2GOBJ(self))->name);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
set_name(self, name)
|
40
|
+
VALUE self, name;
|
41
|
+
{
|
42
|
+
g_type_module_set_name(G_TYPE_MODULE(RVAL2GOBJ(self)), StringValuePtr(name));
|
43
|
+
return name;
|
44
|
+
}
|
45
|
+
|
46
|
+
#if 0
|
47
|
+
GType g_type_module_register_type (GTypeModule *module,
|
48
|
+
GType parent_type,
|
49
|
+
const gchar *type_name,
|
50
|
+
const GTypeInfo *type_info,
|
51
|
+
GTypeFlags flags);
|
52
|
+
void g_type_module_add_interface (GTypeModule *module,
|
53
|
+
GType instance_type,
|
54
|
+
GType interface_type,
|
55
|
+
const GInterfaceInfo *interface_info);
|
56
|
+
#endif
|
57
|
+
|
58
|
+
void
|
59
|
+
Init_gobject_gtypemodule()
|
60
|
+
{
|
61
|
+
VALUE cTypeModule = G_DEF_CLASS(G_TYPE_TYPE_MODULE, "TypeModule", mGLib);
|
62
|
+
rb_define_method(cTypeModule, "use", use, 0);
|
63
|
+
rb_define_method(cTypeModule, "unuse", unuse, 0);
|
64
|
+
rb_define_method(cTypeModule, "name", get_name, 0);
|
65
|
+
rb_define_method(cTypeModule, "name=", set_name, 1);
|
66
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_typeplugin.c -
|
5
|
+
|
6
|
+
$Author: mutoh $
|
7
|
+
$Date: 2003/02/01 16:03:09 $
|
8
|
+
created at: Mon Aug 5 00:42:09 JST 2002
|
9
|
+
|
10
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
11
|
+
|
12
|
+
**********************************************************************/
|
13
|
+
|
14
|
+
#include "rbgprivate.h"
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
use(self)
|
18
|
+
VALUE self;
|
19
|
+
{
|
20
|
+
g_type_plugin_use(G_TYPE_PLUGIN(RVAL2GOBJ(self)));
|
21
|
+
return self;
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE
|
25
|
+
unuse(self)
|
26
|
+
VALUE self;
|
27
|
+
{
|
28
|
+
g_type_plugin_unuse(G_TYPE_PLUGIN(RVAL2GOBJ(self)));
|
29
|
+
return self;
|
30
|
+
}
|
31
|
+
|
32
|
+
#if 0
|
33
|
+
void g_type_plugin_complete_type_info (GTypePlugin *plugin,
|
34
|
+
GType g_type,
|
35
|
+
GTypeInfo *info,
|
36
|
+
GTypeValueTable *value_table);
|
37
|
+
void g_type_plugin_complete_interface_info (GTypePlugin *plugin,
|
38
|
+
GType interface_type,
|
39
|
+
GType instance_type,
|
40
|
+
GInterfaceInfo *info);
|
41
|
+
#endif
|
42
|
+
|
43
|
+
void
|
44
|
+
Init_gobject_gtypeplugin()
|
45
|
+
{
|
46
|
+
VALUE iTypePlugin = G_DEF_INTERFACE(G_TYPE_TYPE_PLUGIN, "TypePlugin", mGLib);
|
47
|
+
rb_define_method(iTypePlugin, "use", use, 0);
|
48
|
+
rb_define_method(iTypePlugin, "unuse", unuse, 0);
|
49
|
+
}
|
data/src/rbgobj_value.c
ADDED
@@ -0,0 +1,313 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_value.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 16:07:28 $
|
8
|
+
|
9
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
10
|
+
|
11
|
+
**********************************************************************/
|
12
|
+
|
13
|
+
#include "rbgprivate.h"
|
14
|
+
|
15
|
+
/**********************************************************************/
|
16
|
+
|
17
|
+
static ID id_to_s;
|
18
|
+
static GQuark qRValueToGValueFunc;
|
19
|
+
static GQuark qGValueToRValueFunc;
|
20
|
+
|
21
|
+
void
|
22
|
+
rbgobj_register_r2g_func(GType gtype, RValueToGValueFunc func)
|
23
|
+
{
|
24
|
+
g_type_set_qdata(gtype, qRValueToGValueFunc, func);
|
25
|
+
}
|
26
|
+
|
27
|
+
void
|
28
|
+
rbgobj_register_g2r_func(GType gtype, GValueToRValueFunc func)
|
29
|
+
{
|
30
|
+
g_type_set_qdata(gtype, qGValueToRValueFunc, func);
|
31
|
+
}
|
32
|
+
|
33
|
+
/**********************************************************************/
|
34
|
+
|
35
|
+
VALUE
|
36
|
+
rbgobj_gvalue_to_rvalue(const GValue* value)
|
37
|
+
{
|
38
|
+
GType type, fundamental_type;
|
39
|
+
VALUE rvalue;
|
40
|
+
|
41
|
+
if (!value)
|
42
|
+
return Qnil;
|
43
|
+
|
44
|
+
type = G_VALUE_TYPE(value);
|
45
|
+
if (rbgobj_convert_gvalue2rvalue(type, value, &rvalue))
|
46
|
+
return rvalue;
|
47
|
+
|
48
|
+
fundamental_type = G_TYPE_FUNDAMENTAL(type);
|
49
|
+
switch (fundamental_type) {
|
50
|
+
case G_TYPE_NONE:
|
51
|
+
return Qnil;
|
52
|
+
case G_TYPE_CHAR:
|
53
|
+
return CHR2FIX(g_value_get_char(value));
|
54
|
+
case G_TYPE_UCHAR:
|
55
|
+
return INT2FIX(g_value_get_uchar(value));
|
56
|
+
case G_TYPE_BOOLEAN:
|
57
|
+
return CBOOL2RVAL(g_value_get_boolean(value));
|
58
|
+
case G_TYPE_INT:
|
59
|
+
return INT2NUM(g_value_get_int(value));
|
60
|
+
case G_TYPE_UINT:
|
61
|
+
return UINT2NUM(g_value_get_uint(value));
|
62
|
+
case G_TYPE_LONG:
|
63
|
+
return LONG2NUM(g_value_get_long(value));
|
64
|
+
case G_TYPE_ULONG:
|
65
|
+
return ULONG2NUM(g_value_get_ulong(value));
|
66
|
+
case G_TYPE_INT64:
|
67
|
+
return rbglib_int64_to_num(g_value_get_int64(value));
|
68
|
+
case G_TYPE_UINT64:
|
69
|
+
return rbglib_uint64_to_num(g_value_get_uint64(value));
|
70
|
+
case G_TYPE_FLOAT:
|
71
|
+
return rb_float_new(g_value_get_float(value));
|
72
|
+
case G_TYPE_DOUBLE:
|
73
|
+
return rb_float_new(g_value_get_double(value));
|
74
|
+
case G_TYPE_STRING:
|
75
|
+
{
|
76
|
+
const char* str = g_value_get_string(value);
|
77
|
+
return str ? rb_str_new2(str) : Qnil;
|
78
|
+
}
|
79
|
+
case G_TYPE_ENUM:
|
80
|
+
return rbgobj_make_enum(g_value_get_enum(value), type);
|
81
|
+
case G_TYPE_FLAGS:
|
82
|
+
return rbgobj_make_flags(g_value_get_flags(value), type);
|
83
|
+
case G_TYPE_OBJECT:
|
84
|
+
case G_TYPE_INTERFACE:
|
85
|
+
{
|
86
|
+
GObject* gobj = g_value_get_object(value);
|
87
|
+
return gobj ? GOBJ2RVAL(gobj) : Qnil;
|
88
|
+
}
|
89
|
+
case G_TYPE_PARAM:
|
90
|
+
{
|
91
|
+
GParamSpec* pspec = g_value_get_param(value);
|
92
|
+
return pspec ? rbgobj_ruby_object_from_instance(pspec) : Qnil;
|
93
|
+
}
|
94
|
+
case G_TYPE_POINTER:
|
95
|
+
{
|
96
|
+
gpointer ptr = g_value_get_pointer(value);
|
97
|
+
if (!ptr)
|
98
|
+
return Qnil;
|
99
|
+
else
|
100
|
+
return rbgobj_ptr_new(type, ptr);
|
101
|
+
}
|
102
|
+
|
103
|
+
case G_TYPE_BOXED:
|
104
|
+
{
|
105
|
+
GType gtype;
|
106
|
+
for (gtype = type;
|
107
|
+
gtype != G_TYPE_INVALID;
|
108
|
+
gtype = g_type_parent(gtype))
|
109
|
+
{
|
110
|
+
GValueToRValueFunc func =
|
111
|
+
g_type_get_qdata(gtype, qGValueToRValueFunc);
|
112
|
+
if (!func)
|
113
|
+
continue;
|
114
|
+
return func(value);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
default:
|
118
|
+
if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) {
|
119
|
+
GValueToRValueFunc func;
|
120
|
+
func = g_type_get_qdata(type, qGValueToRValueFunc);
|
121
|
+
if (!func) {
|
122
|
+
g_warning("rbgobj_gvalue_to_rvalue: unsupported type: %s\n",
|
123
|
+
g_type_name(type));
|
124
|
+
} else {
|
125
|
+
rvalue = func(value);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return rvalue;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
void
|
133
|
+
rbgobj_initialize_gvalue(GValue *result, VALUE value)
|
134
|
+
{
|
135
|
+
GType type;
|
136
|
+
|
137
|
+
type = rbgobj_convert_rvalue2gtype(value);
|
138
|
+
if (type == 0) {
|
139
|
+
switch (TYPE(value)) {
|
140
|
+
case T_NONE:
|
141
|
+
case T_NIL:
|
142
|
+
type = G_TYPE_NONE;
|
143
|
+
break;
|
144
|
+
case T_FLOAT:
|
145
|
+
type = G_TYPE_DOUBLE;
|
146
|
+
break;
|
147
|
+
case T_STRING:
|
148
|
+
case T_SYMBOL:
|
149
|
+
type = G_TYPE_STRING;
|
150
|
+
break;
|
151
|
+
case T_FIXNUM:
|
152
|
+
type = G_TYPE_INT;
|
153
|
+
break;
|
154
|
+
case T_BIGNUM:
|
155
|
+
type = G_TYPE_INT64;
|
156
|
+
break;
|
157
|
+
case T_TRUE:
|
158
|
+
case T_FALSE:
|
159
|
+
type = G_TYPE_BOOLEAN;
|
160
|
+
break;
|
161
|
+
default:
|
162
|
+
if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cEnum))) {
|
163
|
+
type = G_TYPE_ENUM;
|
164
|
+
}
|
165
|
+
else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cFlags))) {
|
166
|
+
type = G_TYPE_FLAGS;
|
167
|
+
}
|
168
|
+
else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cBoxed))) {
|
169
|
+
type = G_TYPE_BOXED;
|
170
|
+
}
|
171
|
+
else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cParam))) {
|
172
|
+
type = G_TYPE_PARAM;
|
173
|
+
}
|
174
|
+
else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cObject))) {
|
175
|
+
type = G_TYPE_OBJECT;
|
176
|
+
}
|
177
|
+
else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_mInterface))) {
|
178
|
+
/* should use rbgobj_mMetaInterface? */
|
179
|
+
type = G_TYPE_INTERFACE;
|
180
|
+
}
|
181
|
+
else {
|
182
|
+
VALUE inspected_value;
|
183
|
+
inspected_value = rb_funcall(value, rb_intern("inspect"), 0);
|
184
|
+
rb_raise(rb_eArgError,
|
185
|
+
"unsupported value type: %s",
|
186
|
+
RSTRING_PTR(inspected_value));
|
187
|
+
}
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
g_value_init(result, type);
|
193
|
+
rbgobj_rvalue_to_gvalue(value, result);
|
194
|
+
}
|
195
|
+
|
196
|
+
void
|
197
|
+
rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
|
198
|
+
{
|
199
|
+
GType type, fundamental_type;
|
200
|
+
|
201
|
+
type = G_VALUE_TYPE(result);
|
202
|
+
if (rbgobj_convert_rvalue2gvalue(type, val, result))
|
203
|
+
return;
|
204
|
+
|
205
|
+
fundamental_type = G_TYPE_FUNDAMENTAL(type);
|
206
|
+
switch (fundamental_type) {
|
207
|
+
case G_TYPE_NONE:
|
208
|
+
return;
|
209
|
+
case G_TYPE_CHAR:
|
210
|
+
g_value_set_char(result, NUM2INT(val));
|
211
|
+
return;
|
212
|
+
case G_TYPE_UCHAR:
|
213
|
+
g_value_set_uchar(result, NUM2UINT(val));
|
214
|
+
return;
|
215
|
+
case G_TYPE_BOOLEAN:
|
216
|
+
g_value_set_boolean(result, RVAL2CBOOL(val));
|
217
|
+
return;
|
218
|
+
case G_TYPE_INT:
|
219
|
+
g_value_set_int(result, NUM2INT(val));
|
220
|
+
return;
|
221
|
+
case G_TYPE_UINT:
|
222
|
+
g_value_set_uint(result, NUM2UINT(val));
|
223
|
+
return;
|
224
|
+
case G_TYPE_LONG:
|
225
|
+
g_value_set_long(result, NUM2LONG(val));
|
226
|
+
return;
|
227
|
+
case G_TYPE_ULONG:
|
228
|
+
g_value_set_ulong(result, NUM2ULONG(val));
|
229
|
+
return;
|
230
|
+
case G_TYPE_INT64:
|
231
|
+
g_value_set_int64(result, rbglib_num_to_int64(val));
|
232
|
+
return;
|
233
|
+
case G_TYPE_UINT64:
|
234
|
+
g_value_set_uint64(result, rbglib_num_to_uint64(val));
|
235
|
+
return;
|
236
|
+
case G_TYPE_ENUM:
|
237
|
+
g_value_set_enum(result, rbgobj_get_enum(val, G_VALUE_TYPE(result)));
|
238
|
+
return;
|
239
|
+
case G_TYPE_FLAGS:
|
240
|
+
g_value_set_flags(result, rbgobj_get_flags(val, G_VALUE_TYPE(result)));
|
241
|
+
return;
|
242
|
+
case G_TYPE_FLOAT:
|
243
|
+
g_value_set_float(result, NUM2DBL(val));
|
244
|
+
return;
|
245
|
+
case G_TYPE_DOUBLE:
|
246
|
+
g_value_set_double(result, NUM2DBL(val));
|
247
|
+
return;
|
248
|
+
case G_TYPE_STRING:
|
249
|
+
{
|
250
|
+
if (SYMBOL_P(val))
|
251
|
+
val = rb_funcall(val, id_to_s, 0);
|
252
|
+
g_value_set_string(result, NIL_P(val) ? NULL : StringValuePtr(val));
|
253
|
+
return;
|
254
|
+
}
|
255
|
+
case G_TYPE_OBJECT:
|
256
|
+
case G_TYPE_INTERFACE:
|
257
|
+
g_value_set_object(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
|
258
|
+
return;
|
259
|
+
case G_TYPE_PARAM:
|
260
|
+
g_value_set_param(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
|
261
|
+
return;
|
262
|
+
case G_TYPE_POINTER:
|
263
|
+
g_value_set_pointer(result, NIL_P(val) ? NULL : rbgobj_ptr2cptr(val));
|
264
|
+
return;
|
265
|
+
case G_TYPE_BOXED:
|
266
|
+
{
|
267
|
+
GType gtype;
|
268
|
+
for (gtype = type;
|
269
|
+
gtype != G_TYPE_INVALID;
|
270
|
+
gtype = g_type_parent(gtype))
|
271
|
+
{
|
272
|
+
RValueToGValueFunc func =
|
273
|
+
g_type_get_qdata(gtype, qRValueToGValueFunc);
|
274
|
+
if (!func)
|
275
|
+
continue;
|
276
|
+
func(val, result);
|
277
|
+
return;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
default:
|
282
|
+
if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) {
|
283
|
+
RValueToGValueFunc func =
|
284
|
+
g_type_get_qdata(type, qRValueToGValueFunc);
|
285
|
+
if (!func){
|
286
|
+
g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n",
|
287
|
+
g_type_name(type));
|
288
|
+
} else {
|
289
|
+
func(val, result);
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
/**********************************************************************/
|
296
|
+
|
297
|
+
void
|
298
|
+
rbgobj_gc_mark_gvalue(GValue* value)
|
299
|
+
{
|
300
|
+
GType gtype = G_VALUE_TYPE(value);
|
301
|
+
/* FIXME */
|
302
|
+
if (G_TYPE_FUNDAMENTAL(gtype) == G_TYPE_OBJECT)
|
303
|
+
rbgobj_gc_mark_instance(g_value_get_object(value));
|
304
|
+
}
|
305
|
+
|
306
|
+
/**********************************************************************/
|
307
|
+
|
308
|
+
void Init_gobject_gvalue()
|
309
|
+
{
|
310
|
+
id_to_s = rb_intern("to_s");
|
311
|
+
qRValueToGValueFunc = g_quark_from_static_string("__ruby_r2g_func__");
|
312
|
+
qGValueToRValueFunc = g_quark_from_static_string("__ruby_g2r_func__");
|
313
|
+
}
|