gobject-introspection 3.4.0 → 3.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gobject-introspection/extconf.rb +1 -4
  3. data/ext/gobject-introspection/rb-gi-argument.c +10 -3
  4. data/ext/gobject-introspection/rb-gi-arguments-in.c +82 -122
  5. data/ext/gobject-introspection/rb-gi-arguments-out.c +31 -11
  6. data/ext/gobject-introspection/rb-gi-arguments.c +217 -18
  7. data/ext/gobject-introspection/rb-gi-base-info.c +11 -1
  8. data/ext/gobject-introspection/rb-gi-callable-info.c +10 -2
  9. data/ext/gobject-introspection/rb-gi-callback.c +156 -2
  10. data/ext/gobject-introspection/rb-gi-conversions.h +6 -6
  11. data/ext/gobject-introspection/rb-gi-interface-info.c +1 -7
  12. data/ext/gobject-introspection/rb-gi-loader.c +58 -10
  13. data/ext/gobject-introspection/rb-gi-object-info.c +11 -1
  14. data/ext/gobject-introspection/rb-gi-private-arguments-in.h +3 -1
  15. data/ext/gobject-introspection/rb-gi-private-arguments.h +6 -2
  16. data/ext/gobject-introspection/rb-gi-private-callback.h +6 -3
  17. data/ext/gobject-introspection/rb-gi-private.h +1 -0
  18. data/ext/gobject-introspection/rb-gi-repository.c +1 -1
  19. data/ext/gobject-introspection/rb-gi-struct-info.c +15 -3
  20. data/ext/gobject-introspection/rb-gi-vfunc-info.c +2 -2
  21. data/ext/gobject-introspection/rb-gobject-introspection.c +231 -0
  22. data/lib/gobject-introspection/loader.rb +66 -2
  23. data/lib/gobject-introspection/type-tag.rb +2 -0
  24. data/test/gobject-introspection-test-utils.rb +2 -2
  25. data/test/run-test.rb +18 -25
  26. data/test/test-base-info.rb +5 -1
  27. data/test/test-callable-info.rb +16 -2
  28. data/test/test-loader.rb +53 -7
  29. data/test/test-object-info.rb +5 -1
  30. data/test/test-struct-info.rb +6 -1
  31. metadata +5 -8
  32. data/ext/gobject-introspection/gobject-introspection-enum-types.c +0 -230
  33. data/ext/gobject-introspection/gobject-introspection-enum-types.h +0 -42
  34. data/ext/gobject-introspection/rbgiversion.h +0 -24
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -160,6 +160,15 @@ rg_namespace(VALUE self)
160
160
  return CSTR2RVAL(g_base_info_get_namespace(info));
161
161
  }
162
162
 
163
+ static VALUE
164
+ rg_container(VALUE self)
165
+ {
166
+ GIBaseInfo *info;
167
+
168
+ info = SELF(self);
169
+ return rb_gi_base_info_to_ruby(g_base_info_get_container(info));
170
+ }
171
+
163
172
  static VALUE
164
173
  rg_operator_aref(VALUE self, VALUE name)
165
174
  {
@@ -201,6 +210,7 @@ rb_gi_base_info_init(VALUE rb_mGI)
201
210
  RG_DEF_METHOD(type, 0);
202
211
  RG_DEF_METHOD(name, 0);
203
212
  RG_DEF_METHOD(namespace, 0);
213
+ RG_DEF_METHOD(container, 0);
204
214
  RG_DEF_METHOD_OPERATOR("[]", aref, 1);
205
215
  RG_DEF_METHOD(each, 0);
206
216
 
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -21,7 +21,7 @@
21
21
  #include "rb-gi-private.h"
22
22
 
23
23
  #define RG_TARGET_NAMESPACE rb_cGICallableInfo
24
- #define SELF(self) ((GICallableInfo *)(RVAL2GI_BASE_INFO(self)))
24
+ #define SELF(self) RVAL2GI_CALLABLE_INFO(self)
25
25
 
26
26
  GType
27
27
  gi_callable_info_get_type(void)
@@ -35,6 +35,13 @@ gi_callable_info_get_type(void)
35
35
  return type;
36
36
  }
37
37
 
