glib2 2.2.5 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -468,7 +468,7 @@ rg_initialize(VALUE self, VALUE type)
468
468
  }
469
469
 
470
470
  if (G_TYPE_INVALID == gtype)
471
- rb_raise(rb_eArgError, "invalid type");
471
+ rb_raise(rb_eArgError, "invalid GType");
472
472
 
473
473
  rb_ivar_set(self, id_gtype, ULONG2NUM(gtype));
474
474
 
@@ -106,11 +106,17 @@ rbgobj_instance_call_cinfo_free(gpointer instance)
106
106
  each_cinfo(instance, call_cinfo_free, NULL);
107
107
  }
108
108
 
109
- void
109
+ gboolean
110
110
  rbgobj_gc_mark_instance(gpointer instance)
111
111
  {
112
112
  VALUE obj = rbgobj_ruby_object_from_instance2(instance, FALSE);
113
+
114
+ if (NIL_P(obj)) {
115
+ return FALSE;
116
+ }
117
+
113
118
  rb_gc_mark(obj);
119
+ return TRUE;
114
120
  }
115
121
 
116
122
  /**********************************************************************/
@@ -125,4 +131,4 @@ Init_gobject_typeinstance(void)
125
131
  rb_define_alloc_func(RG_TARGET_NAMESPACE, (VALUE(*)_((VALUE)))instantiatable_s_allocate);
126
132
  RG_DEF_METHOD(gtype, 0);
127
133
  RG_DEF_METHOD(clone, 0);
128
- }
134
+ }
@@ -122,6 +122,12 @@ rbgobj_gvalue_to_rvalue(const GValue* value)
122
122
  return func(value);
123
123
  }
124
124
  }
125
+ case G_TYPE_VARIANT:
126
+ {
127
+ GVariant *variant = g_value_peek_pointer(value);
128
+ rvalue = rbg_variant_to_ruby(variant);
129
+ return rvalue;
130
+ }
125
131
  default:
126
132
  if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) {
127
133
  GValueToRValueFunc func;
@@ -191,18 +197,14 @@ rbgobj_initialize_gvalue(GValue *result, VALUE value)
191
197
  if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cEnum))) {
192
198
  type = G_TYPE_ENUM;
193
199
  }
194
- else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cFlags))) {
195
- type = G_TYPE_FLAGS;
196
- }
197
- else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cBoxed))) {
198
- type = G_TYPE_BOXED;
200
+ else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cFlags)) ||
201
+ RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cBoxed)) ||
202
+ RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cObject))) {
203
+ type = RVAL2GTYPE(value);
199
204
  }
200
205
  else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cParam))) {
201
206
  type = G_TYPE_PARAM;
202
207
  }
203
- else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_cObject))) {
204
- type = G_TYPE_OBJECT;
205
- }
206
208
  else if (RVAL2CBOOL(rb_obj_is_kind_of(value, rbgobj_mInterface))) {
207
209
  /* should use rbgobj_mMetaInterface? */
208
210
  type = G_TYPE_INTERFACE;
@@ -335,12 +337,18 @@ rbgobj_gc_mark_gvalue(GValue* value)
335
337
  /**********************************************************************/
336
338
 
337
339
  static VALUE
338
- rg_initialize(VALUE self, VALUE rb_gtype, VALUE rb_value)
340
+ rg_initialize(int argc, VALUE *argv, VALUE self)
339
341
  {
340
342
  GValue value = G_VALUE_INIT;
343
+ VALUE rb_gtype;
344
+ VALUE rb_value;
345
+
346
+ rb_scan_args(argc, argv, "11", &rb_gtype, &rb_value);
341
347
 
342
- g_value_init(&value, NUM2INT(rb_to_int(rb_gtype)));
343
- rbgobj_rvalue_to_gvalue(rb_value, &value);
348
+ g_value_init(&value, NUM2ULONG(rb_to_int(rb_gtype)));
349
+ if (argc == 2) {
350
+ rbgobj_rvalue_to_gvalue(rb_value, &value);
351
+ }
344
352
  G_INITIALIZE(self, g_boxed_copy(G_TYPE_VALUE, &value));
345
353
  g_value_unset(&value);
346
354
 
@@ -388,7 +396,7 @@ Init_gobject_gvalue(void)
388
396
  qGValueToRValueFunc = g_quark_from_static_string("__ruby_g2r_func__");
389
397
 
390
398
  RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_VALUE, "Value", mGLib);
391
- RG_DEF_METHOD(initialize, 2);
399
+ RG_DEF_METHOD(initialize, -1);
392
400
  RG_DEF_METHOD(type, 0);
393
401
  RG_DEF_METHOD(value, 0);
394
402
  RG_DEF_METHOD(to_s, 0);
@@ -384,4 +384,6 @@ Init_gobject(void)
384
384
 
385
385
  Init_gobject_gtypeplugin();
386
386
  Init_gobject_gtypemodule();
387
+
388
+ Init_gobject_gbinding();
387
389
  }
