gobject-introspection 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/Rakefile +50 -0
  2. data/ext/gobject-introspection/extconf.rb +97 -0
  3. data/ext/gobject-introspection/rb-gi-arg-info.c +151 -0
  4. data/ext/gobject-introspection/rb-gi-argument.c +223 -0
  5. data/ext/gobject-introspection/rb-gi-base-info.c +218 -0
  6. data/ext/gobject-introspection/rb-gi-boxed-info.c +48 -0
  7. data/ext/gobject-introspection/rb-gi-callable-info.c +124 -0
  8. data/ext/gobject-introspection/rb-gi-callback-info.c +48 -0
  9. data/ext/gobject-introspection/rb-gi-constant-info.c +77 -0
  10. data/ext/gobject-introspection/rb-gi-constructor-info.c +82 -0
  11. data/ext/gobject-introspection/rb-gi-conversions.h +95 -0
  12. data/ext/gobject-introspection/rb-gi-enum-info.c +145 -0
  13. data/ext/gobject-introspection/rb-gi-field-info.c +149 -0
  14. data/ext/gobject-introspection/rb-gi-flags-info.c +48 -0
  15. data/ext/gobject-introspection/rb-gi-function-info.c +199 -0
  16. data/ext/gobject-introspection/rb-gi-interface-info.c +222 -0
  17. data/ext/gobject-introspection/rb-gi-loader.c +61 -0
  18. data/ext/gobject-introspection/rb-gi-method-info.c +66 -0
  19. data/ext/gobject-introspection/rb-gi-object-info.c +345 -0
  20. data/ext/gobject-introspection/rb-gi-property-info.c +77 -0
  21. data/ext/gobject-introspection/rb-gi-registered-type-info.c +86 -0
  22. data/ext/gobject-introspection/rb-gi-repository.c +164 -0
  23. data/ext/gobject-introspection/rb-gi-signal-info.c +77 -0
  24. data/ext/gobject-introspection/rb-gi-struct-info.c +183 -0
  25. data/ext/gobject-introspection/rb-gi-type-info.c +143 -0
  26. data/ext/gobject-introspection/rb-gi-type-tag.c +43 -0
  27. data/ext/gobject-introspection/rb-gi-types.h +71 -0
  28. data/ext/gobject-introspection/rb-gi-union-info.c +206 -0
  29. data/ext/gobject-introspection/rb-gi-unresolved-info.c +48 -0
  30. data/ext/gobject-introspection/rb-gi-value-info.c +57 -0
  31. data/ext/gobject-introspection/rb-gi-vfunc-info.c +91 -0
  32. data/ext/gobject-introspection/rb-gobject-introspection.c +42 -0
  33. data/ext/gobject-introspection/rb-gobject-introspection.h +105 -0
  34. data/extconf.rb +71 -0
  35. data/lib/gobject-introspection.rb +39 -0
  36. data/lib/gobject-introspection/collection-reader.rb +34 -0
  37. data/lib/gobject-introspection/loader.rb +148 -0
  38. data/lib/gobject-introspection/object-info.rb +33 -0
  39. data/lib/gobject-introspection/repository.rb +32 -0
  40. data/lib/gobject-introspection/struct-info.rb +28 -0
  41. data/sample/clutter-basic-actor.rb +132 -0
  42. data/sample/clutter.rb +29 -0
  43. data/test/gobject-introspection-test-utils.rb +26 -0
  44. data/test/run-test.rb +45 -0
  45. data/test/test-arg-info.rb +68 -0
  46. data/test/test-base-info.rb +31 -0
  47. data/test/test-boxed-info.rb +21 -0
  48. data/test/test-callable-info.rb +49 -0
  49. data/test/test-callback-info.rb +29 -0
  50. data/test/test-constant-info.rb +24 -0
  51. data/test/test-enum-info.rb +56 -0
  52. data/test/test-field-type.rb +42 -0
  53. data/test/test-flags-info.rb +27 -0
  54. data/test/test-function-info.rb +37 -0
  55. data/test/test-interface-info.rb +97 -0
  56. data/test/test-loader.rb +30 -0
  57. data/test/test-object-info.rb +131 -0
  58. data/test/test-property-info.rb +38 -0
  59. data/test/test-registered-type-info.rb +35 -0
  60. data/test/test-repository.rb +59 -0
  61. data/test/test-signal-info.rb +37 -0
  62. data/test/test-struct-info.rb +57 -0
  63. data/test/test-type-info.rb +62 -0
  64. data/test/test-type-tag.rb +29 -0
  65. data/test/test-union-info.rb +21 -0
  66. data/test/test-value-info.rb +28 -0
  67. data/test/test-vfunc-info.rb +42 -0
  68. metadata +162 -0