38
+ static VALUE
39
+ rg_can_throw_gerror_p(VALUE self)
40
+ {
41
+ GICallableInfo *info = SELF(self);
42
+ return CBOOL2RVAL(g_callable_info_can_throw_gerror(info));
43
+ }
44
+
38
45
  static VALUE
39
46
  rg_return_type(VALUE self)
40
47
  {
@@ -91,6 +98,7 @@ rb_gi_callable_info_init(VALUE rb_mGI, VALUE rb_cGIBaseInfo)
91
98
  G_DEF_CLASS_WITH_PARENT(GI_TYPE_CALLABLE_INFO, "CallableInfo", rb_mGI,
92
99
  rb_cGIBaseInfo);
93
100
 
101
+ RG_DEF_METHOD_P(can_throw_gerror, 0);
94
102
  RG_DEF_METHOD(return_type, 0);
95
103
  RG_DEF_METHOD(caller_owns, 0);
96
104
  RG_DEF_METHOD_P(may_return_null, 0);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -28,17 +28,171 @@ struct RBGICallbackData_ {
28
28
  VALUE rb_owner;
29
29
  };
30
30
 
31
+ typedef struct {
32
+ RBGIArguments *args;
33
+ RBGICallback *callback;
34
+ RBGICallbackData *callback_data;
35
+ void *return_value;
36
+ VALUE rb_return_value;
37
+ } RBGICallbackInvokeData;
38
+
31
39
  static GPtrArray *callback_finders;
32
40
  static VALUE mGLibObject = Qnil;
33
41
  static VALUE mGI = Qnil;
34
42
 
43
+ static VALUE
44
+ rb_gi_callback_invoke_without_protect(VALUE user_data)
45
+ {
46
+ RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
47
+ VALUE rb_args = rb_gi_arguments_in_to_ruby(data->args);
48
+
49
+ if (data->callback->method_name) {
50
+ ID id___send__;
51
+ VALUE rb_receiver = rb_ary_shift(rb_args);
52
+ CONST_ID(id___send__, "__send__");
53
+ rb_ary_unshift(rb_args, rb_str_new_cstr(data->callback->method_name));
54
+ data->rb_return_value =
55
+ rb_funcallv(rb_receiver,
56
+ id___send__,
57
+ RARRAY_LENINT(rb_args),
58
+ RARRAY_CONST_PTR(rb_args));
59
+ } else {
60
+ ID id_call;
61
+ CONST_ID(id_call, "call");
62
+ VALUE rb_callback =
63
+ rb_gi_callback_data_get_rb_callback(data->callback_data);
64
+ data->rb_return_value =
65
+ rb_funcallv(rb_callback,
66
+ id_call,
67
+ RARRAY_LENINT(rb_args),
68
+ RARRAY_CONST_PTR(rb_args));
69
+ }
70
+
71
+ return Qnil;
72
+ }
73
+
74
+ static VALUE
75
+ rb_gi_callback_invoke_fill_raw_results(VALUE user_data)
76
+ {
77
+ RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
78
+ rb_gi_arguments_fill_raw_results(data->args,
79
+ data->rb_return_value,
80
+ data->return_value);
81
+ return Qnil;
82
+ }
83
+
84
+ static VALUE
85
+ rb_gi_callback_invoke(VALUE user_data)
86
+ {
87
+ RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
88
+ int state = 0;
89
+ rb_protect(rb_gi_callback_invoke_without_protect,
90
+ user_data,
91
+ &state);
92
+ if (state != 0) {
93
+ VALUE error = rb_errinfo();
94
+ rb_gi_arguments_fill_raw_out_gerror(data->args, error);
95
+ rb_protect(rb_gi_callback_invoke_fill_raw_results,
96
+ user_data,
97
+ &state);
98
+ } else {
99
+ rb_protect(rb_gi_callback_invoke_fill_raw_results,
100
+ user_data,
101
+ &state);
102
+ if (state != 0) {
103
+ VALUE error = rb_errinfo();
104
+ rb_gi_arguments_fill_raw_out_gerror(data->args, error);
105
+ }
106
+ }
107
+ return Qnil;
108
+ }
109
+
110
+ static void
111
+ rb_gi_ffi_closure_callback(G_GNUC_UNUSED ffi_cif *cif,
112
+ void *return_value,
113
+ void **raw_args,
114
+ void *data)
115
+ {
116
+ RBGICallback *callback = data;
117
+ RBGICallbackData *callback_data = NULL;
118
+ RBGIArguments args;
119
+
120
+ rb_gi_arguments_init(&args,
121
+ callback->callback_info,
122
+ Qnil,
123
+ Qnil,
124
+ raw_args);
125
+ {
126
+ guint i;
127
+
128
+ for (i = 0; i < args.metadata->len; i++) {
129
+ RBGIArgMetadata *metadata;
130
+
131
+ metadata = g_ptr_array_index(args.metadata, i);
132
+ if (!metadata->closure_p) {
133
+ continue;
134
+ }
135
+
136
+ callback_data = *((RBGICallbackData **)(raw_args[i]));
137
+ break;
138
+ }
139
+
140
+ if (!callback_data && args.metadata->len > 0) {
141
+ RBGIArgMetadata *metadata;
142
+
143
+ i = args.metadata->len - 1;
144
+ metadata = g_ptr_array_index(args.metadata, i);
145
+ if (metadata->type.tag == GI_TYPE_TAG_VOID &&
146
+ metadata->type.pointer_p &&
147
+ strcmp(metadata->name, "data") == 0) {
148
+ callback_data = *((RBGICallbackData **)(raw_args[i]));
149
+ }
150
+ }
151
+ }
152
+
153
+ {
154
+ RBGICallbackInvokeData data;
155
+ data.args = &args;
156
+ data.callback = callback;
157
+ data.callback_data = callback_data;
158
+ data.return_value = return_value;
159
+ data.rb_return_value = Qnil;
160
+ rbgutil_invoke_callback(rb_gi_callback_invoke, (VALUE)&data);
161
+ }
162
+ rb_gi_arguments_clear(&args);
163
+
164
+ if (callback_data) {
165
+ RBGIArgMetadata *callback_metadata =
166
+ rb_gi_callback_data_get_metadata(callback_data);
167
+ if (callback_metadata->scope_type == GI_SCOPE_TYPE_ASYNC) {
168
+ rb_gi_callback_data_free(callback_data);
169
+ }
170
+ }
171
+ }
172
+
173
+ RBGICallback *
174
+ rb_gi_callback_new(GICallbackInfo *callback_info,
175
+ const gchar *method_name)
176
+ {
177
+ RBGICallback *callback = RB_ZALLOC(RBGICallback);
178
+ callback->callback_info = callback_info;
179
+ g_base_info_ref(callback->callback_info);
180
+ callback->method_name = g_strdup(method_name);
181
+ callback->closure =
182
+ g_callable_info_prepare_closure(callback->callback_info,
183
+ &(callback->cif),
184
+ rb_gi_ffi_closure_callback,
185
+ callback);
186
+ return callback;
187
+ }
188
+
35
189
  static void
36
190
  rb_gi_callback_free(RBGICallback *callback)
37
191
  {
38
192
  g_callable_info_free_closure(callback->callback_info,
39
193
  callback->closure);
194
+ g_free(callback->method_name);
40
195
  g_base_info_unref(callback->callback_info);
41
- g_base_info_unref(callback->type_info);
42
196
  xfree(callback);
43
197
  }
44
198
 
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2014 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -18,8 +18,7 @@
18
18
  * MA 02110-1301 USA
19
19
  */
20
20
 
21
- #ifndef RB_GI_CONVERSIONS_H
22
- #define RB_GI_CONVERSIONS_H
21
+ #pragma once
23
22
 
24
23
  #define RVAL2GI_REPOSITORY(rb_object) (G_IREPOSITORY(RVAL2GOBJ(rb_object)))
25
24
  #define RVAL2GI_REPOSITORY_LOAD_FLAGS(rb_flags) \
@@ -65,6 +64,10 @@
65
64
  ((GIFieldInfo *)RVAL2GI_BASE_INFO(rb_object))
66
65
  #define RVAL2GI_TYPE_INFO(rb_object) \
67
66
  ((GITypeInfo *)RVAL2GI_BASE_INFO(rb_object))
67
+ #define RVAL2GI_CALLABLE_INFO(rb_object) \
68
+ ((GICallableInfo *)RVAL2GI_BASE_INFO(rb_object))
69
+ #define RVAL2GI_VFUNC_INFO(rb_object) \
70
+ ((GIVFuncInfo *)RVAL2GI_BASE_INFO(rb_object))
68
71
 
69
72
  #define GI_INFO_TYPE2RVAL(type) (GENUM2RVAL(type, G_TYPE_I_INFO_TYPE))
70
73
  #define GI_TRANSFER2RVAL(transfer) (GENUM2RVAL(transfer, G_TYPE_I_TRANSFER))
@@ -100,6 +103,3 @@ VALUE rb_gi_return_argument_to_ruby (GICallableInfo *callable_info,
100
103
  GPtrArray *args_metadata);
101
104
 
102
105
  VALUE rb_gi_array_type_to_ruby (GIArrayType type);
103
-
104
- #endif
105
-
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2017 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -125,15 +125,9 @@ rg_get_signal(VALUE self, VALUE rb_n_or_name)
125
125
  n = NUM2INT(rb_n_or_name);
126
126
  signal_info = g_interface_info_get_signal(info, n);
127
127
  } else {
128
- #ifdef HAVE_G_INTERFACE_INFO_FIND_SIGNAL
129
128
  const char *name;
130
129
  name = RVAL2CSTR(rb_n_or_name);
131
130
  signal_info = g_interface_info_find_signal(info, name);
132
- #else
133
- rb_raise(rb_eArgError,
134
- "g_interface_info_find_signal() is defined "
135
- "since GObjectIntrospection 1.34");
136
- #endif
137
131
  }
