gobject-introspection 3.2.5-x64-mingw32 → 3.2.6-x64-mingw32

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING.LIB +502 -0
  3. data/README.md +24 -0
  4. data/Rakefile +7 -4
  5. data/ext/gobject-introspection/gobject_introspection.def +6 -1
  6. data/ext/gobject-introspection/rb-gi-argument.c +3 -1
  7. data/ext/gobject-introspection/rb-gi-constructor-info.c +3 -3
  8. data/ext/gobject-introspection/rb-gi-field-info.c +44 -8
  9. data/ext/gobject-introspection/rb-gi-function-info.c +45 -13
  10. data/ext/gobject-introspection/rb-gi-loader.c +10 -10
  11. data/ext/gobject-introspection/rb-gi-struct-info.c +82 -41
  12. data/ext/gobject-introspection/rb-gobject-introspection.h +12 -9
  13. data/gobject-introspection.gemspec +48 -0
  14. data/lib/2.2/gobject_introspection.so +0 -0
  15. data/lib/2.3/gobject_introspection.so +0 -0
  16. data/lib/2.4/gobject_introspection.so +0 -0
  17. data/lib/2.5/gobject_introspection.so +0 -0
  18. data/lib/gobject-introspection/loader.rb +4 -0
  19. data/vendor/local/bin/g-ir-compiler.exe +0 -0
  20. data/vendor/local/bin/g-ir-generate.exe +0 -0
  21. data/vendor/local/bin/g-ir-inspect.exe +0 -0
  22. data/vendor/local/bin/libgirepository-1.0-1.dll +0 -0
  23. data/vendor/local/lib/girepository-1.0/GLib-2.0.typelib +0 -0
  24. data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyc +0 -0
  25. data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyo +0 -0
  26. data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyc +0 -0
  27. data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyo +0 -0
  28. data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyc +0 -0
  29. data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyo +0 -0
  30. data/vendor/local/lib/gobject-introspection/giscanner/ast.pyc +0 -0
  31. data/vendor/local/lib/gobject-introspection/giscanner/ast.pyo +0 -0
  32. data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyc +0 -0
  33. data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyo +0 -0
  34. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.py +1 -1
  35. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.pyc +0 -0
  36. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.pyo +0 -0
  37. data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyc +0 -0
  38. data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyo +0 -0
  39. data/vendor/local/lib/gobject-introspection/giscanner/collections/__init__.pyc +0 -0
  40. data/vendor/local/lib/gobject-introspection/giscanner/collections/__init__.pyo +0 -0
  41. data/vendor/local/lib/gobject-introspection/giscanner/collections/counter.pyc +0 -0
  42. data/vendor/local/lib/gobject-introspection/giscanner/collections/counter.pyo +0 -0
  43. data/vendor/local/lib/gobject-introspection/giscanner/collections/ordereddict.pyc +0 -0
  44. data/vendor/local/lib/gobject-introspection/giscanner/collections/ordereddict.pyo +0 -0
  45. data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyc +0 -0
  46. data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyo +0 -0
  47. data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyc +0 -0
  48. data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyo +0 -0
  49. data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyc +0 -0
  50. data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyo +0 -0
  51. data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyc +0 -0
  52. data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyo +0 -0
  53. data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyc +0 -0
  54. data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyo +0 -0
  55. data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyc +0 -0
  56. data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyo +0 -0
  57. data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyc +0 -0
  58. data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyo +0 -0
  59. data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyc +0 -0
  60. data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyo +0 -0
  61. data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyc +0 -0
  62. data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyo +0 -0
  63. data/vendor/local/lib/gobject-introspection/giscanner/message.pyc +0 -0
  64. data/vendor/local/lib/gobject-introspection/giscanner/message.pyo +0 -0
  65. data/vendor/local/lib/gobject-introspection/giscanner/msvccompiler.pyc +0 -0
  66. data/vendor/local/lib/gobject-introspection/giscanner/msvccompiler.pyo +0 -0
  67. data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyc +0 -0
  68. data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyo +0 -0
  69. data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyc +0 -0
  70. data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyo +0 -0
  71. data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyc +0 -0
  72. data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyo +0 -0
  73. data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyc +0 -0
  74. data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyo +0 -0
  75. data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyc +0 -0
  76. data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyo +0 -0
  77. data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyc +0 -0
  78. data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyo +0 -0
  79. data/vendor/local/lib/gobject-introspection/giscanner/utils.pyc +0 -0
  80. data/vendor/local/lib/gobject-introspection/giscanner/utils.pyo +0 -0
  81. data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyc +0 -0
  82. data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyo +0 -0
  83. data/vendor/local/lib/libgirepository-1.0.a +0 -0
  84. data/vendor/local/lib/libgirepository-1.0.dll.a +0 -0
  85. data/vendor/local/lib/libgirepository-1.0.la +1 -1
  86. data/vendor/local/lib/pkgconfig/gobject-introspection-1.0.pc +1 -1
  87. data/vendor/local/lib/pkgconfig/gobject-introspection-no-export-1.0.pc +1 -1
  88. data/vendor/local/share/gir-1.0/GLib-2.0.gir +1 -1
  89. data/vendor/local/share/gir-1.0/Gio-2.0.gir +42 -17
  90. metadata +11 -34
