glib2 1.0.0-x86-mingw32 → 1.0.1-x86-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.
@@ -46,7 +46,7 @@ g_completion_get_type(void)
46
46
  #define _SELF(s) ((GCompletion*)RVAL2BOXED(s, G_TYPE_COMPLETION))
47
47
 
48
48
  /* data should be [self, data] */
49
- static gchar*
49
+ static gchar *
50
50
  comp_func(gpointer compdata)
51
51
  {
52
52
  VALUE ret;
@@ -60,7 +60,7 @@ comp_func(gpointer compdata)
60
60
  } else {
61
61
  ret = rb_funcall(func, id_call, 1, data);
62
62
  }
63
- return RVAL2CSTR(ret);
63
+ return (gchar *)RVAL2CSTR(ret);
64
64
  }
65
65
 
66
66
  static VALUE
@@ -88,7 +88,7 @@ comp_add_items(VALUE self, VALUE items)
88
88
  GList* list = (GList*)NULL;
89
89
  VALUE items_internal = rb_ivar_get(self, id_items_internal);
90
90
 
91
- Check_Type(items, T_ARRAY);
91
+ items = rb_ary_to_ary(items);
92
92
  len = RARRAY_LEN(items);
93
93
  for (i = 0; i < len; i ++){
94
94
  VALUE data = RARRAY_PTR(items)[i];
@@ -108,7 +108,7 @@ comp_remove_items(VALUE self, VALUE items)
108
108
  GList* list = (GList*)NULL;
109
109
  VALUE items_internal = rb_ivar_get(self, id_items_internal);
110
110
 
111
- Check_Type(items, T_ARRAY);
111
+ items = rb_ary_to_ary(items);
112
112
  len = RARRAY_LEN(items);
113
113
  for (i = 0; i < len; i ++){
114
114
  VALUE data = RARRAY_PTR(items)[i];
@@ -52,7 +52,7 @@ rbgerr_define_gerror(GQuark domain, const gchar *name, VALUE module, VALUE paren
52
52
 
53
53
  if (! NIL_P(gtype)){
54
54
  GEnumClass* gclass = g_type_class_ref(gtype);
55
- int i;
55
+ guint i;
56
56
 
57
57
  for (i = 0; i < gclass->n_values; i++) {
58
58
  GEnumValue* entry = &(gclass->values[i]);
@@ -19,16 +19,7 @@
19
19
  static VALUE
20
20
  rbglib_m_language_names(VALUE self)
21
21
  {
22
- const gchar * const *languages;
23
- const gchar *language;
24
- VALUE rb_languages = rb_ary_new();
25
-
26
- languages = g_get_language_names();
27
- for (language = *languages; *languages; language = *(++languages)) {
28
- rb_ary_push(rb_languages, CSTR2RVAL(language));
29
- }
30
-
31
- return rb_languages;
22
+ return STRV2RVAL((const gchar **)g_get_language_names());
32
23
  }
33
24
  #endif
34
25
 
@@ -89,6 +89,8 @@ ioc_s_open(gint argc, VALUE *argv, VALUE self)
89
89
  if (TYPE(arg1) == T_FIXNUM){
90
90
  #ifdef G_OS_UNIX
91
91
  io = g_io_channel_unix_new(NUM2INT(arg1));
92
+ #elif defined(G_OS_WIN32)
93
+ io = g_io_channel_win32_new_fd(NUM2INT(arg1));
92
94
  #else
93
95
  rb_raise(rb_eRuntimeError,
94
96
  "GLib::IOChannel.new(fd) is supported on "
@@ -651,10 +653,12 @@ static VALUE
651
653
  ioc_win32_socket_initialize(VALUE self, VALUE socket)
652
654
  {
653
655
  GIOChannel *io = NULL;
656
+ int fd;
654
657
 
655
658
  rb_secure(4);
656
659
  /* TODO: support IO object */
657
- io = g_io_channel_win32_new_socket(NUM2INT(socket));
660
+ fd = NUM2INT(socket);
661
+ io = g_io_channel_win32_new_socket(rb_w32_get_osfhandle(fd));
658
662
  G_INITIALIZE(self, io);
659
663
 
660
664
  return Qnil;
@@ -70,7 +70,7 @@ keyfile_load_from_file(int argc, VALUE *argv, VALUE self)
70
70
  }
71
71
 
72
72
  ret = g_key_file_load_from_file(_SELF(self),
73
- (const gchar*)RVAL2CSTR(file),
73
+ RVAL2CSTR(file),
74
74
  gflags, &error);
75
75
 
76
76
  if (! ret) RAISE_GERROR(error);
@@ -137,39 +137,28 @@ keyfile_load_from_dirs(int argc, VALUE *argv, VALUE self)
137
137
  GError* error = NULL;
138
138
  gboolean success;
139
139
  const gchar *file;
140
- gchar **search_dirs;
140
+ const gchar **search_dirs;
141
141
  gchar* full_path;
142
142
  GKeyFileFlags flags;
143
143
 
144
144
  rb_scan_args(argc, argv, "12", &rb_file, &rb_search_dirs, &rb_flags);
145
145
 
146
146
  file = RVAL2CSTR(rb_file);
147
- if (NIL_P(rb_search_dirs)) {
148
- search_dirs = NULL;
149
- }
150
- else {
151
- long i, len;
152
-
153
- Check_Type(rb_search_dirs, T_ARRAY);
154
- len = RARRAY_LEN(rb_search_dirs);
155
- search_dirs = ALLOCA_N(gchar *, len + 1);
156
- for (i = 0; i < len; i++) {
157
- search_dirs[i] = RVAL2CSTR(RARRAY_PTR(rb_search_dirs)[i]);
158
- }
159
- search_dirs[i] = NULL;
160
- }
147
+ search_dirs = RVAL2STRV_ACCEPT_NIL(rb_search_dirs);
161
148
  flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
162
149
  if (!NIL_P(rb_flags))
163
150
  flags = RVAL2GFLAGS(rb_flags, G_TYPE_KEY_FILE_FLAGS);
164
151
 
165
- if (search_dirs)
152
+ if (search_dirs != NULL)
166
153
  success = g_key_file_load_from_dirs(_SELF(self), file,
167
- (const gchar **)search_dirs,
154
+ search_dirs,
168
155
  &full_path, flags, &error);
169
156
  else
170
157
  success = g_key_file_load_from_data_dirs(_SELF(self), file,
171
158
  &full_path, flags, &error);
172
159
 
160
+ g_free(search_dirs);
161
+
173
162
  if (!success)
174
163
  RAISE_GERROR(error);
175
164
 
@@ -197,40 +186,21 @@ keyfile_get_start_group(VALUE self)
197
186
  static VALUE
198
187
  keyfile_get_groups(VALUE self)
199
188
  {
200
- gsize length;
201
- int i;
202
- gchar** groups = g_key_file_get_groups(_SELF(self), &length);
203
- VALUE ary = rb_ary_new();
204
-
205
- for (i = 0; i < length; i++){
206
- rb_ary_push(ary, CSTR2RVAL(groups[i]));
207
- }
208
-
209
- g_strfreev(groups);
210
-
211
- return ary;
189
+ return STRV2RVAL_FREE(g_key_file_get_groups(_SELF(self), NULL));
212
190
  }
213
191
 
214
192
  static VALUE
215
193
  keyfile_get_keys(VALUE self, VALUE group_name)
216
194
  {
217
- gsize length;
218
- int i;
219
- GError* error = NULL;
220
- gchar** keys = g_key_file_get_keys(_SELF(self),
221
- (const gchar*)RVAL2CSTR(group_name),
222
- &length, &error);
223
- VALUE ary = rb_ary_new();
224
-
225
- if (error) RAISE_GERROR(error);
226
-
227
- for (i = 0; i < length; i++){
228
- rb_ary_push(ary, CSTR2RVAL(keys[i]));
229
- }
230
-
231
- g_strfreev(keys);
195
+ GError *error = NULL;
196
+ gchar **keys = g_key_file_get_keys(_SELF(self),
197
+ RVAL2CSTR(group_name),
198
+ NULL,
199
+ &error);
200
+ if (error != NULL)
201
+ RAISE_GERROR(error);
232
202
 
233
- return ary;
203
+ return STRV2RVAL_FREE(keys);
234
204
  }
235
205
 
236
206
  static VALUE
@@ -350,7 +320,7 @@ static VALUE
350
320
  keyfile_get_string_list(VALUE self, VALUE group_name, VALUE key)
351
321
  {
352
322
  VALUE ary;
353
- gint i;
323
+ gsize i;
354
324
  gsize length;
355
325
  GError* error = NULL;
356
326
  gchar** ret = g_key_file_get_string_list(_SELF(self),
@@ -375,7 +345,7 @@ keyfile_get_locale_string_list(int argc, VALUE *argv, VALUE self)
375
345
  VALUE group_name, key, locale;
376
346
  GError* error = NULL;
377
347
  VALUE ary;
378
- gint i;
348
+ gsize i;
379
349
  gsize length;
380
350
  gchar** ret;
381
351
 
@@ -402,7 +372,7 @@ static VALUE
402
372
  keyfile_get_boolean_list(VALUE self, VALUE group_name, VALUE key)
403
373
  {
404
374
  VALUE ary;
405
- gint i;
375
+ gsize i;
406
376
  gsize length;
407
377
  GError* error = NULL;
408
378
  gboolean* ret = g_key_file_get_boolean_list(_SELF(self),
@@ -423,7 +393,7 @@ static VALUE
423
393
  keyfile_get_integer_list(VALUE self, VALUE group_name, VALUE key)
424
394
  {
425
395
  VALUE ary;
426
- gint i;
396
+ gsize i;
427
397
  gsize length;
428
398
  GError* error = NULL;
429
399
  gint* ret = g_key_file_get_integer_list(_SELF(self),
@@ -445,7 +415,7 @@ static VALUE
445
415
  keyfile_get_double_list(VALUE self, VALUE group_name, VALUE key)
446
416
  {
447
417
  VALUE ary;
448
- gint i;
418
+ gsize i;
449
419
  gsize length;
450
420
  GError* error = NULL;
451
421
  gdouble* ret = g_key_file_get_double_list(_SELF(self),
@@ -535,38 +505,36 @@ keyfile_set_double(VALUE self, VALUE group_name, VALUE key, VALUE value)
535
505
  #endif
536
506
 
537
507
  static VALUE
538
- keyfile_set_string_list(VALUE self, VALUE group_name, VALUE key, VALUE list)
508
+ keyfile_set_string_list(VALUE self, VALUE group_name, VALUE key, VALUE rblist)
539
509
  {
540
- gint len = RARRAY_LEN(list);
541
- gchar** glist = ALLOCA_N(gchar*, len);
542
- gint i;
543
-
544
- for (i = 0; i < len; i++){
545
- glist[i] = RVAL2CSTR(RARRAY_PTR(list)[i]);
546
- }
510
+ VALUE ary = rb_ary_to_ary(rblist);
511
+ const gchar **list = RVAL2STRV(ary);
547
512
 
548
513
  g_key_file_set_string_list(_SELF(self),
549
- (const gchar*)RVAL2CSTR(group_name),
550
- (const gchar*)RVAL2CSTR(key),
551
- (const gchar**)glist, len);
514
+ RVAL2CSTR(group_name),
515
+ RVAL2CSTR(key),
516
+ list,
517
+ RARRAY_LEN(ary));
518
+
519
+ g_free(list);
520
+
552
521
  return self;
553
522
  }
554
523
 
555
524
  static VALUE
556
- keyfile_set_locale_string_list(VALUE self, VALUE group_name, VALUE key, VALUE locale, VALUE list)
525
+ keyfile_set_locale_string_list(VALUE self, VALUE group_name, VALUE key, VALUE locale, VALUE rblist)
557
526
  {
558
- gint len = RARRAY_LEN(list);
559
- gchar** glist = ALLOCA_N(gchar*, len);
560
- gint i;
527
+ VALUE ary = rb_ary_to_ary(rblist);
528
+ const gchar **list = RVAL2STRV(ary);
561
529
 
562
- for (i = 0; i < len; i++){
563
- glist[i] = RVAL2CSTR(RARRAY_PTR(list)[i]);
564
- }
530
+ g_key_file_set_locale_string_list(_SELF(self),
531
+ RVAL2CSTR(group_name),
532
+ RVAL2CSTR(key),
533
+ RVAL2CSTR(locale),
534
+ list,
535
+ RARRAY_LEN(ary));
565
536
 
566
- g_key_file_set_locale_string_list(_SELF(self), (const gchar*)RVAL2CSTR(group_name),
567
- (const gchar*)RVAL2CSTR(key),
568
- (const gchar*)RVAL2CSTR(locale),
569
- (const gchar**)glist, len);
537
+ g_free(list);
570
538
 
571
539
  return self;
572
540
  }
@@ -574,36 +542,44 @@ keyfile_set_locale_string_list(VALUE self, VALUE group_name, VALUE key, VALUE lo
574
542
  static VALUE
575
543
  keyfile_set_boolean_list(VALUE self, VALUE group_name, VALUE key, VALUE list)
576
544
  {
577
- gint len = RARRAY_LEN(list);
578
- gboolean* glist = ALLOCA_N(gboolean, len);
579
- gint i;
545
+ VALUE ary;
546
+ long i, n;
547
+ gboolean *booleans;
580
548
 
581
- for (i = 0; i < len; i++){
582
- glist[i] = RVAL2CBOOL(RARRAY_PTR(list)[i]);
583
- }
549
+ ary = rb_ary_to_ary(list);
550
+ n = RARRAY_LEN(ary);
551
+ booleans = ALLOCA_N(gboolean, n);
552
+ for (i = 0; i < n; i++)
553
+ booleans[i] = RVAL2CBOOL(RARRAY_PTR(ary)[i]);
584
554
 
585
555
  g_key_file_set_boolean_list(_SELF(self),
586
- (const gchar*)RVAL2CSTR(group_name),
587
- (const gchar*)RVAL2CSTR(key),
588
- glist, len);
556
+ RVAL2CSTR(group_name),
557
+ RVAL2CSTR(key),
558
+ booleans,
559
+ n);
560
+
589
561
  return self;
590
562
  }
591
563
 
592
564
  static VALUE
593
565
  keyfile_set_integer_list(VALUE self, VALUE group_name, VALUE key, VALUE list)
594
566
  {
595
- gint len = RARRAY_LEN(list);
596
- gint* glist = ALLOCA_N(gint, len);
597
- gint i;
567
+ VALUE ary;
568
+ long i, n;
569
+ gint *ints;
598
570
 
599
- for (i = 0; i < len; i++){
600
- glist[i] = RVAL2CBOOL(RARRAY_PTR(list)[i]);
601
- }
571
+ ary = rb_ary_to_ary(list);
572
+ n = RARRAY_LEN(ary);
573
+ ints = ALLOCA_N(gint, n);
574
+ for (i = 0; i < n; i++)
575
+ ints[i] = NUM2INT(RARRAY_PTR(ary)[i]);
602
576
 
603
577
  g_key_file_set_integer_list(_SELF(self),
604
- (const gchar*)RVAL2CSTR(group_name),
605
- (const gchar*)RVAL2CSTR(key),
606
- glist, len);
578
+ RVAL2CSTR(group_name),
579
+ RVAL2CSTR(key),
580
+ ints,
581
+ n);
582
+
607
583
  return self;
608
584
  }
609
585
 
@@ -611,18 +587,22 @@ keyfile_set_integer_list(VALUE self, VALUE group_name, VALUE key, VALUE list)
611
587
  static VALUE
612
588
  keyfile_set_double_list(VALUE self, VALUE group_name, VALUE key, VALUE list)
613
589
  {
614
- gint len = RARRAY_LEN(list);
615
- gdouble* glist = ALLOCA_N(gdouble, len);
616
- gint i;
617
-
618
- for (i = 0; i < len; i++){
619
- glist[i] = RVAL2CBOOL(RARRAY_PTR(list)[i]);
620
- }
590
+ VALUE ary;
591
+ long i, n;
592
+ gdouble *doubles;
593
+
594
+ ary = rb_ary_to_ary(list);
595
+ n = RARRAY_LEN(ary);
596
+ doubles = ALLOCA_N(gdouble, n);
597
+ for (i = 0; i < n; i++)
598
+ doubles[i] = NUM2DBL(RARRAY_PTR(ary)[i]);
621
599
 
622
600
  g_key_file_set_double_list(_SELF(self),
623
- (const gchar*)RVAL2CSTR(group_name),
624
- (const gchar*)RVAL2CSTR(key),
625
- glist, len);
601
+ RVAL2CSTR(group_name),
602
+ RVAL2CSTR(key),
603
+ doubles,
604
+ n);
605
+
626
606
  return self;
627
607
  }
628
608
  #endif
@@ -631,11 +611,14 @@ static VALUE
631
611
  keyfile_set_comment(VALUE self, VALUE group_name, VALUE key, VALUE comment)
632
612
  {
633
613
  GError* error = NULL;
634
- g_key_file_set_comment(_SELF(self), (const gchar*)RVAL2CSTR(group_name),
635
- (const gchar*)(NIL_P(key) ? NULL : RVAL2CSTR(key)),
636
- (const gchar*)RVAL2CSTR(comment), &error);
637
614
 
638
- if (error) RAISE_GERROR(error);
615
+ g_key_file_set_comment(_SELF(self),
616
+ RVAL2CSTR(group_name),
617
+ RVAL2CSTR_ACCEPT_NIL(key),
618
+ RVAL2CSTR(comment),
619
+ &error);
620
+ if (error != NULL)
621
+ RAISE_GERROR(error);
639
622
 
640
623
  return self;
641
624
  }
@@ -644,9 +627,11 @@ static VALUE
644
627
  keyfile_remove_group(VALUE self, VALUE group_name)
645
628
  {
646
629
  GError* error = NULL;
647
- g_key_file_remove_group(_SELF(self), (const gchar*)RVAL2CSTR(group_name), &error);
648
630
 
649
- if (error) RAISE_GERROR(error);
631
+ g_key_file_remove_group(_SELF(self), RVAL2CSTR(group_name), &error);
632
+
633
+ if (error != NULL)
634
+ RAISE_GERROR(error);
650
635
 
651
636
  return self;
652
637
  }
@@ -655,12 +640,14 @@ static VALUE
655
640
  keyfile_remove_key(VALUE self, VALUE group_name, VALUE key)
656
641
  {
657
642
  GError* error = NULL;
643
+
658
644
  g_key_file_remove_key(_SELF(self),
659
- (const gchar*)RVAL2CSTR(group_name),
660
- (const gchar*)RVAL2CSTR(key),
645
+ RVAL2CSTR(group_name),
646
+ RVAL2CSTR(key),
661
647
  &error);
662
648
 
663
- if (error) RAISE_GERROR(error);
649
+ if (error != NULL)
650
+ RAISE_GERROR(error);
664
651
 
665
652
  return self;
666
653
  }
@@ -670,12 +657,14 @@ static VALUE
670
657
  keyfile_remove_comment(VALUE self, VALUE group_name, VALUE key)
671
658
  {
672
659
  GError* error = NULL;
660
+
673
661
  g_key_file_remove_comment(_SELF(self),
674
- (const gchar*)RVAL2CSTR(group_name),
675
- (const gchar*)RVAL2CSTR(key),
676
- &error);
662
+ RVAL2CSTR(group_name),
663
+ RVAL2CSTR(key),
664
+ &error);
677
665
 
678
- if (error) RAISE_GERROR(error);
666
+ if (error != NULL)
667
+ RAISE_GERROR(error);
679
668
 
680
669
  return self;
681
670
  }