138
132
 
139
133
  return GI_BASE_INFO2RVAL_WITH_UNREF(signal_info);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2018 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -39,7 +39,7 @@ rg_s_define_class(int argc, VALUE *argv, G_GNUC_UNUSED VALUE klass)
39
39
  "size", &rb_size,
40
40
  NULL);
41
41
 
42
- gtype = NUM2ULONG(rb_to_int(rb_gtype));
42
+ gtype = rbgobj_gtype_from_ruby(rb_gtype);
43
43
  rb_class = G_DEF_CLASS_WITH_PARENT(gtype, RVAL2CSTR(rb_name),
44
44
  rb_module, rb_parent);
45
45
  if (!NIL_P(rb_size)) {
@@ -54,7 +54,7 @@ rg_s_define_interface(G_GNUC_UNUSED VALUE klass,
54
54
  {
55
55
  GType gtype;
56
56
 
57
- gtype = rbgobj_gtype_get(rb_gtype);
57
+ gtype = rbgobj_gtype_from_ruby(rb_gtype);
58
58
  return G_DEF_INTERFACE(gtype, RVAL2CSTR(rb_name), rb_module);
59
59
  }
60
60
 
@@ -133,12 +133,63 @@ rg_s_define_error(int argc, VALUE *argv, G_GNUC_UNUSED VALUE klass)
133
133
  }
134
134
 
135
135
  if (!NIL_P(rb_gtype)) {
136
- gtype = NUM2ULONG(rb_funcall(rb_gtype, rb_intern("to_i"), 0));
136
+ gtype = rbgobj_gtype_from_ruby(rb_gtype);
137
137
  }
138
138
 
139
139
  return G_DEF_ERROR(domain, name, rb_module, rb_parent, gtype);
140
140
  }