@@ -166,7 +166,7 @@ extern void rbgobj_gobject_initialize(VALUE obj, gpointer cobj);
166
166
  extern void rbgobj_add_abstract_but_create_instance_class(GType gtype);
167
167
 
168
168
  /* rbgobj_typeinstance.c */
169
- extern void rbgobj_gc_mark_instance(gpointer instance);
169
+ extern gboolean rbgobj_gc_mark_instance(gpointer instance);
170
170
 
171
171
 
172
172
  /* rbgobj_type.c */
@@ -229,6 +229,8 @@ extern void g_value_set_ruby_value(GValue* value, VALUE ruby);
229
229
  /* rbgobj_object.c */
230
230
  extern void rbgobj_register_property_setter(GType gtype, const char* prop_name, RValueToGValueFunc func);
231
231
  extern void rbgobj_register_property_getter(GType gtype, const char* prop_name, GValueToRValueFunc func);
232
+ extern void rbgobj_class_init_func(gpointer g_class, gpointer class_data);
233
+ extern void rbgobj_register_type(VALUE klass, VALUE type_name, GClassInitFunc class_init);
232
234
 
233
235
  /* rbgobj_boxed.c */
234
236
  extern VALUE rbgobj_boxed_create(VALUE klass); /* deprecated */
@@ -284,7 +286,7 @@ typedef struct {
284
286
  void (*type_init_hook)(VALUE klass, gpointer user_data);
285
287
  void (*rvalue2gvalue)(VALUE value, GValue *result, gpointer user_data);
286
288
  VALUE (*gvalue2rvalue)(const GValue *value, gpointer user_data);
287
- void (*initialize)(VALUE rb_instance, gpointer insntance, gpointer user_data);
289
+ void (*initialize)(VALUE rb_instance, gpointer instance, gpointer user_data);
288
290
  gpointer (*robj2instance)(VALUE rb_instance, gpointer user_data);
289
291
  VALUE (*instance2robj)(gpointer instance, gpointer user_data);
290
292
  void (*unref)(gpointer instance, gpointer user_data);
@@ -1,7 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2013 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2007 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2007-2015 Ruby-GNOME2 Project Team
5
4
  *
6
5
  * This library is free software; you can redistribute it and/or
7
6
  * modify it under the terms of the GNU Lesser General Public
@@ -23,7 +22,6 @@
23
22
  #define __RBGPRIVATE_H__
24
23
 
25
24
  #include "rbgobject.h"
26
- #include "glib-enum-types.h"
27
25
 
28
26
  #ifndef HAVE_RB_ERRINFO
29
27
  # define rb_errinfo() (ruby_errinfo)
@@ -152,6 +150,8 @@ G_GNUC_INTERNAL void Init_glib_ucs4(void);
152
150
  G_GNUC_INTERNAL void Init_glib_unichar(void);
153
151
  G_GNUC_INTERNAL void Init_glib_keyfile(void);
154
152
  G_GNUC_INTERNAL void Init_glib_bookmark_file(void);
153
+ G_GNUC_INTERNAL void Init_glib_variant_type(void);
154
+ G_GNUC_INTERNAL void Init_glib_variant(void);
155
155
 
156
156
  G_GNUC_INTERNAL void Init_gobject_convert(void);
157
157
  G_GNUC_INTERNAL void Init_gobject_gtype(void);
@@ -172,6 +172,7 @@ G_GNUC_INTERNAL void Init_gobject_gobject(void);
172
172
  G_GNUC_INTERNAL void Init_gobject_gsignal(void);
173
173
  G_GNUC_INTERNAL void Init_gobject_gtypeplugin(void);
174
174
  G_GNUC_INTERNAL void Init_gobject_gtypemodule(void);
175
+ G_GNUC_INTERNAL void Init_gobject_gbinding(void);
175
176
 
176
177
  G_END_DECLS
177
178
 
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2014 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2015 Ruby-GNOME2 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
@@ -21,6 +21,8 @@
21
21
 
22
22
  #include "rbgprivate.h"
23
23
 
24
+ #include <string.h>
25
+
24
26
  ID rbgutil_id_module_eval;
25
27
 
26
28
  static ID id_add_one_arg_setter;
@@ -135,7 +137,7 @@ rbgutil_key_equal(VALUE rb_key, const char *key)
135
137
 
136
138
  static gboolean
137
139
  rbg_interrupt_prepare (G_GNUC_UNUSED GSource *soruce,
138
- G_GNUC_UNUSED gint *timouet)
140
+ G_GNUC_UNUSED gint *timeout)
139
141
  {
140
142
  return rb_thread_interrupted(rb_thread_current());
141
143
  }