@@ -0,0 +1,24 @@
1
+ # Ruby/GObjectIntrospection
2
+
3
+ Ruby/GObjectIntrospection is a Ruby binding of GObject Introspect.
4
+
5
+ ## Requirements
6
+
7
+ * Ruby/GLib2 in
8
+ [Ruby-GNOME2](https://ruby-gnome2.osdn.jp/)
9
+ * [GObject Introspection](http://live.gnome.org/GObjectIntrospection)
10
+
11
+ ## Install
12
+
13
+ gem install gobject-introspection
14
+
15
+ ## License
16
+
17
+ Copyright (c) 2013 Ruby-GNOME2 Project Team
18
+
19
+ This program is free software. You can distribute/modify this program
20
+ under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
21
+
22
+ ## Project Website
23
+
24
+ https://ruby-gnome2.osdn.jp/
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2012-2015 Ruby-GNOME2 Project Team
3
+ # Copyright (C) 2012-2018 Ruby-GNOME2 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
@@ -19,7 +19,10 @@
19
19
  $LOAD_PATH.unshift("./../glib2/lib")
20
20
  require "gnome2/rake/package-task"
21
21
 
22
- package_task = GNOME2::Rake::PackageTask.new do |package|
22
+ package_name = File.basename(__dir__)
23
+ spec = Gem::Specification.load("#{package_name}.gemspec")
24
+
25
+ package_task = GNOME2::Rake::PackageTask.new(spec, __dir__) do |package|
23
26
  package.summary = "Ruby/GObjectIntrospection is a Ruby binding of GObjectIntrospection."
24
27
  package.description = "Ruby/GObjectIntrospection is a Ruby binding of GObjectIntrospection."
25
28
  package.dependency.gem.runtime = ["glib2"]
@@ -32,7 +35,7 @@ package_task = GNOME2::Rake::PackageTask.new do |package|
32
35
  :name => "glib",
33
36
  :download_site => :gnome,
34
37
  :label => "GLib",
35
- :version => "2.56.0",
38
+ :version => "2.56.1",
36
39
  :compression_method => "xz",
37
40
  :windows => {
38
41
  :build => false,
@@ -47,7 +50,7 @@ package_task = GNOME2::Rake::PackageTask.new do |package|
47
50
  :name => "gobject-introspection",
48
51
  :download_site => :gnome,
49
52
  :label => "gobject-introspection",
50
- :version => "1.56.0",
53
+ :version => "1.56.1",
51
54
  :compression_method => "xz",
52
55
  :windows => {
53
56
  :configure_args => [
@@ -1,5 +1,10 @@
1
1
  EXPORTS
2
2
  Init_gobject_introspection
3
3
 
4
- rb_gi_callback_data_free
5
4
  rb_gi_callback_register_finder
5
+ rb_gi_callback_data_free
6
+ rb_gi_callback_data_get_metadata
7
+ rb_gi_callback_data_get_rb_callback
8
+
9
+ rb_gi_struct_new_raw
10
+ rb_gi_struct_get_raw
@@ -22,6 +22,7 @@
22
22
 
23
23
  static VALUE rb_cGLibValue = Qnil;
24
24
  static VALUE rb_cGLibBytes = Qnil;
25
+ static VALUE rb_cGLibBoxed = Qnil;
25
26
 
26
27
  static gboolean
27
28
  rb_gi_arg_info_may_be_null(GIArgInfo *arg_info)
@@ -2883,7 +2884,7 @@ rb_gi_value_argument_from_ruby_interface(GIArgument *argument,
2883
2884
  case GI_INFO_TYPE_STRUCT:
2884
2885
  gtype = g_registered_type_info_get_g_type(interface_info);
2885
2886
  if (gtype == G_TYPE_NONE) {
2886
- argument->v_pointer = DATA_PTR(rb_argument);
2887
+ argument->v_pointer = rb_gi_struct_get_raw(rb_argument, gtype);
2887
2888
  } else if (gtype == G_TYPE_VALUE) {
2888
2889
  GValue *gvalue;
2889
2890
  if (RVAL2CBOOL(rb_obj_is_kind_of(rb_argument, rb_cGLibValue))) {
@@ -4470,4 +4471,5 @@ rb_gi_argument_init(void)
4470
4471
  {
4471
4472
  rb_cGLibValue = rb_const_get(mGLib, rb_intern("Value"));
4472
4473
  rb_cGLibBytes = rb_const_get(mGLib, rb_intern("Bytes"));
4474
+ rb_cGLibBoxed = rb_const_get(mGLib, rb_intern("Boxed"));
4473
4475
  }
@@ -28,7 +28,7 @@ gi_constructor_info_get_type(void)
28
28
  {
29
29
  static GType type = 0;
30
30
  if (type == 0) {
31
- type = g_boxed_type_register_static("GIConstructorInfo",
31
+ type = g_boxed_type_register_static("GIConstructorInfo",
32
32
  (GBoxedCopyFunc)g_base_info_ref,
33
33
  (GBoxedFreeFunc)g_base_info_unref);
34
34
  }
@@ -141,9 +141,9 @@ rb_gi_constructor_info_init(VALUE rb_mGI, VALUE rb_cGIFunctionInfo)
141
141
  VALUE RG_TARGET_NAMESPACE;
142
142
 
143
143
  RG_TARGET_NAMESPACE =
144
- G_DEF_CLASS_WITH_PARENT(GI_TYPE_CONSTRUCTOR_INFO,
144
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_CONSTRUCTOR_INFO,
145
145
  "ConstructorInfo", rb_mGI,
146
- rb_cGIFunctionInfo);
146
+ rb_cGIFunctionInfo);
147
147
 
148
148
  RG_DEF_METHOD(invoke, 2);
149
149
  }
@@ -79,24 +79,36 @@ rb_gi_field_info_get_field_raw_interface(GIFieldInfo *info,
79
79
  VALUE rb_field_value = Qnil;
80
80
  GIBaseInfo *interface_info;
81
81
  GIInfoType interface_type;
82
+ GType gtype;
83
+ gint offset;
82
84
 
83
85
  interface_info = g_type_info_get_interface(type_info);
84
86
  interface_type = g_base_info_get_type(interface_info);
87
+ gtype = g_registered_type_info_get_g_type(interface_info);
88
+ offset = g_field_info_get_offset(info);
85
89
  switch (interface_type) {
86
90
  case GI_INFO_TYPE_INVALID:
87
91
  case GI_INFO_TYPE_FUNCTION:
88
92
  case GI_INFO_TYPE_CALLBACK:
93
+ rb_raise(rb_eNotImpError,
94
+ "TODO: GIField(interface)[%s](%s)",
95
+ g_info_type_to_string(interface_type),
96
+ g_type_name(gtype));
89
97
  break;
90
98
  case GI_INFO_TYPE_STRUCT:
91
99
  {
92
100
  GIStructInfo *struct_info = (GIStructInfo *)interface_info;
93
- gint offset;
101
+ gboolean is_pointer;
102
+ gpointer target;
94
103
 
95
- offset = g_field_info_get_offset(info);
96
- rb_field_value = rb_gi_struct_info_to_ruby(
97
- struct_info,
98
- (gchar *)memory + offset,
99
- g_type_info_is_pointer(type_info));
104
+ is_pointer = g_type_info_is_pointer(type_info);
105
+ target = (gpointer)((guint8 *)memory + offset);
106
+ if (is_pointer) {
107
+ target = *((gpointer *)target);
108
+ }
109
+ rb_field_value = rb_gi_struct_info_to_ruby(struct_info,
110
+ target,
111
+ is_pointer);
100
112
  break;
101
113
  }
102
114
  case GI_INFO_TYPE_BOXED:
@@ -104,16 +116,36 @@ rb_gi_field_info_get_field_raw_interface(GIFieldInfo *info,
104
116
  case GI_INFO_TYPE_OBJECT:
105
117
  {
106
118
  GIArgument argument;
107
- gint offset;
108
119
 
109
- offset = g_field_info_get_offset(info);
110
120
  argument.v_pointer = G_STRUCT_MEMBER(gpointer, memory, offset);
111
121
  rb_field_value = GI_ARGUMENT2RVAL(&argument, FALSE, type_info,
112
122
  NULL, NULL, NULL);
113
123
  }
114
124
  break;
115
125
  case GI_INFO_TYPE_ENUM:
126
+ {
127
+ gint32 raw_value;
128
+
129
+ raw_value = G_STRUCT_MEMBER(gint32, memory, offset);
130
+ if (gtype == G_TYPE_NONE) {
131
+ rb_field_value = INT2NUM(raw_value);
132
+ } else {
133
+ rb_field_value = GENUM2RVAL(raw_value, gtype);
134
+ }
135
+ }
136
+ break;
116
137
  case GI_INFO_TYPE_FLAGS:
138
+ {
139
+ gint32 raw_value;
140
+
141
+ raw_value = G_STRUCT_MEMBER(gint32, memory, offset);
142
+ if (gtype == G_TYPE_NONE) {
143
+ rb_field_value = INT2NUM(raw_value);
144
+ } else {
145
+ rb_field_value = GFLAGS2RVAL(raw_value, gtype);
146
+ }
147
+ }
148
+ break;
117
149
  case GI_INFO_TYPE_INTERFACE:
118
150
  case GI_INFO_TYPE_CONSTANT:
119
151
  case GI_INFO_TYPE_INVALID_0:
@@ -125,6 +157,10 @@ rb_gi_field_info_get_field_raw_interface(GIFieldInfo *info,
125
157
  case GI_INFO_TYPE_ARG:
126
158
  case GI_INFO_TYPE_TYPE:
127
159
  case GI_INFO_TYPE_UNRESOLVED:
160
+ rb_raise(rb_eNotImpError,
161
+ "TODO: GIField(interface)[%s](%s)",
162
+ g_info_type_to_string(interface_type),
163
+ g_type_name(gtype));
128
164
  break;
129
165
  default:
130
166
  break;
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2016 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2018 Ruby-GNOME2 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
@@ -42,6 +42,12 @@ typedef struct _RBGICallback {
42
42
  ffi_closure *closure;
43
43
  } RBGICallback;
44
44
 
45
+ struct RBGICallbackData_ {
46
+ RBGICallback *callback;
47
+ RBGIArgMetadata *metadata;
48
+ VALUE rb_callback;
49
+ };
50
+
45
51
  static VALUE RG_TARGET_NAMESPACE;
46
52
  static VALUE rb_cGLibError;
47
53
  static const char *callbacks_key = "gi_callbacks";
@@ -300,22 +306,13 @@ fill_metadata(GPtrArray *args_metadata, GICallableInfo *info)
300
306
  static void
301
307
  callback_data_guard_from_gc(RBGICallbackData *callback_data)
302
308
  {
303
- VALUE rb_callbacks;
304
-
305
- rb_callbacks = rb_iv_get(RG_TARGET_NAMESPACE, callbacks_key);
306
- callback_data->rb_gc_guard_key = rb_class_new_instance(0, NULL, rb_cObject);
307
- rb_hash_aset(rb_callbacks,
308
- callback_data->rb_gc_guard_key,
309
- callback_data->rb_callback);
309
+ rbg_gc_guard(callback_data, callback_data->rb_callback);
310
310
  }
311
311
 
312
312
  static void
313
313
  callback_data_unguard_from_gc(RBGICallbackData *callback_data)
314
314
  {
315
- VALUE rb_callbacks;
316
-
317
- rb_callbacks = rb_iv_get(RG_TARGET_NAMESPACE, callbacks_key);
318
- rb_hash_delete(rb_callbacks, callback_data->rb_gc_guard_key);
315
+ rbg_gc_unguard(callback_data);
319
316
  }
320
317
 
321
318
  static void
@@ -339,6 +336,18 @@ rb_gi_callback_data_free(RBGICallbackData *callback_data)
339
336
  xfree(callback_data);
340
337
  }
341
338
 
339
+ RBGIArgMetadata *
340
+ rb_gi_callback_data_get_metadata(RBGICallbackData *callback_data)
341
+ {
342
+ return callback_data->metadata;
343
+ }
344
+
345
+ VALUE
346
+ rb_gi_callback_data_get_rb_callback(RBGICallbackData *callback_data)
347
+ {
348
+ return callback_data->rb_callback;
349
+ }
350
+
342
351
  static void
343
352
  destroy_notify(gpointer data)
344
353
  {
@@ -1023,6 +1032,29 @@ ffi_closure_callback(G_GNUC_UNUSED ffi_cif *cif,
1023
1032
  callback_data = *((RBGICallbackData **)(raw_args[i]));
1024
1033
  break;
1025
1034
  }
1035
+
1036
+ if (!callback_data && args_metadata->len > 0) {
1037
+ RBGIArgMetadata *metadata;
1038
+ GIArgInfo *arg_info;
1039
+ GITypeInfo *type_info;
1040
+ GITypeTag type_tag;
1041
+ gboolean is_pointer;
1042
+ const gchar *arg_name;
1043
+
1044
+ i = args_metadata->len - 1;
1045
+ metadata = g_ptr_array_index(args_metadata, i);
1046
+ arg_info = &(metadata->arg_info);
1047
+ type_info = g_arg_info_get_type(arg_info);
1048
+ type_tag = g_type_info_get_tag(type_info);
1049
+ is_pointer = g_type_info_is_pointer(type_info);
1050
+ g_base_info_unref(type_info);
1051
+ arg_name = g_base_info_get_name(arg_info);
1052
+ if (type_tag == GI_TYPE_TAG_VOID &&
1053
+ is_pointer &&
1054
+ strcmp(arg_name, "data") == 0) {
1055
+ callback_data = *((RBGICallbackData **)(raw_args[i]));
1056
+ }
1057
+ }
1026
1058
  }
1027
1059
 
1028
1060
  {
@@ -1421,7 +1453,7 @@ rb_gi_function_info_invoke_raw(GIFunctionInfo *info,
1421
1453
  object_class = g_type_class_ref(CLASS2GTYPE(rb_receiver));
1422
1454
  receiver.v_pointer = object_class;
1423
1455
  } else {
1424
- receiver.v_pointer = DATA_PTR(rb_receiver);
1456
+ receiver.v_pointer = rb_gi_struct_get_raw(rb_receiver, G_TYPE_NONE);
1425
1457
  }
1426
1458
  }
1427
1459
  rb_arguments = rbg_to_array(rb_arguments);
@@ -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-2018 Ruby-GNOME2 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
@@ -58,23 +58,23 @@ rg_s_define_interface(G_GNUC_UNUSED VALUE klass,
58
58
  return G_DEF_INTERFACE(gtype, RVAL2CSTR(rb_name), rb_module);
59
59
  }
60
60
 
61
- static void
62
- struct_free(void *pointer)
63
- {
64
- xfree(pointer);
65
- }
66
-
67
61
  static VALUE
68
62
  struct_alloc(VALUE klass)
69
63
  {
70
64
  VALUE rb_size;
71
65
  size_t size;
72
66
  gpointer instance;
67
+ gboolean is_owned;
73
68
 
74
69
  rb_size = rb_iv_get(klass, "@size");
75
- size = NUM2ULONG(rb_size);
76
- instance = xcalloc(1, size);
77
- return Data_Wrap_Struct(klass, NULL, struct_free, instance);
70
+ if (NIL_P(rb_size)) {
71
+ is_owned = FALSE;
72
+ } else {
73
+ size = NUM2ULONG(rb_size);
74
+ instance = xcalloc(1, size);
75
+ is_owned = TRUE;
76
+ }
77
+ return rb_gi_struct_new_raw(klass, instance, is_owned);
78
78
  }
79
79
 
80
80
  static VALUE
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2013 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2018 Ruby-GNOME2 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
@@ -35,6 +35,72 @@ gi_struct_info_get_type(void)
35
35
  return type;
36
36
  }
37
37
 
38
+ typedef struct {
39
+ gpointer instance;
40
+ gboolean is_owned;
41
+ } RBGIStructData;
42
+
43
+ static void
44
+ struct_free(void *data)
45
+ {
46
+ RBGIStructData *struct_data = data;
47
+ if (struct_data->is_owned) {
48
+ xfree(struct_data->instance);
49
+ }
50
+ xfree(struct_data);
51
+ }
52
+
53
+ static const rb_data_type_t rb_gi_struct_type = {
54
+ "GObjectIntrospection::Struct",
55
+ {
56
+ NULL,
57
+ struct_free,
58
+ NULL,
59
+ },
60
+ NULL,
61
+ NULL,
62
+ RUBY_TYPED_FREE_IMMEDIATELY,
63
+ };
64
+
65
+ VALUE
66
+ rb_gi_struct_new_raw(VALUE klass, gpointer instance, gboolean is_owned)
67
+ {
68
+ RBGIStructData *data;
69
+ data = RB_ALLOC(RBGIStructData);
70
+ data->instance = instance;
71
+ data->is_owned = is_owned;
72
+ return TypedData_Wrap_Struct(klass, &rb_gi_struct_type, data);
73
+ }
74
+
75
+ gpointer
76
+ rb_gi_struct_get_raw(VALUE rb_struct, GType gtype)
77
+ {
78
+ gpointer raw_struct;
79
+
80
+ if (gtype == G_TYPE_NONE) {
81
+ VALUE rb_struct_class;
82
+
83
+ rb_struct_class = rb_class_of(rb_struct);
84
+ if (rb_respond_to(rb_struct_class, rb_intern("gtype"))) {
85
+ VALUE rb_gtype;
86
+ rb_gtype = rb_funcall(rb_struct_class, rb_intern("gtype"), 0);
87
+ gtype = NUM2ULONG(rb_funcall(rb_gtype, rb_intern("to_i"), 0));
88
+ }
89
+ }
90
+ if (gtype == G_TYPE_NONE) {
91
+ RBGIStructData *data;
92
+ TypedData_Get_Struct(rb_struct,
93
+ RBGIStructData,
94
+ &rb_gi_struct_type,
95
+ data);
96
+ raw_struct = data->instance;
97
+ } else {
98
+ raw_struct = RVAL2BOXED(rb_struct, gtype);
99
+ }
100
+
101
+ return raw_struct;
102
+ }
103
+
38
104
  VALUE
39
105
  rb_gi_struct_info_to_ruby(GIStructInfo *info,
40
106
  gpointer object,
@@ -47,15 +113,13 @@ rb_gi_struct_info_to_ruby(GIStructInfo *info,
47
113
  const char *name;
48
114
  VALUE rb_module;
49
115
  VALUE rb_class;
50
- gpointer target_object = object;
51
- RUBY_DATA_FUNC free_func = NULL;
52
116
 
53
117
  gtype = g_registered_type_info_get_g_type(registered_type_info);
54
118
  if (gtype == G_TYPE_VARIANT) {
55
119
  GVariant *variant = object;
56
120
  return rbg_variant_to_ruby(variant);
57
121
  } else if (gtype != G_TYPE_NONE) {
58
- return BOXED2RVAL(target_object, gtype);
122
+ return BOXED2RVAL(object, gtype);
59
123
  }
60
124
 
61
125
  namespace = g_base_info_get_namespace(base_info);
@@ -68,7 +132,7 @@ rb_gi_struct_info_to_ruby(GIStructInfo *info,
68
132
  gtype_name = g_strdup_printf("Cairo%s", name);
69
133
  gtype = g_type_from_name(gtype_name);
70
134
  g_free(gtype_name);
71
- return BOXED2RVAL(target_object, gtype);
135
+ return BOXED2RVAL(object, gtype);
72
136
  }
73
137
 
74
138
  rb_module = rb_const_get(rb_cObject, rb_intern(namespace));
@@ -79,18 +143,21 @@ rb_gi_struct_info_to_ruby(GIStructInfo *info,
79
143
 
80
144
  rb_gtype = rb_funcall(rb_class, rb_intern("gtype"), 0);
81
145
  gtype = NUM2ULONG(rb_funcall(rb_gtype, rb_intern("to_i"), 0));
82
- return BOXED2RVAL(target_object, gtype);
146
+ return BOXED2RVAL(object, gtype);
83
147
  }
84
148
 
85
- if (!is_pointer) {
149
+ if (is_pointer) {
150
+ return rb_gi_struct_new_raw(rb_class, object, FALSE);
151
+ } else {
86
152
  size_t object_size;
153
+ gpointer copied_object;
154
+
87
155
  object_size = g_struct_info_get_size(info);
88
- target_object = xmalloc(object_size);
89
- memcpy(target_object, object, object_size);
90
- free_func = xfree;
91
- }
156
+ copied_object = xmalloc(object_size);
157
+ memcpy(copied_object, object, object_size);
92
158
 
93
- return Data_Wrap_Struct(rb_class, NULL, free_func, target_object);
159
+ return rb_gi_struct_new_raw(rb_class, copied_object, TRUE);
160
+ }
94
161
  }
95
162
 
96
163
  gpointer
@@ -100,11 +167,7 @@ rb_gi_struct_info_from_ruby(GIStructInfo *info, VALUE rb_object)
100
167
  GType gtype;
101
168
 
102
169
  gtype = g_registered_type_info_get_g_type(registerd_type_info);
103
- if (gtype == G_TYPE_NONE) {
104
- return DATA_PTR(rb_object);
105
- } else {
106
- return RVAL2BOXED(rb_object, gtype);
107
- }
170
+ return rb_gi_struct_get_raw(rb_object, gtype);
108
171
  }
109
172
 
110
173
  static VALUE
@@ -127,28 +190,6 @@ rg_get_field(VALUE self, VALUE rb_n)
127
190
  return GI_BASE_INFO2RVAL_WITH_UNREF(g_struct_info_get_field(info, n));
128
191
  }
129
192
 
130
- static gpointer
131
- extract_raw_struct(VALUE rb_struct,
132
- GIStructInfo *struct_info)
133
- {
134
- GType gtype;
135
- gpointer raw_struct;
136
-
137
- gtype = g_registered_type_info_get_g_type(struct_info);
138
- if (gtype == G_TYPE_NONE && rb_respond_to(rb_struct, rb_intern("gtype"))) {
139
- VALUE rb_gtype;
140
- rb_gtype = rb_funcall(rb_struct, rb_intern("gtype"), 0);
141
- gtype = NUM2ULONG(rb_funcall(rb_gtype, rb_intern("to_i"), 0));
142
- }
143
- if (gtype == G_TYPE_NONE) {
144
- raw_struct = DATA_PTR(rb_struct);
145
- } else {
146
- raw_struct = RVAL2BOXED(rb_struct, gtype);
147
- }
148
-
149
- return raw_struct;
150
- }
151
-
152
193
  static VALUE
153
194
  rg_get_field_value(VALUE self, VALUE rb_struct, VALUE rb_n)
154
195
  {
@@ -159,7 +200,7 @@ rg_get_field_value(VALUE self, VALUE rb_struct, VALUE rb_n)
159
200
  VALUE rb_value;
160
201
 
161
202
  info = SELF(self);
162
- raw_struct = extract_raw_struct(rb_struct, info);
203
+ raw_struct = rb_gi_struct_info_from_ruby(info, rb_struct);
163
204
  n = NUM2INT(rb_n);
164
205
  field_info = g_struct_info_get_field(info, n);
165
206
  rb_value = rb_gi_field_info_get_field_raw(field_info, raw_struct);
@@ -177,7 +218,7 @@ rg_set_field_value(VALUE self, VALUE rb_struct, VALUE rb_n, VALUE rb_value)
177
218
  GIFieldInfo *field_info;
178
219
 
179
220
  info = SELF(self);
180
- raw_struct = extract_raw_struct(rb_struct, info);
221
+ raw_struct = rb_gi_struct_info_from_ruby(info, rb_struct);
181
222
  n = NUM2INT(rb_n);
182
223
  field_info = g_struct_info_get_field(info, n);
183
224
  rb_gi_field_info_set_field_raw(field_info, raw_struct, rb_value);