141
141
 
142
+ static VALUE
143
+ rg_s_implement_virtual_function(G_GNUC_UNUSED VALUE klass,
144
+ VALUE rb_field_info,
145
+ VALUE rb_implementor_gtype,
146
+ VALUE rb_vtable_gtype,
147
+ VALUE rb_method_name)
148
+ {
149
+ GIFieldInfo *field_info;
150
+ GType implementor_gtype;
151
+ GType vtable_gtype;
152
+ const gchar *method_name;
153
+ RBGICallback *callback;
154
+
155
+ field_info = RVAL2GI_FIELD_INFO(rb_field_info);
156
+ implementor_gtype = rbgobj_gtype_from_ruby(rb_implementor_gtype);
157
+ vtable_gtype = rbgobj_gtype_from_ruby(rb_vtable_gtype);
158
+ method_name = RVAL2CSTR(rb_method_name);
159
+
160
+ {
161
+ GITypeInfo *type_info;
162
+ GICallbackInfo *callback_info;
163
+
164
+ type_info = g_field_info_get_type(field_info);
165
+ callback_info = g_type_info_get_interface(type_info);
166
+ callback = rb_gi_callback_new(callback_info, method_name);
167
+ g_base_info_unref(callback_info);
168
+ g_base_info_unref(type_info);
169
+ }
170
+
171
+ {
172
+ gpointer implementor_struct;
173
+ gpointer vtable_struct;
174
+ gint offset;
175
+ gpointer *method_address;
176
+
177
+ implementor_struct = g_type_class_ref(implementor_gtype);
178
+ if (G_TYPE_IS_INTERFACE(vtable_gtype)) {
179
+ vtable_struct = g_type_interface_peek(implementor_struct,
180
+ vtable_gtype);
181
+ } else {
182
+ vtable_struct = implementor_struct;
183
+ }
184
+ offset = g_field_info_get_offset(field_info);
185
+ method_address = G_STRUCT_MEMBER_P(vtable_struct, offset);
186
+ *method_address = callback->closure;
187
+ g_type_class_unref(implementor_struct);
188
+ }
189
+
190
+ return Qnil;
191
+ }
192
+
142
193
  typedef struct {
143
194
  GType type;
144
195
  VALUE rb_converters;
@@ -173,12 +224,10 @@ rg_s_register_boxed_class_converter(VALUE klass, VALUE rb_gtype)
173
224
  {
174
225
  RGConvertTable table;
175
226
  BoxedInstance2RObjData *data;
176
- ID id_to_i;
177
227
  VALUE boxed_class_converters;
178
228
 
179
229
  memset(&table, 0, sizeof(RGConvertTable));
180
- CONST_ID(id_to_i, "to_i");
181
- table.type = NUM2ULONG(rb_funcall(rb_gtype, id_to_i, 0));
230
+ table.type = rbgobj_gtype_from_ruby(rb_gtype);
182
231
  table.klass = Qnil;
183
232
  table.instance2robj = boxed_instance2robj;
184
233
 
@@ -243,12 +292,10 @@ rg_s_register_object_class_converter(VALUE klass, VALUE rb_gtype)
243
292
  {
244
293
  RGConvertTable table;
245
294
  ObjectInstance2RObjData *data;
246
- ID id_to_i;
247
295
  VALUE object_class_converters;
248
296
 
249
297
  memset(&table, 0, sizeof(RGConvertTable));
250
- CONST_ID(id_to_i, "to_i");
251
- table.type = NUM2ULONG(rb_funcall(rb_gtype, id_to_i, 0));
298
+ table.type = rbgobj_gtype_from_ruby(rb_gtype);
252
299
  table.klass = Qnil;
253
300
  table.instance2robj = object_instance2robj;
254
301
 
@@ -337,6 +384,7 @@ rb_gi_loader_init(VALUE rb_mGI)
337
384
  RG_DEF_SMETHOD(define_interface, 3);
338
385
  RG_DEF_SMETHOD(define_struct, -1);
339
386
  RG_DEF_SMETHOD(define_error, -1);
387
+ RG_DEF_SMETHOD(implement_virtual_function, 4);
340
388
  RG_DEF_SMETHOD(register_boxed_class_converter, 1);
341
389
  RG_DEF_SMETHOD(register_object_class_converter, 1);
342
390
  RG_DEF_SMETHOD(register_constant_rename_map, 2);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -272,6 +272,15 @@ rg_get_constant(VALUE self, VALUE rb_n)
272
272
  return GI_BASE_INFO2RVAL_WITH_UNREF(g_object_info_get_constant(info, n));
273
273
  }
274
274
 
275
+ static VALUE
276
+ rg_class_struct(VALUE self)
277
+ {
278
+ GIObjectInfo *info;
279
+
280
+ info = SELF(self);
281
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_object_info_get_class_struct(info));
282
+ }
283
+
275
284
  static VALUE
276
285
  rg_unref_function(VALUE self)
277
286
  {
@@ -338,6 +347,7 @@ rb_gi_object_info_init(VALUE rb_mGI, VALUE rb_cGIRegisteredTypeInfo)
338
347
  RG_DEF_METHOD(get_vfunc, 1);
339
348
  RG_DEF_METHOD(n_constants, 0);
340
349
  RG_DEF_METHOD(get_constant, 1);
350
+ RG_DEF_METHOD(class_struct, 0);
341
351
  RG_DEF_METHOD(unref_function, 0);
342
352
  RG_DEF_METHOD(ref_function, 0);
343
353
  RG_DEF_METHOD(set_value_function, 0);