@@ -158,12 +160,15 @@ rbg_interrupt_dispatch (G_GNUC_UNUSED GSource *soruce,
158
160
  }
159
161
  }
160
162
 
161
- static GSourceFuncs rbg_interrupt_funcs = {
162
- rbg_interrupt_prepare,
163
- rbg_interrupt_check,
164
- rbg_interrupt_dispatch,
165
- NULL
166
- };
163
+ static GSourceFuncs rbg_interrupt_funcs;
164
+ static void
165
+ rbg_interrupt_funcs_init(void)
166
+ {
167
+ memset(&rbg_interrupt_funcs, 0, sizeof(GSourceFuncs));
168
+ rbg_interrupt_funcs.prepare = rbg_interrupt_prepare;
169
+ rbg_interrupt_funcs.check = rbg_interrupt_check;
170
+ rbg_interrupt_funcs.dispatch = rbg_interrupt_dispatch;
171
+ }
167
172
 
168
173
  GSource *
169
174
  rbg_interrupt_source_new(void)
@@ -171,6 +176,27 @@ rbg_interrupt_source_new(void)
171
176
  return g_source_new(&rbg_interrupt_funcs, sizeof(GSource));
172
177
  }
173
178
 
179
+ gchar *
180
+ rbg_name_to_nick(const gchar *name)
181
+ {
182
+ gchar *nick, *current;
183
+
184
+ nick = g_strdup(name);
185
+ for (current = nick; *current; current++) {
186
+ switch (*current) {
187
+ case '_':
188
+ case ' ':
189
+ *current = '-';
190
+ break;
191
+ default:
192
+ *current = g_ascii_tolower(*current);
193
+ break;
194
+ }
195
+ }
196
+
197
+ return nick;
198
+ }
199
+
174
200
  void
175
201
  Init_gutil(void)