@@ -0,0 +1,77 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIPropertyInfo
24
+ #define SELF(self) RVAL2GI_BASE_INFO(self)
25
+
26
+ GType
27
+ gi_property_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GIPropertyInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_flags(VALUE self)
40
+ {
41
+ GIPropertyInfo *info;
42
+
43
+ info = SELF(self);
44
+ return INT2NUM(g_property_info_get_flags(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_type(VALUE self)
49
+ {
50
+ GIPropertyInfo *info;
51
+
52
+ info = SELF(self);
53
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_property_info_get_type(info));
54
+ }
55
+
56
+ static VALUE
57
+ rg_ownership_transfer(VALUE self)
58
+ {
59
+ GIPropertyInfo *info;
60
+
61
+ info = SELF(self);
62
+ return GI_TRANSFER2RVAL(g_property_info_get_ownership_transfer(info));
63
+ }
64
+
65
+ void
66
+ rb_gi_property_info_init(VALUE rb_mGI, VALUE rb_cGICallableInfo)
67
+ {
68
+ VALUE RG_TARGET_NAMESPACE;
69
+
70
+ RG_TARGET_NAMESPACE =
71
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_PROPERTY_INFO, "PropertyInfo", rb_mGI,
72
+ rb_cGICallableInfo);
73
+
74
+ RG_DEF_METHOD(flags, 0);
75
+ RG_DEF_METHOD(type, 0);
76
+ RG_DEF_METHOD(ownership_transfer, 0);
77
+ }
@@ -0,0 +1,86 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIRegisteredTypeInfo
24
+ #define SELF(self) (RVAL2GI_REGISTERED_TYPE_INFO(self))
25
+
26
+ GType
27
+ gi_registered_type_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GIRegisteredTypeInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_type_name(VALUE self)
40
+ {
41
+ GIRegisteredTypeInfo *info;
42
+
43
+ info = SELF(self);
44
+ return CSTR2RVAL(g_registered_type_info_get_type_name(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_type_init(VALUE self)
49
+ {
50
+ GIRegisteredTypeInfo *info;
51
+
52
+ info = SELF(self);
53
+ return CSTR2RVAL(g_registered_type_info_get_type_init(info));
54
+ }
55
+
56
+ static VALUE
57
+ rg_gtype(VALUE self)
58
+ {
59
+ GIRegisteredTypeInfo *info;
60
+
61
+ info = SELF(self);
62
+ return rbgobj_gtype_new(g_registered_type_info_get_g_type(info));
63
+ }
64
+
65
+ void
66
+ rb_gi_registered_type_info_init(VALUE rb_mGI, VALUE rb_cGIBaseInfo)
67
+ {
68
+ VALUE RG_TARGET_NAMESPACE;
69
+
70
+ RG_TARGET_NAMESPACE =
71
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_REGISTERED_TYPE_INFO,
72
+ "RegisteredTypeInfo",
73
+ rb_mGI,
74
+ rb_cGIBaseInfo);
75
+
76
+ RG_DEF_METHOD(type_name, 0);
77
+ RG_DEF_METHOD(type_init, 0);
78
+ RG_DEF_METHOD(gtype, 0);
79
+
80
+ rb_gi_struct_info_init(rb_mGI, RG_TARGET_NAMESPACE);
81
+ rb_gi_boxed_info_init(rb_mGI, RG_TARGET_NAMESPACE);
82
+ rb_gi_enum_info_init(rb_mGI, RG_TARGET_NAMESPACE);
83
+ rb_gi_object_info_init(rb_mGI, RG_TARGET_NAMESPACE);
84
+ rb_gi_interface_info_init(rb_mGI, RG_TARGET_NAMESPACE);
85
+ rb_gi_union_info_init(rb_mGI, RG_TARGET_NAMESPACE);
86
+ }
@@ -0,0 +1,164 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIRepository
24
+ #define SELF(self) RVAL2GI_REPOSITORY(self)
25
+
26
+ static VALUE
27
+ rg_s_default(G_GNUC_UNUSED VALUE klass)
28
+ {
29
+ return GOBJ2RVAL(g_irepository_get_default());
30
+ }
31
+
32
+ static VALUE
33
+ rg_require(int argc, VALUE *argv, VALUE self)
34
+ {
35
+ VALUE rb_namespace, rb_version, rb_flags;
36
+ const gchar *namespace_, *version;
37
+ GIRepositoryLoadFlags flags = 0;
38
+ GError *error = NULL;
39
+
40
+ rb_scan_args(argc, argv, "12", &rb_namespace, &rb_version, &rb_flags);
41
+
42
+ namespace_ = RVAL2CSTR(rb_namespace);
43
+ version = RVAL2CSTR_ACCEPT_NIL(rb_version);
44
+ if (!NIL_P(rb_flags)) {
45
+ flags = RVAL2GI_REPOSITORY_LOAD_FLAGS(rb_flags);
46
+ }
47
+
48
+ g_irepository_require(SELF(self), namespace_, version, flags, &error);
49
+ if (error) {
50
+ RG_RAISE_ERROR(error);
51
+ }
52
+
53
+ return Qnil;
54
+ }
55
+
56
+ static VALUE
57
+ rg_get_dependencies(VALUE self, VALUE rb_namespace)
58
+ {
59
+ GIRepository *repository;
60
+ const gchar *namespace_;
61
+ VALUE rb_dependencies;
62
+ gchar **dependencies;
63
+ gint i;
64
+
65
+ repository = SELF(self);
66
+ namespace_ = RVAL2CSTR(rb_namespace);
67
+ dependencies = g_irepository_get_dependencies(repository, namespace_);
68
+ rb_dependencies = rb_ary_new();
69
+ for (i = 0; dependencies[i]; i++) {
70
+ rb_ary_push(rb_dependencies, CSTR2RVAL(dependencies[i]));
71
+ }
72
+ g_strfreev(dependencies);
73
+
74
+ return rb_dependencies;
75
+ }
76
+
77
+ static VALUE
78
+ rg_loaded_namespaces(VALUE self)
79
+ {
80
+ GIRepository *repository;
81
+ VALUE rb_namespaces;
82
+ gchar **namespaces;
83
+ gint i;
84
+
85
+ repository = SELF(self);
86
+ namespaces = g_irepository_get_loaded_namespaces(repository);
87
+ rb_namespaces = rb_ary_new();
88
+ for (i = 0; namespaces[i]; i++) {
89
+ rb_ary_push(rb_namespaces, CSTR2RVAL(namespaces[i]));
90
+ }
91
+ g_strfreev(namespaces);
92
+
93
+ return rb_namespaces;
94
+ }
95
+
96
+ static VALUE
97
+ rg_get_n_infos(VALUE self, VALUE rb_namespace)
98
+ {
99
+ const gchar *namespace_;
100
+ gint n_infos;
101
+
102
+ namespace_ = RVAL2CSTR(rb_namespace);
103
+ n_infos = g_irepository_get_n_infos(SELF(self), namespace_);
104
+
105
+ return INT2NUM(n_infos);
106
+ }
107
+
108
+ static VALUE
109
+ rg_get_info(VALUE self, VALUE rb_namespace, VALUE rb_n)
110
+ {
111
+ GIRepository *repository;
112
+ const gchar *namespace_;
113
+ gint n;
114
+ GIBaseInfo *info;
115
+
116
+ repository = SELF(self);
117
+ namespace_ = RVAL2CSTR(rb_namespace);
118
+ n = NUM2INT(rb_n);
119
+ info = g_irepository_get_info(repository, namespace_, n);
120
+ return GI_BASE_INFO2RVAL_WITH_UNREF(info);
121
+ }
122
+
123
+ static VALUE
124
+ rg_find(int argc, VALUE *argv, VALUE self)
125
+ {
126
+ GIBaseInfo *info;
127
+
128
+ if (argc == 1) {
129
+ VALUE rb_gtype;
130
+ GType gtype;
131
+ rb_gtype = argv[0];
132
+ gtype = NUM2UINT(rb_gtype);
133
+ info = g_irepository_find_by_gtype(SELF(self), gtype);
134
+ } else {
135
+ VALUE rb_namespace, rb_name;
136
+ const gchar *namespace_, *name;
137
+
138
+ rb_scan_args(argc, argv, "2", &rb_namespace, &rb_name);
139
+ namespace_ = RVAL2CSTR(rb_namespace);
140
+ name = RVAL2CSTR(rb_name);
141
+ info = g_irepository_find_by_name(SELF(self), namespace_, name);
142
+ }
143
+
144
+ return GI_BASE_INFO2RVAL(info);
145
+ }
146
+
147
+ void
148
+ rb_gi_repository_init(VALUE rb_mGI)
149
+ {
150
+ VALUE RG_TARGET_NAMESPACE;
151
+
152
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_IREPOSITORY, "Repository", rb_mGI);
153
+
154
+ RG_DEF_SMETHOD(default, 0);
155
+ RG_DEF_METHOD(require, -1);
156
+ RG_DEF_METHOD(get_dependencies, 1);
157
+ RG_DEF_METHOD(loaded_namespaces, 0);
158
+ RG_DEF_METHOD(get_n_infos, 1);
159
+ RG_DEF_METHOD(get_info, 2);
160
+ RG_DEF_METHOD(find, -1);
161
+
162
+ G_DEF_CLASS(G_TYPE_I_REPOSITORY_LOAD_FLAGS, "RepositoryLoadFlags", rb_mGI);
163
+ G_DEF_CLASS(G_TYPE_I_REPOSITORY_ERROR, "RepositoryError", rb_mGI);
164
+ }
@@ -0,0 +1,77 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGISignalInfo
24
+ #define SELF(self) RVAL2GI_BASE_INFO(self)
25
+
26
+ GType
27
+ gi_signal_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GISignalInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_flags(VALUE self)
40
+ {
41
+ GISignalInfo *info;
42
+
43
+ info = SELF(self);
44
+ return GI_SIGNAL_FLAGS2RVAL(g_signal_info_get_flags(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_class_closure(VALUE self)
49
+ {
50
+ GISignalInfo *info;
51
+
52
+ info = SELF(self);
53
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_signal_info_get_class_closure(info));
54
+ }
55
+
56
+ static VALUE
57
+ rg_true_stops_emit_p(VALUE self)
58
+ {
59
+ GISignalInfo *info;
60
+
61
+ info = SELF(self);
62
+ return CBOOL2RVAL(g_signal_info_true_stops_emit(info));
63
+ }
64
+
65
+ void
66
+ rb_gi_signal_info_init(VALUE rb_mGI, VALUE rb_cGICallableInfo)
67
+ {
68
+ VALUE RG_TARGET_NAMESPACE;
69
+
70
+ RG_TARGET_NAMESPACE =
71
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_SIGNAL_INFO, "SignalInfo", rb_mGI,
72
+ rb_cGICallableInfo);
73
+
74
+ RG_DEF_METHOD(flags, 0);
75
+ RG_DEF_METHOD(class_closure, 0);
76
+ RG_DEF_METHOD_P(true_stops_emit, 0);
77
+ }
@@ -0,0 +1,183 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIStructInfo
24
+ #define SELF(self) (RVAL2GI_STRUCT_INFO(self))
25
+
26
+ GType
27
+ gi_struct_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GIStructInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_n_fields(VALUE self)
40
+ {
41
+ GIStructInfo *info;
42
+
43
+ info = SELF(self);
44
+ return INT2NUM(g_struct_info_get_n_fields(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_get_field(VALUE self, VALUE rb_n)
49
+ {
50
+ GIStructInfo *info;
51
+ gint n;
52
+
53
+ info = SELF(self);
54
+ n = NUM2INT(rb_n);
55
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_struct_info_get_field(info, n));
56
+ }
57
+
58
+ static VALUE
59
+ rg_get_field_value(VALUE self, VALUE rb_struct, VALUE rb_n)
60
+ {
61
+ GIStructInfo *info;
62
+ gint n;
63
+ GIFieldInfo *field_info;
64
+ GType gtype;
65
+ VALUE rb_value;
66
+
67
+ info = SELF(self);
68
+ n = NUM2INT(rb_n);
69
+ field_info = g_struct_info_get_field(info, n);
70
+ gtype = g_registered_type_info_get_g_type(info);
71
+ rb_value = rb_gi_field_info_get_field_raw(field_info,
72
+ RVAL2BOXED(rb_struct, gtype));
73
+ g_base_info_unref(field_info);
74
+
75
+ return rb_value;
76
+ }
77
+
78
+ static VALUE
79
+ rg_set_field_value(VALUE self, VALUE rb_struct, VALUE rb_n, VALUE rb_value)
80
+ {
81
+ GIStructInfo *info;
82
+ gint n;
83
+ GIFieldInfo *field_info;
84
+ GType gtype;
85
+
86
+ info = SELF(self);
87
+ n = NUM2INT(rb_n);
88
+ field_info = g_struct_info_get_field(info, n);
89
+ gtype = g_registered_type_info_get_g_type(info);
90
+ rb_gi_field_info_set_field_raw(field_info,
91
+ RVAL2BOXED(rb_struct, gtype),
92
+ rb_value);
93
+ /* TODO: use rb_ensure() to unref field_info. */
94
+ g_base_info_unref(field_info);
95
+
96
+ return Qnil;
97
+ }
98
+
99
+ static VALUE
100
+ rg_n_methods(VALUE self)
101
+ {
102
+ GIStructInfo *info;
103
+
104
+ info = SELF(self);
105
+ return INT2NUM(g_struct_info_get_n_methods(info));
106
+ }
107
+
108
+ static VALUE
109
+ rg_get_method(VALUE self, VALUE rb_n_or_name)
110
+ {
111
+ GIStructInfo *info;
112
+ GIFunctionInfo *function_info;
113
+
114
+ info = SELF(self);
115
+ if (RB_TYPE_P(rb_n_or_name, RUBY_T_FIXNUM)) {
116
+ gint n;
117
+ n = NUM2INT(rb_n_or_name);
118
+ function_info = g_struct_info_get_method(info, n);
119
+ } else {
120
+ const gchar *name;
121
+ name = RVAL2CSTR(rb_n_or_name);
122
+ function_info = g_struct_info_find_method(info, name);
123
+ }
124
+
125
+ return GI_BASE_INFO2RVAL_WITH_UNREF(function_info);
126
+ }
127
+
128
+ static VALUE
129
+ rg_size(VALUE self)
130
+ {
131
+ GIStructInfo *info;
132
+
133
+ info = SELF(self);
134
+ return UINT2NUM(g_struct_info_get_size(info));
135
+ }
136
+
137
+ static VALUE
138
+ rg_alignment(VALUE self)
139
+ {
140
+ GIStructInfo *info;
141
+
142
+ info = SELF(self);
143
+ return UINT2NUM(g_struct_info_get_alignment(info));
144
+ }
145
+
146
+ static VALUE
147
+ rg_gtype_struct_p(VALUE self)
148
+ {
149
+ GIStructInfo *info;
150
+
151
+ info = SELF(self);
152
+ return CBOOL2RVAL(g_struct_info_is_gtype_struct(info));
153
+ }
154
+
155
+ static VALUE
156
+ rg_foreign_p(VALUE self)
157
+ {
158
+ GIStructInfo *info;
159
+
160
+ info = SELF(self);
161
+ return CBOOL2RVAL(g_struct_info_is_foreign(info));
162
+ }
163
+
164
+ void
165
+ rb_gi_struct_info_init(VALUE rb_mGI, VALUE rb_cGIRegisteredTypeInfo)
166
+ {
167
+ VALUE RG_TARGET_NAMESPACE;
168
+
169
+ RG_TARGET_NAMESPACE =
170
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_STRUCT_INFO, "StructInfo", rb_mGI,
171
+ rb_cGIRegisteredTypeInfo);
172
+
173
+ RG_DEF_METHOD(n_fields, 0);
174
+ RG_DEF_METHOD(get_field, 1);
175
+ RG_DEF_METHOD(get_field_value, 2);
176
+ RG_DEF_METHOD(set_field_value, 3);
177
+ RG_DEF_METHOD(n_methods, 0);
178
+ RG_DEF_METHOD(get_method, 1);
179
+ RG_DEF_METHOD(size, 0);
180
+ RG_DEF_METHOD(alignment, 0);
181
+ RG_DEF_METHOD_P(gtype_struct, 0);
182
+ RG_DEF_METHOD_P(foreign, 0);
183
+ }