176
202
  {
@@ -180,4 +206,6 @@ Init_gutil(void)
180
206
  id_add_one_arg_setter = rb_intern("__add_one_arg_setter");
181
207
  id_allocate = rb_intern("allocate");
182
208
  id_equal = rb_intern("==");
209
+
210
+ rbg_interrupt_funcs_init();
183
211
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011-2014 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2015 Ruby-GNOME2 Project Team
4
4
  * Copyright (C) 2002,2003 Masao Mutoh
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -107,6 +107,8 @@ extern gboolean rbgutil_key_equal(VALUE rb_string, const char *key);
107
107
  extern const gchar *rbg_inspect(VALUE object);
108
108
  extern GSource *rbg_interrupt_source_new(void);
109
109
 
110
+ extern gchar *rbg_name_to_nick(const gchar *name);
111
+
110
112
  /*< protected >*/
111
113
  RUBY_GLIB2_VAR ID rbgutil_id_module_eval;
112
114
  extern void rbgutil_glibid_r2g_func(VALUE from, GValue* to);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2015 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
@@ -171,3 +171,99 @@ rbg_gslist2rval_with_type(GSList *const list, RBGRValueFuncWithType conv, GType
171
171
  gslist2rval_ensure, (VALUE)&args);
172
172
  }
173
173
 
174
+ struct rval2glist_args {
175
+ GList *list;
176
+ VALUE rb_array;
177
+ };
178
+
179
+ static VALUE
180
+ rval2glist_body(VALUE data)
181
+ {
182
+ struct rval2glist_args *args = (struct rval2glist_args *)data;
183
+ VALUE rb_array;
184
+ int i, n;
185
+
186
+ rb_array = rbg_to_array(args->rb_array);
187
+ n = RARRAY_LEN(rb_array);
188
+ for (i = 0; i < n; i++) {
189
+ VALUE rb_element = RARRAY_CONST_PTR(rb_array)[i];
190
+ args->list = g_list_append(args->list, RVAL2GOBJ(rb_element));
191
+ }
192
+
193
+ return Qnil;
194
+ }
195
+
196
+ static VALUE
197
+ rval2glist_rescue(VALUE data, VALUE e)
198
+ {
199
+ struct rval2glist_args *args = (struct rval2glist_args *)data;
200
+
201
+ g_list_free(args->list);
202
+ args->list = NULL;
203
+
204
+ rb_exc_raise(e);
205
+
206
+ return Qnil;
207
+ }
208
+
209
+ GList *
210
+ rbg_rval2glist(VALUE rb_array)
211
+ {
212
+ struct rval2glist_args args;
213
+ args.list = NULL;
214
+ args.rb_array = rb_array;
215
+
216
+ rb_rescue(rval2glist_body, (VALUE)&args,
217
+ rval2glist_rescue, (VALUE)&args);
218
+
219
+ return args.list;
220
+ }
221
+
222
+ struct rval2gslist_args {
223
+ GSList *list;
224
+ VALUE rb_array;
225
+ };
226
+
227
+ static VALUE
228
+ rval2gslist_body(VALUE data)
229
+ {
230
+ struct rval2gslist_args *args = (struct rval2gslist_args *)data;
231
+ VALUE rb_array;
232
+ int i, n;
233
+
234
+ rb_array = rbg_to_array(args->rb_array);
235
+ n = RARRAY_LEN(rb_array);
236
+ for (i = 0; i < n; i++) {
237
+ VALUE rb_element = RARRAY_CONST_PTR(rb_array)[i];
238
+ args->list = g_slist_append(args->list, RVAL2GOBJ(rb_element));
239
+ }
240
+
241
+ return Qnil;
242
+ }
243
+
244
+ static VALUE
245
+ rval2gslist_rescue(VALUE data, VALUE e)
246
+ {
247
+ struct rval2gslist_args *args = (struct rval2gslist_args *)data;
248
+
249
+ g_slist_free(args->list);
250
+ args->list = NULL;
251
+
252
+ rb_exc_raise(e);
253
+
254
+ return Qnil;
255
+ }
256
+
257
+ GSList *
258
+ rbg_rval2gslist(VALUE rb_array)
259
+ {
260
+ struct rval2gslist_args args;
261
+ args.list = NULL;
262
+ args.rb_array = rb_array;
263
+
264
+ rb_rescue(rval2gslist_body, (VALUE)&args,
265
+ rval2gslist_rescue, (VALUE)&args);
266
+
267
+ return args.list;
268
+ }
269
+
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2015 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
@@ -67,6 +67,12 @@ G_BEGIN_DECLS
67
67
  rbg_gslist2rval_with_type(list, (RBGRValueFuncWithType)rbgobj_make_boxed, gtype, \
68
68
  (GFreeFunc)free_list, (GFreeFunc)free_elem)
69
69
 
70
+ #define RVAL2GOBJGLIST(rb_array) \
71
+ rbg_rval2glist(rb_array)
72
+ #define RVAL2GOBJGSLIST(rb_array) \
73
+ rbg_rval2gslist(rb_array)
74
+
75
+
70
76
  typedef VALUE (*RBGRValueFunc)(gpointer obj);
71
77
  typedef VALUE (*RBGRValueFuncWithType)(gpointer obj, GType gtype);
72
78
 
@@ -79,6 +85,9 @@ extern VALUE rbg_glist2rval_with_type(GList *const list, RBGRValueFuncWithType c
79
85
  extern VALUE rbg_gslist2rval_with_type(GSList *const list, RBGRValueFuncWithType conv, GType gtype,
80
86
  GFreeFunc free_list, GFreeFunc free_elem);
81
87
 
88
+ extern GList *rbg_rval2glist(VALUE rb_array);
89
+ extern GSList *rbg_rval2gslist(VALUE rb_array);
90
+
82
91
  G_END_DECLS
83
92
 
84
93
  #endif /* __RBGUTIL_LIST_H__ */
@@ -14,7 +14,7 @@ module GLib
14
14
  end
15
15
 
16
16
  def define_deprecated_enums(enums, prefix = nil)
17
- enums = module_eval(enums.to_s) rescue return
17
+ enums = resolve_constant_name(enums.to_s)
18
18
  enums.constants.each do |const|
19
19
  deprecated_const = prefix ? "#{prefix}_#{const}" : const
20
20
  new_const = [enums, const].join('::')
@@ -33,7 +33,7 @@ module GLib
33
33
 
34
34
  def define_deprecated_method_by_hash_args(deprecated_method, old_args, new_args, req_argc = 0, &block)
35
35
  klass = self
36
- alias_name = "__deprecatable_#{deprecated_method}__"
36
+ alias_name = "__deprecatable_#{object_id}_#{deprecated_method}__"
37
37
  alias_method alias_name, deprecated_method
38
38
  private alias_name
39
39
 
@@ -99,7 +99,7 @@ module GLib
99
99
  msg = "#{caller[0]}: '#{[name, deprecated_const].join('::')}' has been deprecated."
100
100
  case new_const
101
101
  when String, Symbol
102
- new_const_val = constant_get(new_const)
102
+ new_const_val = resolve_constant_name(new_const)
103
103
  case new_const_val
104
104
  when GLib::Enum, GLib::Flags
105
105
  alt = " or ':#{new_const_val.nick.gsub('-', '_')}'"
@@ -120,8 +120,23 @@ module GLib
120
120
  end
121
121
  end
122
122
 
123
- def constant_get(const)
124
- const.split('::').inject(Object){|r, c| r.const_get(c)}
123
+ def resolve_constant_name(name)
124
+ name.to_s.split("::").inject(nil) do |context, local_name|
125
+ if context.nil?
126
+ candidates = []
127
+ candidate_context = ::Object
128
+ self.to_s.split("::").each do |candidate_name|
129
+ candidate = candidate_context.const_get(candidate_name)
130
+ candidates.unshift(candidate)
131
+ candidate_context = candidate
132
+ end
133
+ context = candidates.find do |candidate|
134
+ candidate.const_defined?(local_name)
135
+ end
136
+ context ||= ::Object
137
+ end
138
+ context.const_get(local_name)
139
+ end
125
140
  end
126
141
 
127
142
  def __define_deprecated_method__(type, deprecated_method, new_method = {}, &block)